lazy question: any good way to convert enums to human readable strings?

I have done very little searching, but it seemed worth just asking... sorry if this is newsgroup pollution: Does anyone have a favored way to convert large enums into stings suitable for printing? For example, we have an enum declared: enum eFurniture { eOT_chair = 1, eOT_stool =2, eOT_sofa =3, ... eOT_lounger = 1000, }; It would be really nice if there were a programmatic way to do something like: STRINGED_ENUM(eFurniture) E_STRING(eOT_chair, 1) E_STRING(eOT_stool, 2) E_STRING(eOT_sofa, 3) ... E_STRING(eOT_lounger, 1000) and then there would be a programmatic way to get both the enum and the string, such as eFurniture eTheAntique = eOT_stool; //and then... char* szTheAntique[128]; GetEnumString<eObjectTypes>(eTheAntique, szTheAntique); printf("the antique is %s\n", szTheAntique); //or maybe... char* szTheAntique = eFurniture_STRING_TABLE[eTheAntique]; Any recomendations? Thanks, Andy.

On 9/4/06, Andrew Schweitzer
Does anyone have a favored way to convert large enums into stings suitable for printing?
The proposed Boost.Enum library in the vault =) http://www.boost-consulting.com/vault/ ~ SWMc

me22 wrote:
On 9/4/06, Andrew Schweitzer
wrote: Does anyone have a favored way to convert large enums into stings suitable for printing?
The proposed Boost.Enum library in the vault =) http://www.boost-consulting.com/vault/
~ SWMc
You know, I just downloaded it and read the doc, but I didn't see any mention of converting to strings... maybe I didn't read carefully enough or didn't think about the possibilities? I'll look again.

On 9/4/06, Andrew Schweitzer
You know, I just downloaded it and read the doc, but I didn't see any mention of converting to strings... maybe I didn't read carefully enough or didn't think about the possibilities? I'll look again.
I'm not sure how complete the docs are, but there does appear to be a .str() member function returning a char const *. ( And operator<< for streams is defined in terms of it. ) ~ SWMc

I have never found anything better than using a Perl script on the side. I also ended up writing a bijection class, which is like a map except both types are keys, which lets you easily convert from enum to string and vice versa. My Perl script then generates the code to initialize the bijection. At 10:12 AM 9/4/2006, you wrote:
I have done very little searching, but it seemed worth just asking... sorry if this is newsgroup pollution:
Does anyone have a favored way to convert large enums into stings suitable for printing?
For example, we have an enum declared:
enum eFurniture { eOT_chair = 1, eOT_stool =2, eOT_sofa =3, ... eOT_lounger = 1000, };
It would be really nice if there were a programmatic way to do something like:
STRINGED_ENUM(eFurniture) E_STRING(eOT_chair, 1) E_STRING(eOT_stool, 2) E_STRING(eOT_sofa, 3) ... E_STRING(eOT_lounger, 1000)
and then there would be a programmatic way to get both the enum and the string, such as
participants (3)
-
Alan M. Carroll
-
Andrew Schweitzer
-
me22