Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
reflect.hpp File Reference
#include <fc/utility.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/enum.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <stdint.h>
#include <string.h>
#include <fc/reflect/typename.hpp>
Include dependency graph for reflect.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fc::reflector< T >
 defines visit functions for T Unless this is specialized, visit() will not be defined for T. More...
 
struct  fc::has_reflector_init< C >
 
struct  fc::reflect_init
 
struct  fc::reflector_init_visitor< Class >
 

Namespaces

namespace  fc
 namespace sysio::chain
 

Macros

#define FC_REFLECT_VISIT_BASE(r, visitor, base)
 
#define FC_TEMPLATE   template
 
#define FC_REFLECT_VISIT_MEMBER(r, visitor, elem)
 
#define FC_REFLECT_BASE_MEMBER_COUNT(r, OP, elem)
 
#define FC_REFLECT_MEMBER_COUNT(r, OP, elem)
 
#define FC_REFLECT_DERIVED_IMPL_INLINE(TYPE, INHERITS, MEMBERS)
 
#define FC_REFLECT_VISIT_ENUM(r, enum_type, elem)
 
#define FC_REFLECT_ENUM_TO_STRING(r, enum_type, elem)
 
#define FC_REFLECT_ENUM_TO_FC_STRING(r, enum_type, elem)
 
#define FC_REFLECT_ENUM_FROM_STRING(r, enum_type, elem)
 
#define FC_REFLECT_ENUM_FROM_STRING_CASE(r, enum_type, elem)
 
#define FC_REFLECT_ENUM(ENUM, FIELDS)
 
#define FC_REFLECT_DERIVED_TEMPLATE(TEMPLATE_ARGS, TYPE, INHERITS, MEMBERS)
 
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
 Specializes fc::reflector for TYPE where type inherits other reflected classes.
 
#define FC_REFLECT(TYPE, MEMBERS)
 Specializes fc::reflector for TYPE.
 
#define FC_REFLECT_TEMPLATE(TEMPLATE_ARGS, TYPE, MEMBERS)
 
#define FC_REFLECT_EMPTY(TYPE)
 
#define FC_REFLECT_TYPENAME(TYPE)
 

Functions

void fc::throw_bad_enum_cast (int64_t i, const char *e)
 
void fc::throw_bad_enum_cast (const char *k, const char *e)
 

Macro Definition Documentation

◆ FC_REFLECT

#define FC_REFLECT ( TYPE,
MEMBERS )
Value:
FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, MEMBERS )
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition reflect.hpp:298
Parameters
MEMBERS- a sequence of member names. (field1)(field2)(field3)
See also
FC_REFLECT_DERIVED

Definition at line 311 of file reflect.hpp.

311#define FC_REFLECT( TYPE, MEMBERS ) \
312 FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, MEMBERS )

◆ FC_REFLECT_BASE_MEMBER_COUNT

#define FC_REFLECT_BASE_MEMBER_COUNT ( r,
OP,
elem )
Value:
defines visit functions for T Unless this is specialized, visit() will not be defined for T.
Definition reflect.hpp:33
#define OP(opname)

Definition at line 160 of file reflect.hpp.

160#define FC_REFLECT_BASE_MEMBER_COUNT( r, OP, elem ) \
161 OP fc::reflector<elem>::total_member_count

◆ FC_REFLECT_DERIVED

#define FC_REFLECT_DERIVED ( TYPE,
INHERITS,
MEMBERS )
Value:
FC_REFLECT_DERIVED_TEMPLATE( (), TYPE, INHERITS, MEMBERS )
#define FC_REFLECT_DERIVED_TEMPLATE(TEMPLATE_ARGS, TYPE, INHERITS, MEMBERS)
Definition reflect.hpp:270
Parameters
INHERITS- a sequence of base class names (basea)(baseb)(basec)
MEMBERS- a sequence of member names. (field1)(field2)(field3)

Definition at line 298 of file reflect.hpp.

298#define FC_REFLECT_DERIVED( TYPE, INHERITS, MEMBERS ) \
299 FC_REFLECT_DERIVED_TEMPLATE( (), TYPE, INHERITS, MEMBERS )

◆ FC_REFLECT_DERIVED_IMPL_INLINE

