| [746ff1] | 1 | /*
 | 
|---|
| [1afcbe] | 2 |  * Factory_impl.hpp
 | 
|---|
| [746ff1] | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Jan 3, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | // include config.h
 | 
|---|
 | 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 10 | #include <config.h>
 | 
|---|
 | 11 | #endif
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | #include <boost/preprocessor/debug/assert.hpp>
 | 
|---|
 | 14 | #include <boost/preprocessor/facilities/empty.hpp>
 | 
|---|
 | 15 | #include <boost/preprocessor/iteration/local.hpp>
 | 
|---|
 | 16 | #include <boost/preprocessor/punctuation/comma.hpp>
 | 
|---|
 | 17 | #include <boost/preprocessor/punctuation/comma_if.hpp>
 | 
|---|
| [724564] | 18 | #include <boost/preprocessor/punctuation/paren.hpp>
 | 
|---|
| [746ff1] | 19 | #include <boost/preprocessor/seq/elem.hpp>
 | 
|---|
 | 20 | #include <boost/preprocessor/seq/size.hpp>
 | 
|---|
 | 21 | #include <boost/preprocessor/stringize.hpp>
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | // check for required type_seq
 | 
|---|
 | 24 | #ifdef type_seq
 | 
|---|
 | 25 | #define type_seq_size BOOST_PP_SEQ_SIZE(type_seq)
 | 
|---|
 | 26 | #else
 | 
|---|
 | 27 | BOOST_PP_ASSERT_MSG( 0 , \
 | 
|---|
 | 28 |     "std::cout << \"missing type_seq for creating Factory<T>\" << std::endl")
 | 
|---|
 | 29 | #define type_seq ()
 | 
|---|
 | 30 | #endif
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | // check for required Abstract_Interface_Class
 | 
|---|
 | 33 | #ifndef Abstract_Interface_Class
 | 
|---|
 | 34 |     BOOST_PP_ASSERT_MSG( 0 , \
 | 
|---|
 | 35 |         "std::cout << \"missing Abstract_Interface_Class for creating Factory<T>\" << std::endl")
 | 
|---|
 | 36 | #define Abstract_Interface_Class NONE
 | 
|---|
 | 37 | #endif
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | // check for required Abstract_Encapsulation_Class
 | 
|---|
 | 40 | #ifndef Abstract_Encapsulation_Class
 | 
|---|
 | 41 |     BOOST_PP_ASSERT_MSG( 0 , \
 | 
|---|
 | 42 |         "std::cout << \"missing Abstract_Encapsulation_Class for creating Factory<T>\" << std::endl")
 | 
|---|
 | 43 | #define Abstract_Encapsulation_Class NONE
 | 
|---|
 | 44 | #endif
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | // check for type_name_space, is only optional
 | 
|---|
 | 47 | #ifndef type_name_space
 | 
|---|
 | 48 | #define type_name_space BOOST_PP_EMPTY()
 | 
|---|
 | 49 | #endif
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | #ifndef type_name_space_suffix
 | 
|---|
 | 52 | #define type_name_space_suffix BOOST_PP_EMPTY()
 | 
|---|
 | 53 | #endif
 | 
|---|
 | 54 | 
 | 
|---|
| [724564] | 55 | 
 | 
|---|
| [746ff1] | 56 | /** Functions that allows to print a given seq of elements in the way of
 | 
|---|
 | 57 |  *  std::map from strings to enums.
 | 
|---|
 | 58 |  *
 | 
|---|
 | 59 |  * e.g. let "seq" be defined as
 | 
|---|
 | 60 |  * #define seq (one)(two)(three)(four)
 | 
|---|
 | 61 |  *
 | 
|---|
 | 62 |  * then we use
 | 
|---|
| [724564] | 63 |  * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(seqsize, n, seq, EnumMap, test::)
 | 
|---|
| [746ff1] | 64 |  * #define BOOST_PP_LOCAL_LIMITS  (0, BOOST_PP_SEQ_SIZE(seq)-1 )
 | 
|---|
 | 65 |  * #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 66 |  *
 | 
|---|
 | 67 |  * which expands by the preprocessor to:
 | 
|---|
| [724564] | 68 |  * EnumMap[one] = test::one;
 | 
|---|
 | 69 |  * EnumMap[two] = test::two;
 | 
|---|
 | 70 |  * EnumMap[three] = test::three;
 | 
|---|
 | 71 |  * EnumMap[four] = test::four;
 | 
|---|
 | 72 |  *
 | 
|---|
| [746ff1] | 73 |  */
 | 
|---|
| [d76c105] | 74 | #define seqitems_as_enum_key_map(z,n,_seq_with_elements, _map, _keytype, _key_name_space, _type_name_space, _type_suffix) \
 | 
|---|
 | 75 |   _map [ _key_name_space \
 | 
|---|
 | 76 |   BOOST_PP_SEQ_ELEM(n, _seq_with_elements) \
 | 
|---|
 | 77 |   ] = _keytype< _type_name_space BOOST_PP_SEQ_ELEM(n, _seq_with_elements) _type_suffix > ();
 | 
|---|
| [746ff1] | 78 | 
 | 
