diff --git a/include/fc/reflect/reflect.hpp b/include/fc/reflect/reflect.hpp index 837b431..da62732 100644 --- a/include/fc/reflect/reflect.hpp +++ b/include/fc/reflect/reflect.hpp @@ -17,7 +17,7 @@ #include -namespace fc { +namespace fc { /** * @brief defines visit functions for T @@ -32,13 +32,13 @@ template struct reflector{ typedef T type; typedef fc::false_type is_defined; - typedef fc::false_type is_enum; + typedef fc::false_type is_enum; /** * @tparam Visitor a function object of the form: - * + * * @code - * struct functor { + * struct functor { * template * void operator()( const char* name )const; * }; @@ -46,19 +46,19 @@ struct reflector{ * * If T is an enum then the functor has the following form: * @code - * struct functor { + * struct functor { * template * void operator()( const char* name )const; * }; * @endcode - * + * * @param v a functor that will be called for each member on T * * @note - this method is not defined for non-reflected types. */ #ifdef DOXYGEN template - static inline void visit( const Visitor& v ); + static inline void visit( const Visitor& v ); #endif // DOXYGEN }; @@ -77,7 +77,7 @@ void throw_bad_enum_cast( const char* k, const char* e ); #define TEMPLATE template #else // Disable warning C4482: nonstandard extention used: enum 'enum_type::enum_value' used in qualified name - #pragma warning( disable: 4482 ) + #pragma warning( disable: 4482 ) #define TEMPLATE #endif @@ -98,14 +98,14 @@ template\ static inline void visit( const Visitor& v ) { \ BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_BASE, v, INHERITS ) \ BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_MEMBER, v, MEMBERS ) \ -} +} #define FC_REFLECT_DERIVED_IMPL_EXT( TYPE, INHERITS, MEMBERS ) \ template\ void fc::reflector::visit( const Visitor& v ) { \ BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_BASE, v, INHERITS ) \ BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_MEMBER, v, MEMBERS ) \ -} +} #endif // DOXYGEN @@ -132,15 +132,23 @@ template<> struct reflector { \ }\ return nullptr; \ } \ + static const char* to_string(ENUM elem) { \ + switch( elem ) { \ + BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_TO_STRING, ENUM, FIELDS ) \ + default: \ + fc::throw_bad_enum_cast( BOOST_PP_STRINGIZE(elem), BOOST_PP_STRINGIZE(ENUM) ); \ + }\ + return nullptr; \ + } \ static ENUM from_string( const char* s ) { \ BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_FROM_STRING, ENUM, FIELDS ) \ fc::throw_bad_enum_cast( s, BOOST_PP_STRINGIZE(ENUM) ); \ return ENUM();\ } \ }; \ -} +} -/* Note: FC_REFLECT_ENUM previously defined this function, but I don't think it ever +/* Note: FC_REFLECT_ENUM previously defined this function, but I don't think it ever * did what we expected it to do. I've disabled it for now. * * template \ @@ -152,7 +160,7 @@ template<> struct reflector { \ /** * @def FC_REFLECT_DERIVED(TYPE,INHERITS,MEMBERS) * - * @brief Specializes fc::reflector for TYPE where + * @brief Specializes fc::reflector for TYPE where * type inherits other reflected classes * * @param INHERITS - a sequence of base class names (basea)(baseb)(basec) @@ -170,7 +178,7 @@ template<> struct reflector {\ total_member_count = local_member_count BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_BASE_MEMBER_COUNT, +, INHERITS )\ }; \ FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \ -}; } +}; } #define FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, INHERITS, MEMBERS ) \ namespace fc { \ template struct get_typename { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \ @@ -183,9 +191,9 @@ template struct reflector {\ total_member_count = local_member_count BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_BASE_MEMBER_COUNT, +, INHERITS )\ }; \ FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \ -}; } +}; } -//BOOST_PP_SEQ_SIZE(MEMBERS), +//BOOST_PP_SEQ_SIZE(MEMBERS), /** * @def FC_REFLECT(TYPE,MEMBERS) diff --git a/src/rpc/json_connection.cpp b/src/rpc/json_connection.cpp index 81bbf42..ffd05f2 100644 --- a/src/rpc/json_connection.cpp +++ b/src/rpc/json_connection.cpp @@ -141,7 +141,7 @@ namespace fc { namespace rpc { } } } - else if( i != obj.end() ) + else if( i != obj.end() ) //handle any received JSON response { uint64_t id = i->value().as_int64(); auto await = _awaiting.find(id); @@ -149,11 +149,11 @@ namespace fc { namespace rpc { { auto r = obj.find("result"); auto e = obj.find("error"); - if( r != obj.end() ) + if( r != obj.end() ) //if regular result response { await->second->set_value( r->value() ); } - else if( e != obj.end() ) + else if( e != obj.end() ) //if error response { try {