BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
Classes | Namespaces | Macros | Functions
reflect.hpp File Reference

Defines types and macros used to provide reflection. More...

#include <fc/string.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 <type_traits>
#include <fc/reflect/typename.hpp>
#include <fc/reflect/typelist.hpp>

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::member_names::member_name< Class, index >
 A template which stores the name of the native member at a given index in a given class. More...
 
struct  fc::field_reflection< Index, Container, Member, field >
 A template to store compile-time information about a field in a reflected struct. More...
 
struct  fc::inherited_field_reflection< IndexInBase, Base, Derived, Member, field >
 
struct  fc::impl::Reflect_type< Container >
 Helper template to create a field_reflection without any commas (makes it macro-friendly) More...
 
struct  fc::impl::Reflect_type< Container >::with_field_type< Member >
 
struct  fc::impl::Reflect_type< Container >::with_field_type< Member >::at_index< Index >
 
struct  fc::impl::Reflect_type< Container >::with_field_type< Member >::at_index< Index >::with_field_pointer< field >
 
struct  fc::impl::Derivation_reflection_transformer< Derived >
 Template to make a transformer of a field_reflection from a base class to a derived class. More...
 
struct  fc::impl::Derivation_reflection_transformer< Derived >::transform< typename >
 
struct  fc::impl::Derivation_reflection_transformer< Derived >::transform< field_reflection< IndexInBase, BaseContainer, Member, field > >
 
struct  fc::impl::Derivation_reflection_transformer< Derived >::transform< inherited_field_reflection< IndexInBase, BaseContainer, IntermediateContainer, Member, field > >
 
struct  fc::reflector< T >
 defines visit functions for T Unless this is specialized, visit() will not be defined for T. More...
 

Namespaces

 fc
 
 fc::member_names
 
 fc::impl
 

Macros

#define FC_CONCAT_BASE_MEMBER_REFLECTIONS(r, derived, base)   ::add_list<typelist::transform<reflector<base>::members, impl::Derivation_reflection_transformer<derived>>>
 Macro to transform reflected fields of a base class to a derived class and concatenate them to a type list. More...
 
#define FC_CONCAT_MEMBER_REFLECTION(r, container, idx, member)
 Macro to concatenate a new field_reflection to a typelist. More...
 
#define FC_REFLECT_MEMBER_NAME(r, container, idx, member)   template<> struct member_name<container, idx> { constexpr static const char* value = BOOST_PP_STRINGIZE(member); };
 
#define FC_REFLECT_TEMPLATE_MEMBER_NAME(r, data, idx, member)
 
#define FC_CONCAT_TYPE(r, x, TYPE)   ::add<TYPE>
 Macro to concatenate a new type to a typelist. More...
 
#define FC_REFLECT_VISIT_BASE(r, visitor, base)   fc::reflector<base>::visit( visitor );
 
#define TEMPLATE   template
 
#define FC_REFLECT_VISIT_MEMBER(r, visitor, elem)
 
#define FC_REFLECT_VISIT_MEMBER_I(r, visitor, I, elem)   case I: FC_REFLECT_VISIT_MEMBER( r, visitor, elem ) break;
 
#define FC_REFLECT_DERIVED_IMPL_INLINE(TYPE, INHERITS, MEMBERS)
 
#define FC_REFLECT_VISIT_ENUM(r, enum_type, elem)   v.operator()(BOOST_PP_STRINGIZE(elem), int64_t(enum_type::elem) );
 
#define FC_REFLECT_ENUM_TO_STRING(r, enum_type, elem)   case enum_type::elem: return BOOST_PP_STRINGIZE(elem);
 
#define FC_REFLECT_ENUM_TO_FC_STRING(r, enum_type, elem)   case enum_type::elem: return std::string(BOOST_PP_STRINGIZE(elem));
 
#define FC_REFLECT_ENUM_FROM_STRING(r, 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_DERIVED(TYPE, INHERITS, MEMBERS)
 Specializes fc::reflector for TYPE where type inherits other reflected classes. More...
 
#define FC_REFLECT_DERIVED_TEMPLATE(TEMPLATE_ARGS, TYPE, INHERITS, MEMBERS)
 
#define FC_REFLECT_DERIVED_NO_TYPENAME(TYPE, INHERITS, MEMBERS)
 
#define FC_REFLECT(TYPE, MEMBERS)   FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, MEMBERS )
 Specializes fc::reflector for TYPE. More...
 
#define FC_REFLECT_TEMPLATE(TEMPLATE_ARGS, TYPE, MEMBERS)   FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, BOOST_PP_SEQ_NIL, MEMBERS )
 
#define FC_REFLECT_EMPTY(TYPE)   FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, BOOST_PP_SEQ_NIL )
 
#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)
 

Detailed Description

Defines types and macros used to provide reflection.

Definition in file reflect.hpp.

Macro Definition Documentation

#define FC_CONCAT_BASE_MEMBER_REFLECTIONS (   r,
  derived,
  base 
)    ::add_list<typelist::transform<reflector<base>::members, impl::Derivation_reflection_transformer<derived>>>

Macro to transform reflected fields of a base class to a derived class and concatenate them to a type list.

Definition at line 114 of file reflect.hpp.

#define FC_CONCAT_MEMBER_REFLECTION (   r,
  container,
  idx,
  member 
)
Value:
::add<typename impl::Reflect_type<container>::template with_field_type<decltype(container::member)> \
::template at_index<idx> \
::template with_field_pointer<&container::member>::type>

Macro to concatenate a new field_reflection to a typelist.

Definition at line 117 of file reflect.hpp.

#define FC_CONCAT_TYPE (   r,
  x,
  TYPE 
)    ::add<TYPE>

Macro to concatenate a new type to a typelist.

Definition at line 127 of file reflect.hpp.

#define FC_REFLECT (   TYPE,
  MEMBERS 
)    FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, MEMBERS )

Specializes fc::reflector for TYPE.

Parameters
MEMBERS- a sequence of member names. (field1)(field2)(field3)
See also
FC_REFLECT_DERIVED

Definition at line 386 of file reflect.hpp.

#define FC_REFLECT_DERIVED (   TYPE,
  INHERITS,
  MEMBERS 
)
Value:
namespace fc { \
template<> struct get_typename<TYPE> { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \
template<> struct reflector<TYPE> {\
typedef TYPE type; \
typedef std::true_type is_defined; \
using native_members = \
using inherited_members = \
using base_classes = typename typelist::builder<>::type \
BOOST_PP_SEQ_FOR_EACH( FC_CONCAT_TYPE, x, INHERITS ) ::finalize; \
enum member_count_enum { \
local_member_count = typelist::length<native_members>(), \
total_member_count = typelist::length<members>() \
}; \
FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \
}; \
namespace member_names { \
BOOST_PP_SEQ_FOR_EACH_I( FC_REFLECT_MEMBER_NAME, TYPE, MEMBERS ) \
} }
#define FC_REFLECT_DERIVED_IMPL_INLINE(TYPE, INHERITS, MEMBERS)
Definition: reflect.hpp:207
#define FC_CONCAT_BASE_MEMBER_REFLECTIONS(r, derived, base)
Macro to transform reflected fields of a base class to a derived class and concatenate them to a type...
Definition: reflect.hpp:114
#define FC_REFLECT_MEMBER_NAME(r, container, idx, member)
Definition: reflect.hpp:121
#define FC_CONCAT_TYPE(r, x, TYPE)
Macro to concatenate a new type to a typelist.
Definition: reflect.hpp:127
#define FC_CONCAT_MEMBER_REFLECTION(r, container, idx, member)
Macro to concatenate a new field_reflection to a typelist.
Definition: reflect.hpp:117
Definition: api.hpp:15
typename impl::concat< Lists... >::type concat
Concatenate two or more typelists together.
Definition: typelist.hpp:150

Specializes fc::reflector for TYPE where type inherits other reflected classes.

Parameters
INHERITS- a sequence of base class names (basea)(baseb)(basec)
MEMBERS- a sequence of member names. (field1)(field2)(field3)

Definition at line 304 of file reflect.hpp.

#define FC_REFLECT_DERIVED_IMPL_INLINE (   TYPE,
  INHERITS,
  MEMBERS 
)
Value:
template<typename Visitor>\
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_VISIT_BASE(r, visitor, base)
Definition: reflect.hpp:186
#define FC_REFLECT_VISIT_MEMBER(r, visitor, elem)
Definition: reflect.hpp:198

Definition at line 207 of file reflect.hpp.

#define FC_REFLECT_DERIVED_NO_TYPENAME (   TYPE,
  INHERITS,
  MEMBERS 
)
Value:
namespace fc { \
template<> struct reflector<TYPE> {\
typedef TYPE type; \
typedef std::true_type is_defined; \
using native_members = \
BOOST_PP_SEQ_FOR_EACH( FC_CONCAT_TYPE, x, INHERITS ) ::finalize; \
enum member_count_enum { \
local_member_count = typelist::length<native_members>(), \
total_member_count = typelist::length<members>() \
}; \
FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \
}; \
}
typelist::list<> members
A typelist with a field_reflection for each member of the struct, starting with inherited members...
Definition: reflect.hpp:147
typelist::list<> inherited_members
A typelist with a field_reflection for each inherited member of the struct.
Definition: reflect.hpp:145
#define FC_REFLECT_DERIVED_IMPL_INLINE(TYPE, INHERITS, MEMBERS)
Definition: reflect.hpp:207
#define FC_CONCAT_BASE_MEMBER_REFLECTIONS(r, derived, base)
Macro to transform reflected fields of a base class to a derived class and concatenate them to a type...
Definition: reflect.hpp:114
typelist::list<> native_members
A typelist with a field_reflection for each native member (non-inherited) of the struct.
Definition: reflect.hpp:143
typelist::list<> base_classes
A typelist of base classes for this type.
Definition: reflect.hpp:149
std::false_type is_defined
Definition: reflect.hpp:141
#define FC_CONCAT_TYPE(r, x, TYPE)
Macro to concatenate a new type to a typelist.
Definition: reflect.hpp:127
#define FC_CONCAT_MEMBER_REFLECTION(r, container, idx, member)
Macro to concatenate a new field_reflection to a typelist.
Definition: reflect.hpp:117
Definition: api.hpp:15
typename impl::concat< Lists... >::type concat
Concatenate two or more typelists together.
Definition: typelist.hpp:150

Definition at line 356 of file reflect.hpp.

#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; \
typedef std::true_type is_defined; \
using native_members = \
using inherited_members = \
using base_classes = typename typelist::builder<>::type \
BOOST_PP_SEQ_FOR_EACH( FC_CONCAT_TYPE, x, INHERITS ) ::finalize; \
enum member_count_enum { \
local_member_count = typelist::length<native_members>(), \
total_member_count = typelist::length<members>() \
}; \
FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \
}; \
namespace member_names { \
BOOST_PP_SEQ_FOR_EACH_I( FC_REFLECT_TEMPLATE_MEMBER_NAME, (TEMPLATE_ARGS)(TYPE), MEMBERS ) \
} }
#define FC_REFLECT_DERIVED_IMPL_INLINE(TYPE, INHERITS, MEMBERS)
Definition: reflect.hpp:207
#define FC_CONCAT_BASE_MEMBER_REFLECTIONS(r, derived, base)
Macro to transform reflected fields of a base class to a derived class and concatenate them to a type...
Definition: reflect.hpp:114
#define FC_CONCAT_TYPE(r, x, TYPE)
Macro to concatenate a new type to a typelist.
Definition: reflect.hpp:127
#define FC_CONCAT_MEMBER_REFLECTION(r, container, idx, member)
Macro to concatenate a new field_reflection to a typelist.
Definition: reflect.hpp:117
Definition: api.hpp:15
typename impl::concat< Lists... >::type concat
Concatenate two or more typelists together.
Definition: typelist.hpp:150
#define FC_REFLECT_TEMPLATE_MEMBER_NAME(r, data, idx, member)
Definition: reflect.hpp:123

Definition at line 329 of file reflect.hpp.

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

Definition at line 393 of file reflect.hpp.

#define FC_REFLECT_ENUM (   ENUM,
  FIELDS 
)

Definition at line 229 of file reflect.hpp.

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

Definition at line 224 of file reflect.hpp.

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

Definition at line 226 of file reflect.hpp.

#define FC_REFLECT_ENUM_TO_FC_STRING (   r,
  enum_type,
  elem 
)    case enum_type::elem: return std::string(BOOST_PP_STRINGIZE(elem));

Definition at line 221 of file reflect.hpp.

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

Definition at line 219 of file reflect.hpp.

#define FC_REFLECT_MEMBER_NAME (   r,
  container,
  idx,
  member 
)    template<> struct member_name<container, idx> { constexpr static const char* value = BOOST_PP_STRINGIZE(member); };

Definition at line 121 of file reflect.hpp.

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

Definition at line 390 of file reflect.hpp.

#define FC_REFLECT_TEMPLATE_MEMBER_NAME (   r,
  data,
  idx,
  member 
)
Value:
template<BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_ELEM(0, data))> struct member_name<BOOST_PP_SEQ_ELEM(1, data), idx> { \
constexpr static const char* value = BOOST_PP_STRINGIZE(member); };

Definition at line 123 of file reflect.hpp.

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

Definition at line 396 of file reflect.hpp.

#define FC_REFLECT_VISIT_BASE (   r,
  visitor,
  base 
)    fc::reflector<base>::visit( visitor );

Definition at line 186 of file reflect.hpp.

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

Definition at line 217 of file reflect.hpp.

#define FC_REFLECT_VISIT_MEMBER (   r,
  visitor,
  elem 
)
Value:
{ typedef decltype(((type*)nullptr)->elem) member_type; \
visitor.TEMPLATE operator()<member_type,type,&type::elem>( BOOST_PP_STRINGIZE(elem) ); \
}
#define TEMPLATE
Definition: reflect.hpp:191

Definition at line 198 of file reflect.hpp.

#define FC_REFLECT_VISIT_MEMBER_I (   r,
  visitor,
  I,
  elem 
)    case I: FC_REFLECT_VISIT_MEMBER( r, visitor, elem ) break;

Definition at line 203 of file reflect.hpp.

#define TEMPLATE   template

Definition at line 191 of file reflect.hpp.