|---|
 | 79 | /** Functions that allows to print a given seq of elements in the way of
 | 
|---|
 | 80 |  *  std::map from strings to enums.
 | 
|---|
 | 81 |  *
 | 
|---|
 | 82 |  * e.g. let "seq" be defined as
 | 
|---|
 | 83 |  * #define seq (one)(two)(three)(four)
 | 
|---|
 | 84 |  *
 | 
|---|
 | 85 |  * then we use
 | 
|---|
| [724564] | 86 |  * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(seqsize, n, seq, EnumMap, typid BOOST_PP_LPAREN() super:: , BOOST_PP_RPAREN().name() , test::)
 | 
|---|
| [746ff1] | 87 |  * #define BOOST_PP_LOCAL_LIMITS  (0, BOOST_PP_SEQ_SIZE(seq)-1 )
 | 
|---|
 | 88 |  * #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 89 |  *
 | 
|---|
 | 90 |  * which expands by the preprocessor to:
 | 
|---|
| [724564] | 91 |  * EnumMap[ typeid ( super:: one ) .name() ] = test::one;
 | 
|---|
 | 92 |  * EnumMap[ typeid ( super:: two ) .name() ] = test::two;
 | 
|---|
 | 93 |  * EnumMap[ typeid ( super:: three ) .name() ] = test::three;
 | 
|---|
 | 94 |  * EnumMap[ typeid ( super:: four ) .name() ] = test::four;
 | 
|---|
 | 95 |  *
 | 
|---|
 | 96 |  * or we use
 | 
|---|
 | 97 |  * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(seqsize, n, seq, EnumMap, BOOST_PP_STRINGIZE BOOST_PP_LPAREN() , BOOST_PP_RPAREN() , test::)
 | 
|---|
 | 98 |  * #define BOOST_PP_LOCAL_LIMITS  (0, BOOST_PP_SEQ_SIZE(seq)-1 )
 | 
|---|
 | 99 |  * #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 100 |  *
 | 
|---|
 | 101 |  * which expands by the preprocessor to:
 | 
|---|
 | 102 |  * EnumMap[ "one" ] = test:: one;
 | 
|---|
 | 103 |  * EnumMap[ "two" ] = test:: two;
 | 
|---|
 | 104 |  * EnumMap[ "three" ] = test:: three;
 | 
|---|
 | 105 |  * EnumMap[ "four" ] = test:: four;
 | 
|---|
| [746ff1] | 106 |  */
 | 
|---|
| [d76c105] | 107 | #define seqitems_as_enum_value_map(z,n,_seq_with_elements, _map, _type_specifier, _type_suffix, _enum_name_space) \
 | 
|---|
 | 108 |   _map [ _type_specifier  \
 | 
|---|
 | 109 |   BOOST_PP_SEQ_ELEM(n, _seq_with_elements) \
 | 
|---|
 | 110 |   _type_suffix \
 | 
|---|
 | 111 |   ] = _enum_name_space BOOST_PP_SEQ_ELEM(n, _seq_with_elements);
 | 
|---|
| [746ff1] | 112 | 
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 | template <>
 | 
|---|
 | 115 | void Factory<Abstract_Interface_Class>::FillEnumTable()
 | 
|---|
 | 116 | {
 | 
|---|
 | 117 |   // insert all known (enum, string) keys
 | 
|---|
| [724564] | 118 | #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(~, n, type_seq, enums, BOOST_PP_STRINGIZE BOOST_PP_LPAREN() , BOOST_PP_RPAREN() , FactoryTypeList<Abstract_Interface_Class>::)
 | 
|---|
 | 119 | #define BOOST_PP_LOCAL_LIMITS  (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
 | 
|---|
 | 120 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 |   // insert all known (type, enum) keys
 | 
|---|
 | 123 | #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_value_map(~, n, type_seq, types, typeid BOOST_PP_LPAREN() type_name_space , type_name_space_suffix BOOST_PP_RPAREN() .name(), FactoryTypeList<Abstract_Interface_Class>::)
 | 
|---|
| [746ff1] | 124 | #define BOOST_PP_LOCAL_LIMITS  (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
 | 
|---|
 | 125 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 |   // create invert mapping (string, enum)
 | 
|---|
 | 128 |   for (Factory<Abstract_Interface_Class>::EnumMap::const_iterator iter = enums.begin();
 | 
|---|
 | 129 |       iter != enums.end();
 | 
|---|
 | 130 |       ++iter) {
 | 
|---|
 | 131 |     names.insert(make_pair(iter->second, iter->first));
 | 
|---|
 | 132 |   }
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | template <>
 | 
|---|
 | 136 | void Factory<Abstract_Interface_Class>::FillPrototypeTable()
 | 
|---|
 | 137 | {
 | 
|---|
 | 138 |   // fill PrototypeTable
 | 
|---|
| [d76c105] | 139 | #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, type_seq, PrototypeTable, new Creator< Abstract_Interface_Class BOOST_PP_COMMA() Abstract_Encapsulation_Class, FactoryTypeList<Abstract_Interface_Class>::, type_name_space, type_name_space_suffix > )
 | 
|---|
| [746ff1] | 140 | #define BOOST_PP_LOCAL_LIMITS  (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
 | 
|---|
 | 141 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 142 | }
 | 
|---|
 | 143 | 
 | 
|---|