Well, I recently wrote a program, and thought I'd share it with the community here.
Its called ConvertEnumToStrings, and the purpose is similiar to the name: to convert enums to strings.
More specifically, the purpose is to be able to retrieve the names of enum values as strings.
Yes, there are other methods around to accomplish this, but none that I know of other than mine can operate on just any enum. You'd have to write a method for each enum you write, in order to retrieve their string names. The beauty of my program is, you can get the enum value string names of ANY enum, provided it is formatted something like this:
Code:
enum NAMEOFENUM {
enumValue1,
enumValue2,
enumValue3
};
or:
Code:
enum NAMEOFENUM {
enumValue1 = 0,
enumValue2 = 1,
enumValue3 = 2, //note, if this were the last enum value, no comma should be there
//etc...
};
It is especially important that each enum value is prefixed by at least one space. Otherwise it wont work (or it wont work WELL anyway...).
Since I'm providing the source code, and not just the binary(ies), you are welcome to edit it as much as you like. But I provide no guarantees that the program will work correctly after you do this.
Instructions:
Download the .zip file containing the source and header files for ConvertEnumToStrings from this link.
Extract everything from the .zip to somewhere on your hard drive, being sure to retain the directory structures.
Add the sources and headers found in the "ConvertEnumToStrings" directory and all sub-directories to a new project file created in whatever IDE you use (I use Code::Blocks).
Make sure your IDE is set to link.
Build the project. It should compile without any errors.
You should now have an executable you can run from whatever target directory you compiled it in.
Now open up a Terminal or Command Prompt (depending on whether you're in Linux or Windows), or whatever name the command-line program is in your OS.
Through the command-line, navigate to the directory (using the "cd" command or similiar) the "ConvertEnumToStrings" executable is in.
Once there, run this if in Windows:
Code:
ConvertEnumToStrings.exe --help
to get a description of how to use the program.
Or this if in Linux:
Code:
./ConvertEnumToStrings --help
to get a description of how to use the program.
Read what it says and respond accordingly.
You should now be able to pass into the program an existing file with an enum in it, and have the program generate a header or source file (header by default) for you providing the method(s) to get different enum elements automatically, including the enum name, a vector of all the enum value names, or the number of enum values.
Constructive criticisms/comments are welcome and encouraged.