I recently had the same issue with a vendor library (Fincad). Fortunately, the vendor provided xml doucumentation for all the enums. I ended up generating a map for each enum type and providing a lookup function for each enum. This technique also allows you to intercept a lookup outside the range of the enum.
I'm sure swig could do something similar for you, but I'm happy to provide the code generation utils which are written in ruby.
Here is a sample of the code:
std::map<std::string, switches::FCSW2::type> init_FCSW2_map() {
std::map<std::string, switches::FCSW2::type> ans;
ans["Act365Fixed"] = FCSW2::Act365Fixed;
ans["actual/365 (fixed)"] = FCSW2::Act365Fixed;
ans["Act360"] = FCSW2::Act360;
ans["actual/360"] = FCSW2::Act360;
ans["Act365Act"] = FCSW2::Act365Act;
ans["actual/365 (actual)"] = FCSW2::Act365Act;
ans["ISDA30360"] = FCSW2::ISDA30360;
ans["30/360 (ISDA)"] = FCSW2::ISDA30360;
ans["ISMA30E360"] = FCSW2::ISMA30E360;
ans["30E/360 (30/360 ISMA)"] = FCSW2::ISMA30E360;
return ans;
}
switches::FCSW2::type FCSW2_lookup(const char* fincad_switch) {
static std::map<std::string, switches::FCSW2::type> switch_map = init_FCSW2_map();
std::map<std::string, switches::FCSW2::type>::iterator it = switch_map.find(fincad_switch);
if(it != switch_map.end()) {
return it->second;
} else {
throw FCSwitchLookupError("Bad Match: FCSW2");
}
}
Seems like you want to go the other way (enum to string, rather than string to enum), but this should be trivial to reverse.
-Whit