Boost Reflect Library 0.1.0
old.hpp
Go to the documentation of this file.
00001 
00002 
00003 #ifndef DOXYGEN
00004 #define CUSTOM_MEMBER_CASES(r, data, i, elem)\
00005 case BOOST_PP_TUPLE_ELEM( 3, 1, elem ):\
00006    v.accept_member( name, &data::BOOST_PP_TUPLE_ELEM(3, 0, elem), BOOST_PP_STRINGIZE( BOOST_PP_TUPLE_ELEM(3,0,elem) ), BOOST_PP_TUPLE_ELEM(3, 2,elem) );\
00007    break;
00008 
00009 #define CUSTOM_MEMBER_ALL(r, data, i, elem)\
00010    v.accept_member( name, &data::BOOST_PP_TUPLE_ELEM(3, 0, elem), BOOST_PP_STRINGIZE( BOOST_PP_TUPLE_ELEM(3,0,elem) ), BOOST_PP_TUPLE_ELEM(3, 2,elem) );\
00011 
00012 #define MEMBER_CASES(r, data, i, elem)\
00013 case i:\
00014    v.accept_member( name, &data::elem, BOOST_PP_STRINGIZE( elem ), i ); \
00015    break;
00016 
00017 #define MEMBER_ALL(r, data, i, elem)\
00018    v.accept_member( name, &data::elem, BOOST_PP_STRINGIZE( elem ), i );
00019 
00020 #define INHERITS (baseA)(baseB)
00021 
00022 #define ACCEPT_BASE(r, data, i, elem) \
00023     v.accept_base( *static_cast<elem*>(&name), BOOST_PP_STRINGIZE( elem ), field );
00024 
00025 
00026 #define BOOST_REFLECT_IMPL( CONST,TYPE, INHERITS, MEMBERS ) \
00027 template<typename Visitor>\
00028 static inline void visit( CONST TYPE& name, Visitor& v, uint32_t field = -1 ) { \
00029     v.start(name, BOOST_PP_STRINGIZE(TYPE) );\
00030     BOOST_PP_SEQ_FOR_EACH_I( ACCEPT_BASE, TYPE, INHERITS ) \
00031     switch( field ) { \
00032         case -1: \
00033             BOOST_PP_SEQ_FOR_EACH_I( MEMBER_ALL, TYPE, MEMBERS ) \
00034             break; \
00035         BOOST_PP_SEQ_FOR_EACH_I( MEMBER_CASES, TYPE, MEMBERS ) \
00036         default: \
00037             v.not_found( name, field );\
00038     }\
00039     v.end(name, BOOST_PP_STRINGIZE(TYPE) );\
00040 } \
00041 
00042 #define BOOST_REFLECT_CUSTOM_IMPL( CONST,TYPE, INHERITS, MEMBERS ) \
00043 template<typename Visitor>\
00044 static inline void visit( CONST TYPE& name, Visitor& v, uint32_t field = -1 ) { \
00045     v.start(name, BOOST_PP_STRINGIZE(TYPE) );\
00046     BOOST_PP_SEQ_FOR_EACH_I( ACCEPT_BASE, TYPE, INHERITS ) \
00047     switch( field ) { \
00048         case -1: \
00049             BOOST_PP_SEQ_FOR_EACH_I( CUSTOM_MEMBER_ALL, TYPE, MEMBERS ) \
00050             break; \
00051         BOOST_PP_SEQ_FOR_EACH_I( CUSTOM_MEMBER_CASES, TYPE, MEMBERS ) \
00052         default: \
00053             v.not_found( name, field );\
00054     }\
00055     v.end(name, BOOST_PP_STRINGIZE(TYPE) );\
00056 } \
00057 
00058 #define BOOST_REFLECT_EMPTY
00059 
00060 #define VISIT_BASE( r, data, elem ) reflector<elem>::visit( *((vtable<elem,InterfaceDelegate>*)&a), data );
00061 #define VISIT_MEMBER( r, data, elem ) t.template accept<data>( a.elem, BOOST_PP_STRINGIZE(elem) );
00062 #endif // DOXYGEN
00063 
00064 /**
00065  *  @brief Specializes boost::reflect::reflector for TYPE
00066  *
00067  *  @param INHERITS - a sequence of base class names (basea)(baseb)(basec)
00068  *  @param MEMBERS - a sequence of member names.  (field1)(field2)(field3)
00069  */
00070 #define BOOST_REFLECT( TYPE, INHERITS, MEMBERS ) \
00071 BOOST_REFLECT_TYPEINFO(TYPE) \
00072 namespace boost { namespace reflect { \
00073 template<> struct reflector<TYPE> {\
00074     BOOST_REFLECT_IMPL( const, TYPE, INHERITS, MEMBERS ) \
00075     BOOST_REFLECT_IMPL( BOOST_REFLECT_EMPTY, TYPE, INHERITS, MEMBERS ) \
00076 \
00077     template<typename T, typename InterfaceDelegate> \
00078     static void visit( boost::reflect::vtable<TYPE,InterfaceDelegate>& a, T& t ) { \
00079         BOOST_PP_SEQ_FOR_EACH( VISIT_BASE, t, INHERITS ) \
00080         BOOST_PP_SEQ_FOR_EACH( VISIT_MEMBER, TYPE, MEMBERS ) \
00081     } \
00082 }; } }
00083 
00084 
00085 /**
00086  *   This macro is identical to BOOST_REFLECT, except that it gives you
00087  *   the ability to customize field numbers and flags.
00088  *
00089  *   @param MEMBERS  - a sequence of 3 param tuples.
00090  *                    ((field_name, NUMBER, FLAGS))((field_name1, NUMBER, FLAGS))
00091  *
00092  */
00093 #define BOOST_REFLECT_CUSTOM( TYPE, INHERITS, MEMBERS ) \
00094     BOOST_REFLECT_TYPEINFO(TYPE) \
00095 namespace boost { namespace reflect { \
00096 template<> struct reflector<TYPE> { \
00097     BOOST_REFLECT_CUSTOM_IMPL( const, TYPE, INHERITS, MEMBERS ) \
00098     BOOST_REFLECT_CUSTOM_IMPL( BOOST_REFLECT_EMPTY, TYPE, INHERITS, MEMBERS ) \
00099 } } }

© Daniel Larimer 2010-2011 - Licensed under Boost Software License, Version 1.0 Boost Reflect Library