// Have enum names be convertible to strings // From https://stackoverflow.com/a/5094430 // by James McNellis // with slight adjustments // Retrieved 14-10-2017 #include #define X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE(r, data, elem) \ case elem : return BOOST_PP_STRINGIZE(elem); #define ENUM_STRING(name, enumerators) \ enum name { \ BOOST_PP_SEQ_ENUM(enumerators) \ }; \ \ inline const char* ToString(name v) \ { \ switch (v) \ { \ BOOST_PP_SEQ_FOR_EACH( \ X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, \ name, \ enumerators \ ) \ default: return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; \ } \ }