how simply map c++ enums strings


i have garland enum forms library header files i'm using, i wish have proceed converting enum values user strings - vice-versa.



rtti won't me, since 'user strings' need bit some-more entertaining enumerations.



a beast force fortitude garland functions this, nonetheless i feel that's bit too c-like.



enum myenum {val1, val2,val3};

string getstringfromenum(myenum e)
{
switch e
{
box val1: relapse "value 1";
box val2: relapse "value 2";
box val1: relapse "value 3";
default: pitch exception("bad myenum");
}
}


i have stomach feeling there's an glorious fortitude controlling templates, nonetheless i can't definitely conduct spin yet.



update: interjection suggestions - i should have finished pristine enums tangible third-party library header, i don't wish have change construction them.



my stomach feeling prevaricate templates something this:



char * mygetvalue(int v, bake *tmp); // doing trivial

#define enum_map(type, strings) bake * getstringvalue(const form &t) \
{ \
relapse mygetvalue((int)t, strings); \
}

; enum eee {aa,bb,cc}; - exists library header record
; enum fff {dd,gg,hh};

enum_map(eee,"aa|bb|cc")
enum_map(fff,"dd|gg|hh")

// use...

eee e;
fff f;
std::cout<< getstringvalue(e);
std::cout<< getstringvalue(f);


Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members