6c2c697a58
Had to recreate repo because it was corrupted. FML.
27 lines
1.5 KiB
C
27 lines
1.5 KiB
C
// Have enum names be convertible to strings
|
|
// From https://stackoverflow.com/a/5094430
|
|
// by James McNellis
|
|
// with slight adjustments
|
|
// Retrieved 14-10-2017
|
|
#include <boost/preprocessor.hpp>
|
|
|
|
#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) "]"; \
|
|
} \
|
|
} |