-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenum_conversions_macro.h
31 lines (23 loc) · 1.09 KB
/
enum_conversions_macro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef ENUM_CONVERSIONS_MACRO_H
#define ENUM_CONVERSIONS_MACRO_H
#include "enum_conversions.h"
// http://stackoverflow.com/a/25516380
#define ENUM_IMPL_(type, name, ...)\
type name\
{\
__VA_ARGS__\
};\
template <> struct EnumConversions<name> { \
static constexpr char enumToStringStr[] = #__VA_ARGS__; \
}; \
template <> struct enum_serializable<name> : std::true_type {};\
// constexpr char EnumConversions<name>::enumToStringStr[];
// template <> constexpr char EnumConversions<name>::enumToStringStr[];
// public: static constexpr EnumToStringVector enumToStringVector = splitStringToVector(#__VA_ARGS__);
// template <> const typename EnumConversions<name>::Vector EnumConversions<name>::enumToStringVector = EnumConversions<name>::splitStringToVector(#__VA_ARGS__);
// static const int name##Size = (sizeof((int[]){__VA_ARGS__})/sizeof(int));
#define ENUM(name, ...) ENUM_IMPL_(enum, name, __VA_ARGS__)
#define ENUM_CLASS(name, ...) ENUM_IMPL_(enum class, name, __VA_ARGS__)
#define ENUM_DEFINITION(name) \
constexpr char EnumConversions<name>::enumToStringStr[];
#endif