Files
small-image-descriptors/Enumstrings.h
T
Mark Hoekveen 6c2c697a58 Initial Commit
Had to recreate repo because it was corrupted. FML.
2018-06-30 14:17:13 +02:00

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) "]"; \
} \
}