Changeset 724564
- Timestamp:
- Jan 4, 2011, 5:15:14 PM (15 years ago)
- Children:
- 1afcbe
- Parents:
- 746ff1
- git-author:
- Frederik Heber <heber@…> (01/04/11 15:57:33)
- git-committer:
- Frederik Heber <heber@…> (01/04/11 17:15:14)
- Files:
-
- 1 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
r746ff1 r724564 3 3 4 4 AC_PREREQ([2.65]) 5 AC_INIT([CodePatterns], [1.0. 2], [heber@ins.uni-bonn.de], [codepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/])5 AC_INIT([CodePatterns], [1.0.3], [heber@ins.uni-bonn.de], [codepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/]) 6 6 AC_CONFIG_AUX_DIR(config) 7 7 AC_CONFIG_SRCDIR([src/Patterns/Singleton_impl.hpp]) … … 25 25 # refer to the libtool manual, section "Updating library version information": 26 26 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html 27 AC_SUBST([CODEPATTERNS_SO_VERSION], [2: 0:0])28 AC_SUBST([CODEPATTERNS_API_VERSION], [1.0. 2])27 AC_SUBST([CODEPATTERNS_SO_VERSION], [2:1:0]) 28 AC_SUBST([CODEPATTERNS_API_VERSION], [1.0.3]) 29 29 30 30 # Checks for libraries. -
src/Patterns/Factory.hpp
r746ff1 r724564 15 15 16 16 #include <map> 17 #include <typeinfo> 18 19 #include "Assert.hpp" 17 20 18 21 #include "Creator.hpp" … … 285 288 } 286 289 290 /** Getter for desired type of product. 291 * 292 * @param type_info object of the desired type 293 * @return reference to copy of current type product or NULL if type mismatch 294 */ 295 T* getProduct(const std::type_info &instance_type_info) const 296 { 297 ASSERT(types.count(instance_type_info.name()) != 0, 298 "Factory<"+toString(typeid(T).name())+">::getProduct() - type info name "+instance_type_info.name()+" is not registered."); 299 return PrototypeTable[ types[instance_type_info.name()] ]->create(); 300 } 287 301 288 302 /** Getter for current type of product. … … 330 344 void FillEnumTable(); 331 345 346 typedef std::map< 347 std::string, 348 TypeList 349 > TypeMap; 332 350 typedef std::map< 333 351 std::string, … … 344 362 345 363 static TypeList currenttype; 364 static TypeMap types; 346 365 static EnumMap enums; 347 366 static InstanceTable PrototypeTable; … … 350 369 351 370 template <class T> typename Factory<T>::TypeList Factory<T>::currenttype = (typename Factory<T>::TypeList)0; 371 template <class T> typename Factory<T>::TypeMap Factory<T>::types; 352 372 template <class T> typename Factory<T>::EnumMap Factory<T>::enums; 353 373 template <class T> typename Factory<T>::NameMap Factory<T>::names; -
src/Patterns/Factory_impl.hpp
r746ff1 r724564 16 16 #include <boost/preprocessor/punctuation/comma.hpp> 17 17 #include <boost/preprocessor/punctuation/comma_if.hpp> 18 #include <boost/preprocessor/punctuation/paren.hpp> 18 19 #include <boost/preprocessor/seq/elem.hpp> 19 20 #include <boost/preprocessor/seq/size.hpp> … … 52 53 #endif 53 54 54 /** Functions that allows to print a given seq of elements in the way of55 * std::map from strings to enums.56 *57 * e.g. let "seq" be defined as58 * #define seq (one)(two)(three)(four)59 *60 * then we use61 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(seqsize, n, seq, EnumMap, name_space)62 * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seq)-1 )63 * #include BOOST_PP_LOCAL_ITERATE()64 *65 * which expands by the preprocessor to:66 * EnumMap["one"] = test:: one;67 * EnumMap["two"] = test:: two;68 * EnumMap["three"] = test:: three;69 * EnumMap["four"] = test:: four;70 71 */72 #define seqitems_as_string_enum_map(z,n,seq_with_elements, map, name_space) \73 map [BOOST_PP_STRINGIZE( \74 BOOST_PP_SEQ_ELEM(n, seq_with_elements) \75 )] = name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) \76 ;77 55 78 56 /** Functions that allows to print a given seq of elements in the way of … … 92 70 * EnumMap[three] = test::three; 93 71 * EnumMap[four] = test::four; 94 72 * 95 73 */ 96 74 #define seqitems_as_enum_key_map(z,n,seq_with_elements, map, keytype, name_space, suffix) \ … … 99 77 ] = keytype< name_space BOOST_PP_SEQ_ELEM(n, seq_with_elements) suffix > (); 100 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 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::) 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: 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; 106 */ 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); 112 101 113 102 114 template <> … … 104 116 { 105 117 // insert all known (enum, string) keys 106 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, type_seq, enums, FactoryTypeList<Abstract_Interface_Class>::) 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>::) 107 124 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(type_seq)-1 ) 108 125 #include BOOST_PP_LOCAL_ITERATE() -
src/Patterns/unittests/CreatorUnitTest.cpp
r746ff1 r724564 25 25 26 26 #include "Creator.hpp" 27 #include "stubs/CommonStub.hpp" 27 28 #include "stubs/CreatorStub.hpp" 28 29 -
src/Patterns/unittests/FactoryUnitTest.cpp
r746ff1 r724564 22 22 #include "FactoryUnitTest.hpp" 23 23 24 #include "stubs/CommonStub.hpp" 24 25 #include "stubs/FactoryStub.hpp" 25 26 … … 68 69 void FactoryTest::setUp() 69 70 { 70 FactoryStub::getInstance(); 71 rndA = 72 FactoryStub::getInstance(). 73 PrototypeTable[FactoryStub::Aclass]->create(); 74 rndB = 75 FactoryStub::getInstance(). 76 PrototypeTable[FactoryStub::Bclass]->create(); 71 77 } 72 78 73 79 void FactoryTest::tearDown() 74 80 { 81 delete rndA; 82 delete rndB; 75 83 FactoryStub::purgeInstance(); 76 84 } … … 93 101 } 94 102 95 // check one of the distributions in the table 96 ICreatorStub * rnd = 97 FactoryStub::getInstance(). 98 PrototypeTable[FactoryStub::Aclass]->create(); 103 // check distributions in the table 99 104 CPPUNIT_ASSERT_EQUAL( 100 105 std::string(typeid(teststubs::Aclass).name()), 101 rnd ->name()106 rndA->name() 102 107 ); 103 delete rnd; 108 CPPUNIT_ASSERT_EQUAL( 109 std::string(typeid(teststubs::Bclass).name()), 110 rndB->name() 111 ); 104 112 } 113 114 115 void FactoryTest::getProductEnumTest() 116 { 117 ICreatorStub * rndA_1 = 118 FactoryStub::getInstance().getProduct(FactoryStub::Aclass); 119 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); 120 delete rndA_1; 121 } 122 123 void FactoryTest::getProductNameTest() 124 { 125 ICreatorStub * rndA_1 = 126 FactoryStub::getInstance().getProduct(std::string("Aclass")); 127 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); 128 delete rndA_1; 129 } 130 131 void FactoryTest::getProductTypeTest() 132 { 133 ICreatorStub * rndA_1 = 134 FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) ); 135 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); 136 delete rndA_1; 137 } -
src/Patterns/unittests/FactoryUnitTest.hpp
r746ff1 r724564 14 14 #endif 15 15 16 class ICreatorStub; 16 17 17 18 #include <cppunit/extensions/HelperMacros.h> … … 21 22 CPPUNIT_TEST_SUITE( FactoryTest ); 22 23 CPPUNIT_TEST ( DistributionTest ); 24 CPPUNIT_TEST ( getProductEnumTest ); 25 CPPUNIT_TEST ( getProductNameTest ); 26 CPPUNIT_TEST ( getProductTypeTest ); 23 27 CPPUNIT_TEST_SUITE_END(); 24 28 … … 28 32 29 33 void DistributionTest(); 34 void getProductEnumTest(); 35 void getProductNameTest(); 36 void getProductTypeTest(); 30 37 31 38 private: 39 ICreatorStub * rndA; 40 ICreatorStub * rndB; 32 41 }; 33 42 -
src/Patterns/unittests/Makefile.am
r746ff1 r724564 37 37 CreatorUnitTest.hpp \ 38 38 ../Creator.hpp \ 39 stubs/CreatorStub.hpp \ 40 stubs/CreatorStub.cpp 39 stubs/CommonStub.cpp \ 40 stubs/CommonStub.hpp \ 41 stubs/CreatorStub.hpp 41 42 CreatorUnitTest_LDADD = $(TESTLIBS) 42 43 … … 44 45 FactoryUnitTest.cpp \ 45 46 FactoryUnitTest.hpp \ 47 stubs/CommonStub.cpp \ 48 stubs/CommonStub.hpp \ 46 49 stubs/CreatorStub.hpp \ 47 stubs/CreatorStub.cpp \48 50 stubs/FactoryStub.hpp \ 49 51 stubs/FactoryStub.cpp \ -
src/Patterns/unittests/stubs/CommonStub.cpp
r746ff1 r724564 7 7 8 8 /* 9 * C reatorStub.cpp9 * CommonStub.cpp 10 10 * 11 11 * Created on: Jan 4, 2011 … … 13 13 */ 14 14 15 // include config.h 16 #ifdef HAVE_CONFIG_H 17 #include <config.h> 18 #endif 19 20 #include "CommonStub.hpp" 21 15 22 namespace teststubs { 16 class Aclass {}; 17 class Bclass {}; 23 Aclass::Aclass() : 24 counter(0) 25 {}; 26 27 Aclass::~Aclass() {}; 28 29 Bclass::Bclass() : 30 counter(256) 31 {}; 32 33 Bclass::~Bclass() {}; 18 34 }; -
src/Patterns/unittests/stubs/CreatorStub.hpp
r746ff1 r724564 8 8 #ifndef CREATORSTUB_HPP_ 9 9 #define CREATORSTUB_HPP_ 10 11 // include config.h 12 #ifdef HAVE_CONFIG_H 13 #include <config.h> 14 #endif 10 15 11 16 #include <typeinfo> … … 19 24 virtual int getcount() = 0; 20 25 virtual std::string name() = 0; 21 };22 23 namespace teststubs {24 class Aclass25 {26 public:27 Aclass() :28 counter(0)29 {};30 ~Aclass() {};31 32 int counter;33 };34 35 class Bclass36 {37 public:38 Bclass() :39 counter(256)40 {};41 ~Bclass() {};42 43 int counter;44 };45 26 }; 46 27 -
src/Patterns/unittests/stubs/FactoryStub.cpp
r746ff1 r724564 13 13 */ 14 14 15 // include config.h 16 #ifdef HAVE_CONFIG_H 17 #include <config.h> 18 #endif 19 15 20 #include "Singleton_impl.hpp" 16 21 22 #include "CommonStub.hpp" 17 23 #include "FactoryStub.hpp" 18 24 -
src/Patterns/unittests/stubs/FactoryStub.hpp
r746ff1 r724564 9 9 #define FACTORYSTUB_HPP_ 10 10 11 // include config.h 12 #ifdef HAVE_CONFIG_H 13 #include <config.h> 14 #endif 15 11 16 #include "CreatorStub.hpp" 12 17 13 // has to be appear BEFORE Factory.hpp is included!18 // triple has to be appear BEFORE Factory.hpp is included! 14 19 #include "FactoryStub.def" 15 20 #include "FactoryTypeList.hpp" 21 #include "FactoryStub.undef" 22 16 23 #include "Factory.hpp" 17 24 … … 27 34 virtual ~FactoryStub(); 28 35 }; 29 #include "FactoryStub.undef"30 36 31 37 #endif /* FACTORYSTUB_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.