Skip to content

Commit

Permalink
Make sure we check for correct usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Loki-Astari committed Jun 16, 2015
1 parent 1579179 commit 119b98b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Serialize/Traits.h
Expand Up @@ -9,6 +9,7 @@
*
* ThorsAnvil_MakeTrait(DataType, ...)
* ThorsAnvil_ExpandTrait(ParentType, DataType, ...)
* ThorsAnvil_MakeEnum(<EnumType>, <EnumValues>...)
*
* See README.md for examples.
*/
Expand Down Expand Up @@ -135,10 +136,10 @@ static_assert(
#define ThorsAnvil_ExpandTrait(ParentType, ...) \
ThorsAnvil_ExpandTrait_With_Ext(ParentType, __VA_ARGS__, 1)

#define ThorsAnvil_MakeEnum(enumName, ...) \
#define ThorsAnvil_MakeEnum(EnumName, ...) \
namespace ThorsAnvil { namespace Serialize { \
template<> \
class Traits<enumName> \
class Traits<EnumName> \
{ \
public: \
static constexpr TraitType type = TraitType::Enum; \
Expand All @@ -153,20 +154,24 @@ class Traits<enumName> \
{ \
return NUM_ARGS(__VA_ARGS__, 1); \
} \
static enumName getValue(std::string const& val, std::string const& msg) \
static EnumName getValue(std::string const& val, std::string const& msg) \
{ \
char const* const* values = getValues(); \
std::size_t size = getSize(); \
for(std::size_t loop = 0;loop < size; ++loop) \
{ \
if (val == values[loop]) { \
return static_cast<enumName>(loop); \
return static_cast<EnumName>(loop); \
} \
} \
throw std::runtime_error(msg + " Invalid Enum Value"); \
} \
}; \
}}
}} \
static_assert( \
::ThorsAnvil::Serialize::Traits<EnumName>::type != ThorsAnvil::Serialize::TraitType::Invalid, \
"The macro ThorsAnvil_MakeTrait must be used outside all namespace." \
)


/*
Expand Down

0 comments on commit 119b98b

Please sign in to comment.