/* * Factory_impl_specific.hpp * * Created on: Jan 3, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include // check for required type_seq #ifdef type_seq #define type_seq_size BOOST_PP_SEQ_SIZE(type_seq) #else BOOST_PP_ASSERT_MSG( 0 , \ "std::cout << \"missing type_seq for creating Factory\" << std::endl") #define type_seq () #endif // check for required Abstract_Interface_Class #ifndef Abstract_Interface_Class BOOST_PP_ASSERT_MSG( 0 , \ "std::cout << \"missing Abstract_Interface_Class for creating Factory\" << std::endl") #define Abstract_Interface_Class NONE #endif // check for required Abstract_Encapsulation_Class #ifndef Abstract_Encapsulation_Class BOOST_PP_ASSERT_MSG( 0 , \ "std::cout << \"missing Abstract_Encapsulation_Class for creating Factory\" << std::endl") #define Abstract_Encapsulation_Class NONE #endif // check for type_name_space, is only optional #ifndef type_name_space #define type_name_space BOOST_PP_EMPTY() #endif #ifndef type_name_space_suffix #define type_name_space_suffix BOOST_PP_EMPTY() #endif /** Functions that allows to print a given seq of elements in the way of * std::map from strings to enums. * * e.g. let "seq" be defined as * #define seq (one)(two)(three)(four) * * then we use * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(seqsize, n, seq, EnumMap, name_space) * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 ) * #include BOOST_PP_LOCAL_ITERATE() * * which expands by the preprocessor to: * EnumMap["one"] = test:: one; * EnumMap["two"] = test:: two; * EnumMap["three"] = test:: three; * EnumMap["four"] = test:: four; */ #define seqitems_as_string_enum_map(z,n,seq_with_elements, map, name_space) \ map [BOOST_PP_STRINGIZE( \ BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ )] = name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ ; /** Functions that allows to print a given seq of elements in the way of * std::map from strings to enums. * * e.g. let "seq" be defined as * #define seq (one)(two)(three)(four) * * then we use * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(seqsize, n, seq, EnumMap, test::) * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 ) * #include BOOST_PP_LOCAL_ITERATE() * * which expands by the preprocessor to: * EnumMap[one] = test::one; * EnumMap[two] = test::two; * EnumMap[three] = test::three; * EnumMap[four] = test::four; */ #define seqitems_as_enum_key_map(z,n,seq_with_elements, map, keytype, name_space, suffix) \ map [ \ BOOST_PP_SEQ_ELEM(n, seq_with_elements) \ ] = keytype< name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) suffix > (); template <> void Factory::FillEnumTable() { // insert all known (enum, string) keys #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, type_seq, enums, FactoryTypeList::) #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 ) #include BOOST_PP_LOCAL_ITERATE() // create invert mapping (string, enum) for (Factory::EnumMap::const_iterator iter = enums.begin(); iter != enums.end(); ++iter) { names.insert(make_pair(iter->second, iter->first)); } } template <> void Factory::FillPrototypeTable() { // fill PrototypeTable #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, type_name_space, type_name_space_suffix > ) #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 ) #include BOOST_PP_LOCAL_ITERATE() }