#define FC_REFLECT_DERIVED_IMPL_INLINE ( TYPE,
INHERITS,
MEMBERS )
Value:
template<typename Visitor>\
static inline void visit_base( Visitor&& v ) { \
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_BASE, v, INHERITS ) \
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_MEMBER, v, MEMBERS ) \
} \
template<typename Visitor>\
static inline void visit( Visitor&& v ) { \
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_BASE, v, INHERITS ) \
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_MEMBER, v, MEMBERS ) \
init( std::forward<Visitor>(v) ); \
}
#define FC_REFLECT_VISIT_BASE(r, visitor, base)
Definition reflect.hpp:142
#define FC_REFLECT_VISIT_MEMBER(r, visitor, elem)
Definition reflect.hpp:154

Definition at line 166 of file reflect.hpp.

166#define FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \
167template<typename Visitor>\
168static inline void visit_base( Visitor&& v ) { \
169 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_BASE, v, INHERITS ) \
170 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_MEMBER, v, MEMBERS ) \
171} \
172template<typename Visitor>\
173static inline void visit( Visitor&& v ) { \
174 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_BASE, v, INHERITS ) \
175 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_MEMBER, v, MEMBERS ) \
176 init( std::forward<Visitor>(v) ); \
177}

◆ FC_REFLECT_DERIVED_TEMPLATE

#define FC_REFLECT_DERIVED_TEMPLATE ( TEMPLATE_ARGS,
TYPE,
INHERITS,
MEMBERS )
Value:
namespace fc { \
template<BOOST_PP_SEQ_ENUM(TEMPLATE_ARGS)> struct get_typename<TYPE> { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \
template<BOOST_PP_SEQ_ENUM(TEMPLATE_ARGS)> struct reflector<TYPE> {\
typedef TYPE type; \
template<typename Visitor> \
static auto init_imp(Visitor&& v, int) -> decltype(std::forward<Visitor>(v).reflector_init(), void()) { \
std::forward<Visitor>(v).reflector_init(); \
} \
template<typename Visitor> \
static auto init_imp(Visitor&& v, long) -> decltype(v, void()) {} \
template<typename Visitor> \
static auto init(Visitor&& v) -> decltype(init_imp(std::forward<Visitor>(v), 0), void()) { \
init_imp(std::forward<Visitor>(v), 0); \
} \
enum member_count_enum { \
local_member_count = 0 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_MEMBER_COUNT, +, MEMBERS ),\
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 ) \
static_assert( not fc::has_reflector_init<TYPE>::value || \
std::is_base_of<fc::reflect_init, TYPE>::value, "must derive from fc::reflect_init" ); \
static_assert( not std::is_base_of<fc::reflect_init, TYPE>::value || \
fc::has_reflector_init<TYPE>::value, "must provide reflector_init() method" ); \
}; }
void init()
Definition lib_test.cpp:3
namespace sysio::chain
Definition authority.cpp:3
#define FC_REFLECT_MEMBER_COUNT(r, OP, elem)
Definition reflect.hpp:163
#define FC_REFLECT_BASE_MEMBER_COUNT(r, OP, elem)
Definition reflect.hpp:160
static const char * name()
fc::false_type is_defined
Definition reflect.hpp:35
fc::false_type is_enum
Definition reflect.hpp:36

Definition at line 270 of file reflect.hpp.

270#define FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, INHERITS, MEMBERS ) \
271namespace fc { \
272 template<BOOST_PP_SEQ_ENUM(TEMPLATE_ARGS)> struct get_typename<TYPE> { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \
273template<BOOST_PP_SEQ_ENUM(TEMPLATE_ARGS)> struct reflector<TYPE> {\
274 typedef TYPE type; \
275 typedef fc::true_type is_defined; \
276 typedef fc::false_type is_enum; \
277 template<typename Visitor> \
278 static auto init_imp(Visitor&& v, int) -> decltype(std::forward<Visitor>(v).reflector_init(), void()) { \
279 std::forward<Visitor>(v).reflector_init(); \
280 } \
281 template<typename Visitor> \
282 static auto init_imp(Visitor&& v, long) -> decltype(v, void()) {} \
283 template<typename Visitor> \
284 static auto init(Visitor&& v) -> decltype(init_imp(std::forward<Visitor>(v), 0), void()) { \
285 init_imp(std::forward<Visitor>(v), 0); \
286 } \
287 enum member_count_enum { \
288 local_member_count = 0 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_MEMBER_COUNT, +, MEMBERS ),\
289 total_member_count = local_member_count BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_BASE_MEMBER_COUNT, +, INHERITS )\
290 }; \
291 FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \
292 static_assert( not fc::has_reflector_init<TYPE>::value || \
293 std::is_base_of<fc::reflect_init, TYPE>::value, "must derive from fc::reflect_init" ); \
294 static_assert( not std::is_base_of<fc::reflect_init, TYPE>::value || \
295 fc::has_reflector_init<TYPE>::value, "must provide reflector_init() method" ); \
296}; }

◆ FC_REFLECT_EMPTY

#define FC_REFLECT_EMPTY ( TYPE)
Value:
FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, BOOST_PP_SEQ_NIL )

Definition at line 317 of file reflect.hpp.

317#define FC_REFLECT_EMPTY( TYPE ) \
318 FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, BOOST_PP_SEQ_NIL )

◆ FC_REFLECT_ENUM

#define FC_REFLECT_ENUM ( ENUM,
FIELDS )

Definition at line 194 of file reflect.hpp.

194#define FC_REFLECT_ENUM( ENUM, FIELDS ) \
195namespace fc { \
196template<> struct reflector<ENUM> { \
197 typedef fc::true_type is_defined; \
198 typedef fc::true_type is_enum; \
199 static const char* to_string(ENUM elem) { \
200 switch( elem ) { \
201 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_TO_STRING, ENUM, FIELDS ) \
202 default: \
203 fc::throw_bad_enum_cast( fc::to_string(int64_t(elem)).c_str(), BOOST_PP_STRINGIZE(ENUM) ); \
204 }\
205 return nullptr; \
206 } \
207 static const char* to_string(int64_t i) { \
208 return to_string(ENUM(i)); \
209 } \
210 static fc::string to_fc_string(ENUM elem) { \
211 switch( elem ) { \
212 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_TO_FC_STRING, ENUM, FIELDS ) \
213 } \
214 return fc::to_string(int64_t(elem)); \
215 } \
216 static fc::string to_fc_string(int64_t i) { \
217 return to_fc_string(ENUM(i)); \
218 } \
219 static ENUM from_int(int64_t i) { \
220 ENUM e = ENUM(i); \
221 switch( e ) \
222 { \
223 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_FROM_STRING_CASE, ENUM, FIELDS ) \
224 break; \
225 default: \
226 fc::throw_bad_enum_cast( i, BOOST_PP_STRINGIZE(ENUM) ); \
227 } \
228 return e;\
229 } \
230 static ENUM from_string( const char* s ) { \
231 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_FROM_STRING, ENUM, FIELDS ) \
232 int64_t i = 0; \
233 try \
234 { \
235 i = boost::lexical_cast<int64_t>(s); \
236 } \
237 catch( const boost::bad_lexical_cast& e ) \
238 { \
239 fc::throw_bad_enum_cast( s, BOOST_PP_STRINGIZE(ENUM) ); \
240 } \
241 return from_int(i); \
242 } \
243 template< typename Visitor > \
244 static void visit( Visitor& v ) \
245 { \
246 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_VISIT_ENUM, ENUM, FIELDS ) \
247 } \
248}; \
249template<> struct get_typename<ENUM> { static const char* name() { return BOOST_PP_STRINGIZE(ENUM); } }; \
250}

◆ FC_REFLECT_ENUM_FROM_STRING

#define FC_REFLECT_ENUM_FROM_STRING ( r,
enum_type,
elem )
Value:
if( strcmp( s, BOOST_PP_STRINGIZE(elem) ) == 0 ) return enum_type::elem;
char * s

Definition at line 189 of file reflect.hpp.

189#define FC_REFLECT_ENUM_FROM_STRING( r, enum_type, elem ) \
190 if( strcmp( s, BOOST_PP_STRINGIZE(elem) ) == 0 ) return enum_type::elem;

◆ FC_REFLECT_ENUM_FROM_STRING_CASE

#define FC_REFLECT_ENUM_FROM_STRING_CASE ( r,
enum_type,
elem )
Value:
case enum_type::elem:

Definition at line 191 of file reflect.hpp.

191#define FC_REFLECT_ENUM_FROM_STRING_CASE( r, enum_type, elem ) \
192 case enum_type::elem:

◆ FC_REFLECT_ENUM_TO_FC_STRING

#define FC_REFLECT_ENUM_TO_FC_STRING ( r,
enum_type,
elem )
Value:
case enum_type::elem: return fc::string(BOOST_PP_STRINGIZE(elem));
std::string string
Definition string.hpp:10

Definition at line 186 of file reflect.hpp.

186#define FC_REFLECT_ENUM_TO_FC_STRING( r, enum_type, elem ) \
187 case enum_type::elem: return fc::string(BOOST_PP_STRINGIZE(elem));

◆ FC_REFLECT_ENUM_TO_STRING

#define FC_REFLECT_ENUM_TO_STRING ( r,
enum_type,
elem )
Value:
case enum_type::elem: return BOOST_PP_STRINGIZE(elem);

Definition at line 184 of file reflect.hpp.

184#define FC_REFLECT_ENUM_TO_STRING( r, enum_type, elem ) \
185 case enum_type::elem: return BOOST_PP_STRINGIZE(elem);

◆ FC_REFLECT_MEMBER_COUNT

#define FC_REFLECT_MEMBER_COUNT ( r,
OP,
elem )
Value:
OP 1

Definition at line 163 of file reflect.hpp.

163#define FC_REFLECT_MEMBER_COUNT( r, OP, elem ) \
164 OP 1

◆ FC_REFLECT_TEMPLATE

#define FC_REFLECT_TEMPLATE ( TEMPLATE_ARGS,
TYPE,
MEMBERS )
Value:
FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, BOOST_PP_SEQ_NIL, MEMBERS )

Definition at line 314 of file reflect.hpp.

314#define FC_REFLECT_TEMPLATE( TEMPLATE_ARGS, TYPE, MEMBERS ) \
315 FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, BOOST_PP_SEQ_NIL, MEMBERS )

◆ FC_REFLECT_TYPENAME

#define FC_REFLECT_TYPENAME ( TYPE)
Value:
namespace fc { \
template<> struct get_typename<TYPE> { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \
}

Definition at line 320 of file reflect.hpp.

320#define FC_REFLECT_TYPENAME( TYPE ) \
321namespace fc { \
322 template<> struct get_typename<TYPE> { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \
323}

◆ FC_REFLECT_VISIT_BASE

#define FC_REFLECT_VISIT_BASE ( r,
visitor,
base )
Value:

Definition at line 142 of file reflect.hpp.

142#define FC_REFLECT_VISIT_BASE(r, visitor, base) \
143 fc::reflector<base>::visit_base( visitor );

◆ FC_REFLECT_VISIT_ENUM

#define FC_REFLECT_VISIT_ENUM ( r,
enum_type,
elem )
Value:
v.operator()(BOOST_PP_STRINGIZE(elem), int64_t(enum_type::elem) );
signed __int64 int64_t
Definition stdint.h:135

Definition at line 182 of file reflect.hpp.

182#define FC_REFLECT_VISIT_ENUM( r, enum_type, elem ) \
183 v.operator()(BOOST_PP_STRINGIZE(elem), int64_t(enum_type::elem) );

◆ FC_REFLECT_VISIT_MEMBER

#define FC_REFLECT_VISIT_MEMBER ( r,
visitor,
elem )
Value:
{ typedef decltype((static_cast<type*>(nullptr))->elem) member_type; \
visitor.FC_TEMPLATE operator()<member_type,type,&type::elem>( BOOST_PP_STRINGIZE(elem) ); \
}
yh_object_type type
Definition yubihsm.h:672

Definition at line 154 of file reflect.hpp.

154#define FC_REFLECT_VISIT_MEMBER( r, visitor, elem ) \
155{ typedef decltype((static_cast<type*>(nullptr))->elem) member_type; \
156 visitor.FC_TEMPLATE operator()<member_type,type,&type::elem>( BOOST_PP_STRINGIZE(elem) ); \
157}

◆ FC_TEMPLATE

#define FC_TEMPLATE   template

Definition at line 147 of file reflect.hpp.