Throw when parsing a string as enum if the string parses as integer but does not exist in enum
This commit is contained in:
parent
8d99ea94e6
commit
80b2341e77
1 changed files with 11 additions and 2 deletions
|
|
@ -120,7 +120,8 @@ void fc::reflector<TYPE>::visit( const Visitor& v ) { \
|
||||||
|
|
||||||
#define FC_REFLECT_ENUM_FROM_STRING( r, enum_type, elem ) \
|
#define FC_REFLECT_ENUM_FROM_STRING( r, enum_type, elem ) \
|
||||||
if( strcmp( s, BOOST_PP_STRINGIZE(elem) ) == 0 ) return enum_type::elem;
|
if( strcmp( s, BOOST_PP_STRINGIZE(elem) ) == 0 ) return enum_type::elem;
|
||||||
|
#define FC_REFLECT_ENUM_FROM_STRING_CASE( r, enum_type, elem ) \
|
||||||
|
case enum_type::elem:
|
||||||
|
|
||||||
#define FC_REFLECT_ENUM( ENUM, FIELDS ) \
|
#define FC_REFLECT_ENUM( ENUM, FIELDS ) \
|
||||||
namespace fc { \
|
namespace fc { \
|
||||||
|
|
@ -158,7 +159,15 @@ template<> struct reflector<ENUM> { \
|
||||||
{ \
|
{ \
|
||||||
fc::throw_bad_enum_cast( s, BOOST_PP_STRINGIZE(ENUM) ); \
|
fc::throw_bad_enum_cast( s, BOOST_PP_STRINGIZE(ENUM) ); \
|
||||||
} \
|
} \
|
||||||
return ENUM(i);\
|
ENUM e = ENUM(i); \
|
||||||
|
switch( e ) \
|
||||||
|
{ \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_FROM_STRING_CASE, ENUM, FIELDS ) \
|
||||||
|
break; \
|
||||||
|
default: \
|
||||||
|
fc::throw_bad_enum_cast( s, BOOST_PP_STRINGIZE(ENUM) ); \
|
||||||
|
} \
|
||||||
|
return e;\
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue