- Timestamp:
- Jan 10, 2011, 8:06:49 PM (15 years ago)
- Children:
- 192c04
- Parents:
- 9f39db
- git-author:
- Frederik Heber <heber@…> (01/06/11 23:48:30)
- git-committer:
- Frederik Heber <heber@…> (01/10/11 20:06:49)
- Location:
- src
- Files:
-
- 14 added
- 8 edited
-
Makefile.am (modified) (1 diff)
-
Patterns/Clone.hpp (modified) (1 diff)
-
Patterns/ManipulableClone.hpp (added)
-
Patterns/ManipulablePrototypeFactory.hpp (added)
-
Patterns/ManipulablePrototypeFactory_impl.hpp (added)
-
Patterns/PrototypeFactory.hpp (modified) (4 diffs)
-
Patterns/unittests/Makefile.am (modified) (2 diffs)
-
Patterns/unittests/ManipulableCloneUnitTest.cpp (added)
-
Patterns/unittests/ManipulableCloneUnitTest.hpp (added)
-
Patterns/unittests/ManipulablePrototypeFactoryUnitTest.cpp (added)
-
Patterns/unittests/ManipulablePrototypeFactoryUnitTest.hpp (added)
-
Patterns/unittests/PrototypeFactoryUnitTest.cpp (modified) (2 diffs)
-
Patterns/unittests/PrototypeFactoryUnitTest.hpp (modified) (2 diffs)
-
Patterns/unittests/stubs/CommonParametersStub.hpp (added)
-
Patterns/unittests/stubs/ManipulableCloneStub.cpp (added)
-
Patterns/unittests/stubs/ManipulableCloneStub.hpp (added)
-
Patterns/unittests/stubs/ManipulablePrototypeFactoryStub.cpp (added)
-
Patterns/unittests/stubs/ManipulablePrototypeFactoryStub.def (added)
-
Patterns/unittests/stubs/ManipulablePrototypeFactoryStub.hpp (added)
-
Patterns/unittests/stubs/ManipulablePrototypeFactoryStub.undef (added)
-
Patterns/unittests/stubs/PrototypeFactoryStub.def (modified) (2 diffs)
-
Patterns/unittests/stubs/PrototypeFactoryStub.undef (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
r9f39db r8dd38e 41 41 Patterns/Factory_impl.hpp \ 42 42 Patterns/FactoryTypeList.hpp \ 43 Patterns/ManipulableClone.hpp \ 44 Patterns/ManipulablePrototypeFactory.hpp \ 45 Patterns/ManipulablePrototypeFactory_impl.hpp \ 43 46 Patterns/ObservedContainer.hpp \ 44 47 Patterns/ObservedIterator.hpp \ -
src/Patterns/Clone.hpp
r9f39db r8dd38e 39 39 * @endcode 40 40 * 41 * \link <ManipulableClone> {See also at ManipulableClones if changes to the 42 * prototype instance can only be accomplished through its constructor. } 43 * 41 44 */ 42 45 template <class interface> -
src/Patterns/PrototypeFactory.hpp
r9f39db r8dd38e 374 374 * 375 375 * @param instance_name name of product 376 * @return reference to prototype stored in this factory376 * @return const reference to prototype stored in this factory, i.e. read-only 377 377 */ 378 T* getPrototypeManipulator(const std::string instance_name)378 const T& getPrototype(const std::string instance_name) 379 379 { 380 380 ASSERT(enums.count(instance_name) != 0, 381 381 "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type name "+instance_name+" is not registered."); 382 382 T* prototype = dynamic_cast<T *>(PrototypeTable[ enums[instance_name] ]); 383 return prototype;383 return *prototype; 384 384 } 385 385 … … 391 391 * 392 392 * @param enumeration index of product 393 * @return reference to prototype stored in this factory393 * @return const reference to prototype stored in this factory, i.e. read-only 394 394 */ 395 T* getPrototypeManipulator(TypeList instance_type)395 const T& getPrototype(TypeList instance_type) 396 396 { 397 397 ASSERT(names.count(instance_type) != 0, 398 398 "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - enum type "+toString(instance_type)+" is not registered."); 399 399 T* prototype = dynamic_cast<T *>(PrototypeTable[instance_type]); 400 return prototype;400 return *prototype; 401 401 } 402 402 … … 408 408 * 409 409 * @param instance_type_info object of the desired type 410 * @return reference to prototype stored in this factory410 * @return const reference to prototype stored in this factory, i.e. read-only 411 411 */ 412 T* getPrototypeManipulator(const std::type_info &instance_type_info)412 const T& getPrototype(const std::type_info &instance_type_info) 413 413 { 414 414 ASSERT(types.count(instance_type_info.name()) != 0, 415 415 "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type info name "+instance_type_info.name()+" is not registered."); 416 416 T* prototype = dynamic_cast<T *>(PrototypeTable[ types[instance_type_info.name()] ]); 417 return prototype;417 return *prototype; 418 418 } 419 419 … … 424 424 * specific friends are allowed to access it. 425 425 * 426 * @return reference to prototype stored in this factory426 * @return const reference to prototype stored in this factory, i.e. read-only 427 427 */ 428 T* getPrototypeManipulator()428 const T& getPrototype() 429 429 { 430 430 T* prototype = dynamic_cast<T *>(PrototypeTable[ currenttype ]); 431 return prototype; 432 } 433 434 /** Allows returning (a possibly different) prototype which is stored in 435 * PrototypeTable. 436 * 437 * @warning a prototype has to be delivered by getPrototypeManipulator() 438 * before it can be returned again. 439 * 440 * @param _newprototype reference to new prototype 441 * @param instance_name name of particular type 442 */ 443 void installPrototype(Clone<T> *_newprototype, const std::string instance_name) 444 { 445 ASSERT(enums.count(instance_name) != 0, 446 "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type name "+instance_name+" is not registered."); 447 ASSERT(typeid(PrototypeTable[ enums[instance_name] ]) == typeid(_newprototype), 448 "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+instance_name+"."); 449 // TODO: use boost::shared_ptr to store prototypes instead! 450 delete PrototypeTable[ enums[instance_name] ]; 451 PrototypeTable[ enums[instance_name] ] = _newprototype; 452 } 453 454 /** Allows returning (a possibly different) prototype which is stored in 455 * PrototypeTable. 456 * 457 * @warning a prototype has to be delivered by getPrototypeManipulator() 458 * before it can be returned again. 459 * 460 * @param _newprototype reference to new prototype 461 * @param instance_type enumeration index of particular type 462 */ 463 void installPrototype(Clone<T> *_newprototype, TypeList instance_type) 464 { 465 ASSERT(names.count(instance_type) != 0, 466 "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - enum type "+toString(instance_type)+" is not registered."); 467 ASSERT( typeid(PrototypeTable[ instance_type ]) == typeid(_newprototype), 468 "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+names[instance_type]+"."); 469 // TODO: use boost::shared_ptr to store prototypes instead! 470 delete PrototypeTable[ instance_type ]; 471 PrototypeTable[ instance_type ] = _newprototype; 472 } 473 474 /** Allows returning (a possibly different) prototype which is stored in 475 * PrototypeTable. 476 * 477 * @warning a prototype has to be delivered by getPrototypeManipulator() 478 * before it can be returned again. 479 * 480 * @param _newprototype reference to new prototype 481 * @param instance_type_info type_info of particular type 482 */ 483 void installPrototype(Clone<T> *_newprototype, const std::type_info &instance_type_info) 484 { 485 ASSERT(types.count(instance_type_info.name()) != 0, 486 "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type info name "+instance_type_info.name()+" is not registered."); 487 ASSERT( typeid(PrototypeTable[ types[instance_type_info.name()] ]) == typeid(_newprototype), 488 "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+instance_type_info.name()+"."); 489 // TODO: use boost::shared_ptr to store prototypes instead! 490 PrototypeTable[ types[instance_type_info.name()] ] = _newprototype; 491 } 492 493 /** Allows returning (a possibly different) prototype which is stored in 494 * PrototypeTable. 495 * 496 * @warning a prototype has to be delivered by getPrototypeManipulator() 497 * before it can be returned again. 498 * 499 * @param _newprototype reference to new prototype 500 * @param instance_type_info type_info of particular type 501 */ 502 void installPrototype(Clone<T> *_newprototype) 503 { 504 ASSERT( typeid(PrototypeTable[ currenttype ]) == typeid(_newprototype), 505 "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+names[currenttype]+"."); 506 // TODO: use boost::shared_ptr to store prototypes instead! 507 PrototypeTable[ currenttype ] = _newprototype; 431 return *prototype; 508 432 } 509 433 -
src/Patterns/unittests/Makefile.am
r9f39db r8dd38e 13 13 CreatorUnitTest \ 14 14 FactoryUnitTest \ 15 ManipulableCloneUnitTest \ 16 ManipulablePrototypeFactoryUnitTest \ 15 17 ObserverUnitTest \ 16 18 PrototypeFactoryUnitTest \ … … 67 69 FactoryUnitTest_LDADD = $(TESTLIBS) 68 70 71 ManipulableCloneUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 72 ManipulableCloneUnitTest.cpp \ 73 ManipulableCloneUnitTest.hpp \ 74 ../ManipulableClone.hpp \ 75 stubs/CommonStub.cpp \ 76 stubs/CommonStub.hpp \ 77 stubs/ManipulableCloneStub.cpp \ 78 stubs/ManipulableCloneStub.hpp 79 ManipulableCloneUnitTest_LDADD = $(TESTLIBS) 80 81 ManipulablePrototypeFactoryUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 82 ManipulablePrototypeFactoryUnitTest.cpp \ 83 ManipulablePrototypeFactoryUnitTest.hpp \ 84 stubs/ManipulableCloneStub.cpp \ 85 stubs/ManipulableCloneStub.hpp \ 86 stubs/CommonStub.cpp \ 87 stubs/CommonStub.hpp \ 88 stubs/ManipulablePrototypeFactoryStub.hpp \ 89 stubs/ManipulablePrototypeFactoryStub.cpp \ 90 ../ManipulablePrototypeFactory.hpp \ 91 ../FactoryTypeList.hpp \ 92 ../ManipulablePrototypeFactory_impl.hpp 93 ManipulablePrototypeFactoryUnitTest_LDADD = $(TESTLIBS) 94 69 95 ObserverUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 70 96 ObserverUnitTest.cpp \ -
src/Patterns/unittests/PrototypeFactoryUnitTest.cpp
r9f39db r8dd38e 161 161 } 162 162 163 void PrototypeFactoryTest:: PrototypeManipulatortest()163 void PrototypeFactoryTest::getPrototypetest() 164 164 { 165 165 // this method is protected and only friends may access it. 166 IPrototype *rndA_1 = PrototypeFactoryStub::getInstance().getPrototypeManipulator(std::string("Aclass")); 167 168 // do something with the prototype. 169 rndA_1->setcount(256); 166 const IPrototype& rndA_1c = PrototypeFactoryStub::getInstance().getPrototype(std::string("Aclass")); 170 167 171 168 // clone the type and check whether new default values holds 172 169 rndA_2 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); 173 CPPUNIT_ASSERT_EQUAL( 256, rndA_2->getcount() ); 170 CPPUNIT_ASSERT_EQUAL( rndA_1c.getcount(), rndA_2->getcount() ); 171 rndA_2->count(); 172 CPPUNIT_ASSERT( rndA_1c.getcount() != rndA_2->getcount() ); 174 173 175 // rndA has been cloned before we have manipulated the prototype 176 CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() ); 177 178 // do something with the prototype. 179 rndA_1->setcount(0); 174 // the following is not possible 175 //rndA_1c.count(); 180 176 181 177 rndA_3 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); … … 183 179 CPPUNIT_ASSERT( rndA->getcount() == rndA_3->getcount() ); 184 180 } 185 186 void PrototypeFactoryTest::installPrototypetest()187 {188 Prototype< teststubs::Aclass> *newprototype = new Prototype< teststubs::Aclass> ();189 newprototype->setcount(1);190 PrototypeFactoryStub::getInstance().installPrototype(newprototype, std::string("Aclass"));191 newprototype = NULL;192 193 IPrototype *rndA_1 = PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));194 CPPUNIT_ASSERT( 1 == rndA_1->getcount() );195 196 rndA_1->count();197 CPPUNIT_ASSERT( 2 == rndA_1->getcount() );198 199 IPrototype *rndA_2 = PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));200 CPPUNIT_ASSERT( 1 == rndA_2->getcount() );201 CPPUNIT_ASSERT( rndA_1->getcount() != rndA_2->getcount() );202 } -
src/Patterns/unittests/PrototypeFactoryUnitTest.hpp
r9f39db r8dd38e 26 26 CPPUNIT_TEST ( getProductTypeTest ); 27 27 CPPUNIT_TEST ( Individualitytest ); 28 CPPUNIT_TEST ( PrototypeManipulatortest ); 29 CPPUNIT_TEST ( installPrototypetest ); 28 CPPUNIT_TEST ( getPrototypetest ); 30 29 CPPUNIT_TEST_SUITE_END(); 31 30 … … 39 38 void getProductTypeTest(); 40 39 void Individualitytest(); 41 void PrototypeManipulatortest(); 42 void installPrototypetest(); 40 void getPrototypetest(); 43 41 44 42 private: -
src/Patterns/unittests/stubs/PrototypeFactoryStub.def
r9f39db r8dd38e 1 #ifndef ABSTRACTFACTORYSTUB_DEF_2 #define ABSTRACTFACTORYSTUB_DEF_1 #ifndef PROTOTYPEFACTORYSTUB_DEF_ 2 #define PROTOTYPEFACTORYSTUB_DEF_ 3 3 4 4 #define type_seq (Aclass)(Bclass) … … 9 9 #undef type_suffix 10 10 11 #endif // ABSTRACTFACTORYSTUB_DEF_11 #endif //PROTOTYPEFACTORYSTUB_DEF_ -
src/Patterns/unittests/stubs/PrototypeFactoryStub.undef
r9f39db r8dd38e 1 #ifdef ABSTRACTFACTORYSTUB_DEF_1 #ifdef PROTOTYPEFACTORYSTUB_DEF_ 2 2 3 3 #undef type_seq … … 8 8 #undef type_name_space 9 9 10 #undef ABSTRACTFACTORYSTUB_DEF_10 #undef PROTOTYPEFACTORYSTUB_DEF_ 11 11 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
