I have a huge C++ solution created as a "win32 console application" project in MVS2008, the only Additional Options during the creation having been : "precompiled header".
In this solution I now have a huge amount of enums defined in various ways : they are always defined in a .h
file, but they can be defined either within a namespace, either within a class, either within a class within a namespace.
I would like to define in more elegant way (I know how to do it in a bruteforce way, but it wouldn't be DRY, right ?) a function:
void myfunc( const char * )
Which would print all "stringed" values of an enum when I pass to it the "string value" of this enum.
To be precise, if I have somewhere in my code:
enum Place
{
Home,
Work
};
I would like to be able to pass to my function the string "Place", and my function to print the strings "Home" and "Work".
Having really A LOT of enums, I would like, if possible, to avoid modifying them a lot, ideally not at all. I thought of a small parser, but I don't think this optimal at all.
By the way, I am RESTRICTED not to use external things different from boost, but I can use macros. I would like to be able to somehow define the concepts of "loop" over enums, and of "loop within the "strings of enums"" as well, but don't see how to do it at all.
All ideas are welcome.