Free program I'm sharing: ConvertEnumToStrings

This is a discussion on Free program I'm sharing: ConvertEnumToStrings within the Projects and Job Recruitment forums, part of the Community Boards category; Well, I recently wrote a program, and thought I'd share it with the community here.
Its called ConvertEnumToStrings, and the ...

Free program I'm sharing: ConvertEnumToStrings

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.

Didn't compile for me. Not in Code::Blocks, or using my own automake routine. Same error using both methods though:

Code:

~\ConvertEnumToStrings\ConvertEnumToStrings\module\CconvertEnumToStrings\CconvertEnumToStrings.cpp|3|error: 'CconvertEnumToStrings' has not been declared|
~\ConvertEnumToStrings\ConvertEnumToStrings\module\CconvertEnumToStrings\CconvertEnumToStrings.cpp|3|error: 'CconvertEnumToStrings' has not been declared|
~\ConvertEnumToStrings\ConvertEnumToStrings\module\CconvertEnumToStrings\CconvertEnumToStrings.cpp|3|error: expected constructor, destructor, or type conversion before '(' token

Didn't compile for me. Not in Code::Blocks, or using my own automake routine. Same error using both methods though:

Code:

~\ConvertEnumToStrings\ConvertEnumToStrings\module\CconvertEnumToStrings\CconvertEnumToStrings.cpp|3|error: 'CconvertEnumToStrings' has not been declared|
~\ConvertEnumToStrings\ConvertEnumToStrings\module\CconvertEnumToStrings\CconvertEnumToStrings.cpp|3|error: 'CconvertEnumToStrings' has not been declared|
~\ConvertEnumToStrings\ConvertEnumToStrings\module\CconvertEnumToStrings\CconvertEnumToStrings.cpp|3|error: expected constructor, destructor, or type conversion before '(' token

Sorry, I didn't mean to include CconvertEnumToStrings.cpp. Delete that file from that project then try again. I'll re-upload the zip in a minute.

You are welcome to shorten it if you want...
I think the explanation and what it states is necessary, even if its a little long.
I might be able to change the wording a little bit to make it shorter, but I can't change what it basically says.

As far as the program, for doing such a specific task, you should provide a little more leeway for how users may enter their enum

Example

Code:

enum NAMEOFENUM {
enumValue1 = 0,
enumValue2 = 1,
enumValue3 = 2, //note, if this were the last enum value, no comma should be there
//etc...
};

is really kinda silly, a more realistic use would be:

Code:

enum foo{
a = 2, b, c
};

So just check for everything between 'enum' and the next encountered '};' characters.

then make a class that contains the enum and the map. You will make sure it is read-only if you want and static. You could use it like

Code:

Name x = Name::Mike;
cout << x.str() << endl;

where x.str() could return the string. To do so it would do something like

Code:

string& str()
{
return this.innerMap[this.value];
}

and of course, you would overload the = operator so it assigns the value given to the "this.value". Where value would be an "enum name" and innerMap the map you use to map the string with the int value of the enum.

So you could create an "Advanced Enum" in order to have the additional functionality you want. The program will replace an enum with the advanced class.