mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Use template specialization instead of name concatenation so that reflection of enums works for enums that are inside another class or namespace.
This commit is contained in:
@@ -143,7 +143,7 @@ private:
|
||||
#define REFLECT_ENUM_GET_MEMBER(Enum) \
|
||||
template<> void GetDefaultMember::handle<Enum>(const Enum& enum_) { \
|
||||
EnumGetMember egm(*this); \
|
||||
reflect_ ## Enum(const_cast<Enum&>(enum_), egm); \
|
||||
ReflectEnum<Enum>::reflect(const_cast<Enum&>(enum_), egm); \
|
||||
}
|
||||
|
||||
/// Handler to be used when reflecting enumerations for GetMember
|
||||
|
||||
@@ -263,12 +263,12 @@ void Reader::handle(IndexMap<K,V>& m) {
|
||||
#define REFLECT_ENUM_READER(Enum) \
|
||||
template<> void Reader::handle<Enum>(Enum& enum_) { \
|
||||
EnumReader reader(getValue()); \
|
||||
reflect_ ## Enum(enum_, reader); \
|
||||
ReflectEnum<Enum>::reflect(enum_, reader); \
|
||||
reader.warnIfNotDone(this); \
|
||||
} \
|
||||
void parse_enum(const String& value, Enum& out) { \
|
||||
EnumReader reader(value); \
|
||||
reflect_ ## Enum(out, reader); \
|
||||
ReflectEnum<Enum>::reflect(out, reader); \
|
||||
reader.errorIfNotDone(); \
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ void Writer::handle(const IndexMap<K,V>& m) {
|
||||
#define REFLECT_ENUM_WRITER(Enum) \
|
||||
template<> void Writer::handle<Enum>(const Enum& enum_) { \
|
||||
EnumWriter writer(*this); \
|
||||
reflect_ ## Enum(const_cast<Enum&>(enum_), writer); \
|
||||
ReflectEnum<Enum>::reflect(const_cast<Enum&>(enum_), writer); \
|
||||
}
|
||||
|
||||
/// Handler to be used when reflecting enumerations for Writer
|
||||
|
||||
@@ -159,6 +159,9 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Reflecting enums
|
||||
|
||||
template <typename Enum>
|
||||
struct ReflectEnum {};
|
||||
|
||||
/// Implement the refelection of a enumeration type Enum
|
||||
/** Usage:
|
||||
* @code
|
||||
@@ -176,13 +179,14 @@
|
||||
* - GetDefaultMember::handle(const Enum&)
|
||||
*/
|
||||
#define IMPLEMENT_REFLECTION_ENUM(Enum) \
|
||||
template <class Handler> \
|
||||
void reflect_ ## Enum (Enum& enum_, Handler& handler); \
|
||||
template <> struct ReflectEnum<Enum> { \
|
||||
template <class Handler> static void reflect(Enum&, Handler&); \
|
||||
}; \
|
||||
REFLECT_ENUM_READER(Enum) \
|
||||
REFLECT_ENUM_WRITER(Enum) \
|
||||
REFLECT_ENUM_GET_MEMBER(Enum) \
|
||||
template <class Handler> \
|
||||
void reflect_ ## Enum (Enum& enum_, Handler& handler)
|
||||
void ReflectEnum<Enum>::reflect(Enum& enum_, Handler& handler)
|
||||
|
||||
/// Declare a possible value of an enum
|
||||
#define VALUE(val) handler.handle(_(#val), val, enum_)
|
||||
|
||||
Reference in New Issue
Block a user