Go to the documentation of this file.
13 #ifndef __defined_libdai_enum_h
14 #define __defined_libdai_enum_h
35 #define DAI_ENUM(x,val0,...) class x {\
37 enum value {val0,__VA_ARGS__};\
44 static char const* labelstring = #val0 "," #__VA_ARGS__;\
45 size_t pos_begin = 0;\
47 for( size_t pos_end = 0; ; pos_end++ ) {\
48 if( (labelstring[pos_end] == ',') || (labelstring[pos_end] == '\0') ) {\
49 if( (strlen( w ) == pos_end - pos_begin) && (strncmp( labelstring + pos_begin, w, pos_end - pos_begin ) == 0) ) {\
54 pos_begin = pos_end + 1;\
57 if( labelstring[pos_end] == '\0' )\
60 DAI_THROWE(UNKNOWN_ENUM_VALUE,"'" + std::string(w) + "' is not in [" + std::string(labelstring) + "]");\
63 operator value() const { return v; }\
65 operator size_t() const { return (size_t)v; }\
67 operator char const*() const {\
68 static char labelstring[] = #val0 "," #__VA_ARGS__;\
69 size_t pos_begin = 0;\
71 for( size_t pos_end = 0; ; pos_end++ )\
72 if( (labelstring[pos_end] == ',') || (labelstring[pos_end] == '\0') ) {\
73 if( (size_t)v == i ) {\
74 labelstring[pos_end] = '\0';\
75 return labelstring + pos_begin;\
78 pos_begin = pos_end + 1;\
83 friend std::istream& operator >> (std::istream& is, x& y) {\
90 friend std::ostream& operator << (std::ostream& os, const x& y) {\
91 os << (const char *)y;\