| 1 | /*
|
|---|
| 2 | * ManipulablePrototypeFactory_impl.hpp
|
|---|
| 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>
|
|---|
| 18 | #include <boost/preprocessor/punctuation/paren.hpp>
|
|---|
| 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 ManipulablePrototypeFactory<T,ParamT>\" << std::endl")
|
|---|
| 29 | #define type_seq ()
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | // check for required FactoryNAME
|
|---|
| 33 | #ifndef FactoryNAME
|
|---|
| 34 | BOOST_PP_ASSERT_MSG( 0 , \
|
|---|
| 35 | "std::cout << \"missing FactoryNAME for creating ManipulablePrototypeFactory<T,ParamT>\" << std::endl")
|
|---|
| 36 | #define FactoryNAME NONE
|
|---|
| 37 | #endif
|
|---|
| 38 |
|
|---|
| 39 | // check for required Abstract_Interface_Class
|
|---|
| 40 | #ifndef Abstract_Interface_Class
|
|---|
| 41 | BOOST_PP_ASSERT_MSG( 0 , \
|
|---|
| 42 | "std::cout << \"missing Abstract_Interface_Class for creating ManipulablePrototypeFactory<T,ParamT>\" << std::endl")
|
|---|
| 43 | #define Abstract_Interface_Class NONE
|
|---|
| 44 | #endif
|
|---|
| 45 |
|
|---|
| 46 | // check for required Abstract_Encapsulation_Class
|
|---|
| 47 | #ifndef Abstract_Encapsulation_Class
|
|---|
| 48 | BOOST_PP_ASSERT_MSG( 0 , \
|
|---|
| 49 | "std::cout << \"missing Abstract_Encapsulation_Class for creating ManipulablePrototypeFactory<T,ParamT>\" << std::endl")
|
|---|
| 50 | #define Abstract_Encapsulation_Class NONE
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | // check for required Abstract_Parameter_Class
|
|---|
| 54 | #ifndef Abstract_Parameter_Class
|
|---|
| 55 | BOOST_PP_ASSERT_MSG( 0 , \
|
|---|
| 56 | "std::cout << \"missing Abstract_Parameter_Class for creating ManipulablePrototypeFactory<T,ParamT>\" << std::endl")
|
|---|
| 57 | #define Abstract_Parameter_Class NONE
|
|---|
| 58 | #endif
|
|---|
| 59 |
|
|---|
| 60 | // check for type_name_space, is only optional
|
|---|
| 61 | #ifndef type_name_space
|
|---|
| 62 | #define type_name_space BOOST_PP_EMPTY()
|
|---|
| 63 | #endif
|
|---|
| 64 |
|
|---|
| 65 | #ifndef type_name_space_suffix
|
|---|
| 66 | #define type_name_space_suffix BOOST_PP_EMPTY()
|
|---|
| 67 | #endif
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | /** Functions that allows to print a given seq of elements in the way of
|
|---|
| 71 | * std::map from strings to enums.
|
|---|
| 72 | *
|
|---|
| 73 | * e.g. let "seq" be defined as
|
|---|
| 74 | * #define seq (one)(two)(three)(four)
|
|---|
| 75 | *
|
|---|
| 76 | * then we use
|
|---|
| 77 | * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(seqsize, n, seq, EnumMap, test::)
|
|---|
| 78 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
|
|---|
| 79 | * #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 80 | *
|
|---|
| 81 | * which expands by the preprocessor to:
|
|---|
| 82 | * EnumMap[one] = test::one;
|
|---|
| 83 | * EnumMap[two] = test::two;
|
|---|
| 84 | * EnumMap[three] = test::three;
|
|---|
| 85 | * EnumMap[four] = test::four;
|
|---|
| 86 | *
|
|---|
| 87 | */
|
|---|
| 88 | #define seqitems_as_enum_key_map(z,n,_seq_with_elements, _map, _keytype, _key_name_space, _type_name_space, _type_suffix) \
|
|---|
| 89 | _map [ _key_name_space \
|
|---|
| 90 | BOOST_PP_SEQ_ELEM(n, _seq_with_elements) \
|
|---|
| 91 | ] = _keytype< _type_name_space BOOST_PP_SEQ_ELEM(n, _seq_with_elements) _type_suffix > ();
|
|---|
| 92 |
|
|---|
| 93 | /** Functions that allows to print a given seq of elements in the way of
|
|---|
| 94 | * std::map from strings to enums.
|
|---|
| 95 | *
|
|---|
| 96 | * e.g. let "seq" be defined as
|
|---|
| 97 | * #define seq (one)(two)(three)(four)
|
|---|
| 98 | *
|
|---|
| 99 | * then we use
|
|---|
| 100 | * #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::)
|
|---|
| 101 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
|
|---|
| 102 | * #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 103 | *
|
|---|
| 104 | * which expands by the preprocessor to:
|
|---|
| 105 | * EnumMap[ typeid ( super:: one ) .name() ] = test::one;
|
|---|
| 106 | * EnumMap[ typeid ( super:: two ) .name() ] = test::two;
|
|---|
| 107 | * EnumMap[ typeid ( super:: three ) .name() ] = test::three;
|
|---|
| 108 | * EnumMap[ typeid ( super:: four ) .name() ] = test::four;
|
|---|
| 109 | *
|
|---|
| 110 | * or we use
|
|---|
| 111 | * #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::)
|
|---|
| 112 | * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )
|
|---|
| 113 | * #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 114 | *
|
|---|
| 115 | * which expands by the preprocessor to:
|
|---|
| 116 | * EnumMap[ "one" ] = test:: one;
|
|---|
| 117 | * EnumMap[ "two" ] = test:: two;
|
|---|
| 118 | * EnumMap[ "three" ] = test:: three;
|
|---|
| 119 | * EnumMap[ "four" ] = test:: four;
|
|---|
| 120 | */
|
|---|
| 121 | #define seqitems_as_enum_value_map(z,n,_seq_with_elements, _map, _type_specifier, _type_suffix, _enum_name_space) \
|
|---|
| 122 | _map [ _type_specifier \
|
|---|
| 123 | BOOST_PP_SEQ_ELEM(n, _seq_with_elements) \
|
|---|
| 124 | _type_suffix \
|
|---|
| 125 | ] = _enum_name_space BOOST_PP_SEQ_ELEM(n, _seq_with_elements);
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | template <>
|
|---|
| 129 | void ManipulablePrototypeFactory<Abstract_Interface_Class, Abstract_Parameter_Class>::FillEnumTable()
|
|---|
| 130 | {
|
|---|
| 131 | // insert all known (enum, string) keys
|
|---|
| 132 | #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>::)
|
|---|
| 133 | #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
|
|---|
| 134 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 135 |
|
|---|
| 136 | // insert all known (type, enum) keys
|
|---|
| 137 | #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>::)
|
|---|
| 138 | #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
|
|---|
| 139 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 140 |
|
|---|
| 141 | // create invert mapping (string, enum)
|
|---|
| 142 | for (ManipulablePrototypeFactory<Abstract_Interface_Class, Abstract_Parameter_Class>::EnumMap::const_iterator iter = enums.begin();
|
|---|
| 143 | iter != enums.end();
|
|---|
| 144 | ++iter) {
|
|---|
| 145 | names.insert(make_pair(iter->second, iter->first));
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | void FactoryNAME::FillPrototypeTable()
|
|---|
| 150 | {
|
|---|
| 151 | // fill PrototypeTable
|
|---|
| 152 | #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, type_seq, ManipulablePrototypeTable, new Abstract_Encapsulation_Class , FactoryTypeList<Abstract_Interface_Class>::, type_name_space, type_name_space_suffix )
|
|---|
| 153 | #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 )
|
|---|
| 154 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | void FactoryNAME::EmptyPrototypeTable()
|
|---|
| 158 | {
|
|---|
| 159 | for (InstanceTable::iterator iter = ManipulablePrototypeTable.begin();
|
|---|
| 160 | !ManipulablePrototypeTable.empty();
|
|---|
| 161 | iter = ManipulablePrototypeTable.begin()) {
|
|---|
| 162 | delete (iter->second);
|
|---|
| 163 | ManipulablePrototypeTable.erase(iter);
|
|---|
| 164 | }
|
|---|
| 165 | ManipulablePrototypeTable.clear();
|
|---|
| 166 | }
|
|---|