Ok, here is an example of what the new version of my program does.
I have a .cpp file which contains an enum (and nothing else, even though it work with lots of other stuff in it too). The enum looks like this:
Code:
enum DAY /* Defines an enumeration type */
{
saturday, /* Names day and declares a */
sunday = 0, /* variable named workday with */
monday, /* that type */
tuesday,
wednesday, /* wednesday is associated with 3 */
thursday,
friday
} workday;
This enum was copied from here.
Ok, so I now pass this file containing enum to my program:
Code:
./ConvertEnumToStrings "/home/gorilla/Documents/test.cpp" "results"
The program generates a "results.h" file in the same directory as the file passed. The results file contains the following:
Code:
#include <string>
#include <vector>
using namespace std;
class CDAYToStrings {
public:
CDAYToStrings();
//Methods/functions:
const vector <string>& getEnumValues();
const string& getNameOfEnum();
const int& getNumOfEnumValues();
//Enumeration type:
enum DAY /* Defines an enumeration type */
{
saturday, /* Names day and declares a */
sunday = 0, /* variable named workday with */
monday, /* that type */
tuesday,
wednesday, /* wednesday is associated with 3 */
thursday,
friday
} workday;
//Method/function:
const string& getEnumValue(DAY enumValue);
private:
vector <string> enumValueNames;
string nameOfEnum;
int numOfEnumValues;
string enumValueName;
};
CDAYToStrings::CDAYToStrings() {
nameOfEnum = "DAY"; //initialize to name of enum
numOfEnumValues = 7; //initialize to number of enum values
enumValueName = ""; //initialize to an empty string
enumValueNames.push_back("saturday"); //add string name of enum value to vector of enum values
enumValueNames.push_back("sunday"); //add string name of enum value to vector of enum values
enumValueNames.push_back("monday"); //add string name of enum value to vector of enum values
enumValueNames.push_back("tuesday"); //add string name of enum value to vector of enum values
enumValueNames.push_back("wednesday"); //add string name of enum value to vector of enum values
enumValueNames.push_back("thursday"); //add string name of enum value to vector of enum values
enumValueNames.push_back("friday"); //add string name of enum value to vector of enum values
}
const vector <string>& CDAYToStrings::getEnumValues() {
const vector <string>& rEnumValueNames = enumValueNames; //get a reference to the enum value names
return rEnumValueNames; //return the reference
}
const string& CDAYToStrings::getNameOfEnum() {
const string& rNameOfEnum = nameOfEnum; //get a reference to the name of enum
return rNameOfEnum; //return the reference
}
const int& CDAYToStrings::getNumOfEnumValues() {
const int& rNumOfEnumValues = numOfEnumValues; //get a reference to the number of enum values
return rNumOfEnumValues; //return the reference
}
const string& CDAYToStrings::getEnumValue(DAY enumValue) {
if (enumValue == saturday) {
enumValueName = "saturday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
if (enumValue == sunday) {
enumValueName = "sunday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
if (enumValue == monday) {
enumValueName = "monday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
if (enumValue == tuesday) {
enumValueName = "tuesday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
if (enumValue == wednesday) {
enumValueName = "wednesday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
if (enumValue == thursday) {
enumValueName = "thursday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
if (enumValue == friday) {
enumValueName = "friday";
const string& rEnumValueName = enumValueName; //get a reference to the enum value name
return rEnumValueName; //return the reference
}
}
As you can see, comments on the same line as the 'enum' keyword are now supported. Also, there is no longer a problem with an enum variable before the semi-colon of the enum.
Next version will support the whole enum on one line.