mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 21:47: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) \
|
#define REFLECT_ENUM_GET_MEMBER(Enum) \
|
||||||
template<> void GetDefaultMember::handle<Enum>(const Enum& enum_) { \
|
template<> void GetDefaultMember::handle<Enum>(const Enum& enum_) { \
|
||||||
EnumGetMember egm(*this); \
|
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
|
/// 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) \
|
#define REFLECT_ENUM_READER(Enum) \
|
||||||
template<> void Reader::handle<Enum>(Enum& enum_) { \
|
template<> void Reader::handle<Enum>(Enum& enum_) { \
|
||||||
EnumReader reader(getValue()); \
|
EnumReader reader(getValue()); \
|
||||||
reflect_ ## Enum(enum_, reader); \
|
ReflectEnum<Enum>::reflect(enum_, reader); \
|
||||||
reader.warnIfNotDone(this); \
|
reader.warnIfNotDone(this); \
|
||||||
} \
|
} \
|
||||||
void parse_enum(const String& value, Enum& out) { \
|
void parse_enum(const String& value, Enum& out) { \
|
||||||
EnumReader reader(value); \
|
EnumReader reader(value); \
|
||||||
reflect_ ## Enum(out, reader); \
|
ReflectEnum<Enum>::reflect(out, reader); \
|
||||||
reader.errorIfNotDone(); \
|
reader.errorIfNotDone(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ void Writer::handle(const IndexMap<K,V>& m) {
|
|||||||
#define REFLECT_ENUM_WRITER(Enum) \
|
#define REFLECT_ENUM_WRITER(Enum) \
|
||||||
template<> void Writer::handle<Enum>(const Enum& enum_) { \
|
template<> void Writer::handle<Enum>(const Enum& enum_) { \
|
||||||
EnumWriter writer(*this); \
|
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
|
/// Handler to be used when reflecting enumerations for Writer
|
||||||
|
|||||||
@@ -159,6 +159,9 @@
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Reflecting enums
|
// ----------------------------------------------------------------------------- : Reflecting enums
|
||||||
|
|
||||||
|
template <typename Enum>
|
||||||
|
struct ReflectEnum {};
|
||||||
|
|
||||||
/// Implement the refelection of a enumeration type Enum
|
/// Implement the refelection of a enumeration type Enum
|
||||||
/** Usage:
|
/** Usage:
|
||||||
* @code
|
* @code
|
||||||
@@ -176,13 +179,14 @@
|
|||||||
* - GetDefaultMember::handle(const Enum&)
|
* - GetDefaultMember::handle(const Enum&)
|
||||||
*/
|
*/
|
||||||
#define IMPLEMENT_REFLECTION_ENUM(Enum) \
|
#define IMPLEMENT_REFLECTION_ENUM(Enum) \
|
||||||
template <class Handler> \
|
template <> struct ReflectEnum<Enum> { \
|
||||||
void reflect_ ## Enum (Enum& enum_, Handler& handler); \
|
template <class Handler> static void reflect(Enum&, Handler&); \
|
||||||
|
}; \
|
||||||
REFLECT_ENUM_READER(Enum) \
|
REFLECT_ENUM_READER(Enum) \
|
||||||
REFLECT_ENUM_WRITER(Enum) \
|
REFLECT_ENUM_WRITER(Enum) \
|
||||||
REFLECT_ENUM_GET_MEMBER(Enum) \
|
REFLECT_ENUM_GET_MEMBER(Enum) \
|
||||||
template <class Handler> \
|
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
|
/// Declare a possible value of an enum
|
||||||
#define VALUE(val) handler.handle(_(#val), val, enum_)
|
#define VALUE(val) handler.handle(_(#val), val, enum_)
|
||||||
|
|||||||
Reference in New Issue
Block a user