- Timestamp:
- Nov 19, 2007, 5:57:02 AM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/BaseObject.cc
r149 r218 3 3 namespace orxonox 4 4 { 5 CreateFactory(BaseObject); 6 5 7 BaseObject::BaseObject() 6 8 { -
code/branches/objecthierarchie/src/CMakeLists.txt
r197 r218 2 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.cc Identifier.cc ClassHierarchy.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc)5 SET(INC_FILES ClassHierarchy.h Identifier.h IdentifierList.h ObjectList.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h)4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.cc Identifier.cc Factory.cc ClassHierarchy.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc) 5 SET(INC_FILES IdentifierIncludes.h ClassHierarchy.h Identifier.h Factory.h IdentifierList.h ObjectList.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h) 6 6 7 7 #Creates an executable -
code/branches/objecthierarchie/src/ClassHierarchy.h
r197 r218 11 11 // - ClassIdentifier 12 12 // - BaseIdentifier 13 // - Factory 13 14 14 15 // IN WORK: 15 // - Factory16 16 17 17 // TO DO: 18 18 // - iterate through lists 19 // - searchtree for classname-strings20 19 21 20 … … 37 36 private: 38 37 ClassHierarchy(); 38 ClassHierarchy(const ClassHierarchy& hierarchy); 39 39 ~ClassHierarchy(); 40 40 void startCreatingHierarchy() { this->hierarchyCreatingCounter_++; std::cout << "*** Increased Hierarchy-Creating-Counter to " << this->hierarchyCreatingCounter_ << "\n"; } … … 91 91 ClassIdentifier<ClassName>::getIdentifier() 92 92 93 #define Factory(ClassName) \ 94 ClassIdentifier<ClassName>::create() 93 #define CreateFactory(ClassName) \ 94 Identifier* global_##ClassName##_Identifier = ClassIdentifier<ClassName>::getIdentifier() 95 96 #define Factory(Name) \ 97 ClassFactory::fabricate(Name) 95 98 } 96 99 -
code/branches/objecthierarchie/src/Identifier.h
r197 r218 6 6 #include "ObjectList.h" 7 7 #include "OrxonoxClass.h" 8 #include "Factory.h" 8 9 9 10 namespace orxonox … … 21 22 void addObject(OrxonoxClass* object); 22 23 void removeObject(OrxonoxClass* object); 24 25 virtual OrxonoxClass* fabricate() {}; 23 26 24 27 bool isA(Identifier* identifier); … … 61 64 static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass, bool bIsAbstractClass); 62 65 static ClassIdentifier<T>* getIdentifier(); 66 OrxonoxClass* fabricate(); 67 T* fabricateClass(); 63 68 64 69 private: … … 83 88 { 84 89 this->pointer_ = NULL; 90 } 91 92 template <class T> 93 OrxonoxClass* ClassIdentifier<T>::fabricate() 94 { 95 return this->fabricateClass(); 96 } 97 98 template <class T> 99 T* ClassIdentifier<T>::fabricateClass() 100 { 101 return new T; 85 102 } 86 103 … … 97 114 pointer_->name_ = name; 98 115 pointer_->bIsAbstractClass_ = bIsAbstractClass; 116 117 ClassFactory::add(name, pointer_); 118 99 119 pointer_->initialize(parents); 100 120 } … … 124 144 } 125 145 126 127 146 // ##### BaseIdentifier ##### 128 147 template <class B> 129 class BaseIdentifier // : public Identifier148 class BaseIdentifier 130 149 { 131 150 public: 132 151 BaseIdentifier(); 133 152 134 //template <class T> 135 BaseIdentifier<B>& operator= (/*Class*/Identifier/*<T>*/* identifier) 153 BaseIdentifier<B>& operator= (Identifier* identifier) 136 154 { 137 155 if (!identifier->isA(ClassIdentifier<B>::getIdentifier())) … … 145 163 return *this; 146 164 } 165 166 Identifier* operator* () 167 { 168 return this->identifier_; 169 } 170 171 Identifier* operator-> () const 172 { 173 return this->identifier_; 174 } 175 176 B* fabricate() 177 { 178 OrxonoxClass* newObject = this->identifier_->fabricate(); 179 if (newObject) 180 { 181 return dynamic_cast<B*>(newObject); 182 } 183 else 184 { 185 if (this->identifier_) 186 { 187 std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<B>::getIdentifier()->getName() << "!\n"; 188 std::cout << "Error: Couldn't fabricate a new Object.\n"; 189 std::cout << "Aborting...\n"; 190 } 191 else 192 { 193 std::cout << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n"; 194 std::cout << "Aborting...\n"; 195 } 196 197 abort(); 198 } 199 } 200 147 201 inline Identifier* getIdentifier() 148 202 { return this->identifier_; } -
code/branches/objecthierarchie/src/IdentifierIncludes.h
r197 r218 1 1 #include "ClassHierarchy.h" 2 2 #include "Identifier.h" 3 #include "Factory.h" 3 4 #include "IdentifierList.h" 4 5 #include "ObjectList.h" -
code/branches/objecthierarchie/src/OrxonoxClass.h
r197 r218 11 11 public: 12 12 OrxonoxClass(); 13 ~OrxonoxClass();13 virtual ~OrxonoxClass(); 14 14 Identifier* getIdentifier() { return this->identifier_; } 15 15 void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; } -
code/branches/objecthierarchie/src/Test.h
r197 r218 2 2 #define _Test_H__ 3 3 4 #include "BaseObject.h" 4 5 #include "IdentifierIncludes.h" 5 6 … … 125 126 A3B2C2() { registerObject(A3B2C2); } 126 127 }; 128 129 CreateFactory(A1); 130 CreateFactory(A2); 131 CreateFactory(A3); 132 CreateFactory(A1B1); 133 CreateFactory(A1B2); 134 CreateFactory(A2B1); 135 CreateFactory(A2B2); 136 CreateFactory(A3B1); 137 CreateFactory(A3B2); 138 CreateFactory(A1B1C1); 139 CreateFactory(A1B1C2); 140 CreateFactory(A1B2C1); 141 CreateFactory(A2B1C1); 142 CreateFactory(A2B2C1); 143 CreateFactory(A3B1C1); 144 CreateFactory(A3B1C2); 145 CreateFactory(A3B2C1); 146 CreateFactory(A3B2C2); 127 147 } 128 148 -
code/branches/objecthierarchie/src/orxonox.cc
r197 r218 31 31 #include <OgreCEGUIRenderer.h> 32 32 33 #include "IdentifierIncludes.h" 33 34 #include "BaseObject.h" 34 35 #include "Test.h" … … 446 447 test7_02 = Class(A1B1); 447 448 448 std::cout << test7_01 .getIdentifier()->getName() << "\n";449 std::cout << test7_02 .getIdentifier()->getName() << "\n";449 std::cout << test7_01->getName() << "\n"; 450 std::cout << test7_02->getName() << "\n"; 450 451 */ 451 452 /* … … 461 462 test7_05 = Class(A2); 462 463 */ 463 464 /* 464 465 std::cout << "Test 8\n"; 465 466 … … 498 499 delete test8_02; 499 500 delete test8_03; 500 501 */ 502 503 std::cout << "Test 9\n"; 504 std::cout << "1\n"; 505 Identifier* test9_01 = Class(A3); 506 OrxonoxClass* test9_02 = test9_01->fabricate(); 507 std::cout << test9_02->getIdentifier()->getName() << "\n"; 508 509 std::cout << "\n2\n"; 510 OrxonoxClass* test9_03 = Class(A1B2)->fabricate(); 511 std::cout << test9_03->getIdentifier()->getName() << "\n"; 512 513 std::cout << "\n3\n"; 514 BaseIdentifier<A1> test9_04; 515 test9_04 = Class(A1B1C1); 516 A1* test9_05 = test9_04.fabricate(); 517 std::cout << test9_05->getIdentifier()->getName() << "\n"; 518 519 std::cout << "\n4\n"; 520 OrxonoxClass* test9_06 = Factory("A2B2"); 521 std::cout << test9_06->getIdentifier()->getName() << "\n"; 522 523 std::cout << "\n5\n"; 524 delete test9_02; 525 delete test9_03; 526 delete test9_05; 527 delete test9_06; 501 528 502 529 } -
code/branches/objecthierarchie/src/test1.cc
r197 r218 5 5 namespace orxonox 6 6 { 7 CreateFactory(Test1); 8 7 9 Test1::Test1() 8 10 { -
code/branches/objecthierarchie/src/test2.cc
r197 r218 5 5 namespace orxonox 6 6 { 7 CreateFactory(Test2); 8 7 9 Test2::Test2() 8 10 { -
code/branches/objecthierarchie/src/test3.cc
r197 r218 5 5 namespace orxonox 6 6 { 7 CreateFactory(Test3); 8 7 9 Test3::Test3() 8 10 {
Note: See TracChangeset
for help on using the changeset viewer.