Changeset 224
- Timestamp:
- Nov 20, 2007, 8:38:53 PM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/CMakeLists.txt
r221 r224 2 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.ccIdentifier.cc Factory.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc)4 SET(SRC_FILES orxonox.cc IdentifierList.cc Identifier.cc Factory.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc) 5 5 SET(INC_FILES IdentifierIncludes.h Identifier.h Factory.h IdentifierList.h ObjectList.h Iterator.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h) 6 6 -
code/branches/objecthierarchie/src/Identifier.cc
r221 r224 11 11 { 12 12 this->bCreatedOneObject_ = false; 13 // this->directParents_ = new IdentifierList();14 // this->allParents_ = new IdentifierList();15 // this->directChildren_ = new IdentifierList();16 // this->allChildren_ = new IdentifierList();17 // this->objects_ = new ObjectList();18 13 } 19 14 20 15 Identifier::~Identifier() 21 16 { 22 // delete this->directParents_;23 // delete this->allParents_;24 // delete this->directChildren_;25 // delete this->allChildren_;26 // delete this->objects_;27 17 delete &this->name_; 28 18 } … … 76 66 } 77 67 78 void Identifier::addObject(OrxonoxClass* object)79 {80 std::cout << "*** Added object to " << this->name_ << "-list.\n";81 this->objects_.add(object);82 }83 84 void Identifier::removeObject(OrxonoxClass* object)85 {86 bool bIterateForwards = !Identifier::isCreatingHierarchy();87 88 if (bIterateForwards)89 std::cout << "*** Removed object from " << this->name_ << "-list, iterating forwards.\n";90 else91 std::cout << "*** Removed object from " << this->name_ << "-list, iterating backwards.\n";92 93 this->objects_.remove(object, bIterateForwards);94 95 IdentifierListElement* temp = this->directParents_.first_;96 while (temp)97 {98 temp->identifier_->removeObject(object);99 temp = temp->next_;100 }101 }102 103 68 bool Identifier::isA(Identifier* identifier) 104 69 { -
code/branches/objecthierarchie/src/Identifier.h
r221 r224 26 26 class BaseObject; 27 27 28 // ##### Identifier ##### 28 // ############################### 29 // ### Identifier ### 30 // ############################### 29 31 class Identifier 30 32 { … … 35 37 friend class BaseIdentifier; 36 38 37 template <class T>38 friend class Iterator;39 40 39 public: 41 void addObject(OrxonoxClass* object); 42 void removeObject(OrxonoxClass* object); 40 virtual void removeObject(OrxonoxClass* object) {}; 43 41 44 42 virtual BaseObject* fabricate() {}; … … 73 71 IdentifierList allChildren_; 74 72 75 ObjectList objects_;76 73 std::string name_; 77 74 … … 83 80 84 81 85 // ##### ClassIdentifier ##### 82 // ############################### 83 // ### ClassIdentifier ### 84 // ############################### 86 85 template <class T> 87 86 class ClassIdentifier : public Identifier 88 87 { 88 template <class U> 89 friend class Iterator; 90 89 91 public: 90 92 static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass, bool bIsAbstractClass); … … 92 94 BaseObject* fabricate(); 93 95 T* fabricateClass(); 96 static void addObject(T* object); 97 void removeObject(OrxonoxClass* object); 94 98 95 99 private: … … 99 103 100 104 static ClassIdentifier<T>* pointer_s; 101 105 ObjectList<T> objects_s; 102 106 }; 103 107 … … 182 186 } 183 187 184 // ##### BaseIdentifier ##### 188 template <class T> 189 void ClassIdentifier<T>::addObject(T* object) 190 { 191 std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n"; 192 ClassIdentifier<T>::getIdentifier()->objects_s.add(object); 193 } 194 195 template <class T> 196 void ClassIdentifier<T>::removeObject(OrxonoxClass* object) 197 { 198 bool bIterateForwards = !Identifier::isCreatingHierarchy(); 199 200 if (bIterateForwards) 201 std::cout << "*** Removed object from " << this->name_ << "-list, iterating forwards.\n"; 202 else 203 std::cout << "*** Removed object from " << this->name_ << "-list, iterating backwards.\n"; 204 205 this->objects_s.remove(object, bIterateForwards); 206 207 IdentifierListElement* temp = this->directParents_.first_; 208 while (temp) 209 { 210 temp->identifier_->removeObject(object); 211 temp = temp->next_; 212 } 213 } 214 215 216 // ############################### 217 // ### BaseIdentifier ### 218 // ############################### 185 219 template <class B> 186 220 class BaseIdentifier -
code/branches/objecthierarchie/src/IdentifierIncludes.h
r221 r224 13 13 if (Identifier::isCreatingHierarchy() && this->getParents()) \ 14 14 this->getParents()->add(this->getIdentifier()); \ 15 this->getIdentifier()->addObject(this)15 ClassIdentifier<ClassName>::addObject(this) 16 16 17 17 #define registerRootObject(ClassName) \ … … 27 27 if (Identifier::isCreatingHierarchy() && this->getParents()) \ 28 28 this->getParents()->add(this->getIdentifier()); \ 29 this->getIdentifier()->addObject(this)29 ClassIdentifier<ClassName>::addObject(this) 30 30 31 31 #define registerObject(ClassName) \ -
code/branches/objecthierarchie/src/Iterator.h
r221 r224 10 10 Iterator() 11 11 { 12 this->elementForwards_ = ClassIdentifier<T>::getIdentifier()->objects_ .first_;13 this->elementBackwards_ = ClassIdentifier<T>::getIdentifier()->objects_ .last_;12 this->elementForwards_ = ClassIdentifier<T>::getIdentifier()->objects_s.first_; 13 this->elementBackwards_ = ClassIdentifier<T>::getIdentifier()->objects_s.last_; 14 14 this->iteratingForwards_ = true; 15 15 } … … 51 51 { 52 52 if (this->iteratingForwards_) 53 return dynamic_cast<T*>(this->elementForwards_->object_);53 return /*dynamic_cast<T*>*/(this->elementForwards_->object_); 54 54 else 55 return dynamic_cast<T*>(this->elementBackwards_->object_);55 return /*dynamic_cast<T*>*/(this->elementBackwards_->object_); 56 56 } 57 57 … … 59 59 { 60 60 if (this->iteratingForwards_) 61 return dynamic_cast<T*>(this->elementForwards_->object_);61 return /*dynamic_cast<T*>*/(this->elementForwards_->object_); 62 62 else 63 return dynamic_cast<T*>(this->elementBackwards_->object_);63 return /*dynamic_cast<T*>*/(this->elementBackwards_->object_); 64 64 65 65 } … … 86 86 87 87 private: 88 ObjectListElement * elementForwards_;89 ObjectListElement * elementBackwards_;88 ObjectListElement<T>* elementForwards_; 89 ObjectListElement<T>* elementBackwards_; 90 90 bool iteratingForwards_; 91 91 }; -
code/branches/objecthierarchie/src/ObjectList.h
r221 r224 6 6 class OrxonoxClass; 7 7 8 // ############################### 9 // ### ObjectListElement ### 10 // ############################### 11 template <class T> 8 12 class ObjectListElement 9 13 { 10 14 public: 11 ObjectListElement( OrxonoxClass* object);15 ObjectListElement(T* object); 12 16 ~ObjectListElement(); 13 17 14 OrxonoxClass* object_;18 T* object_; 15 19 ObjectListElement* next_; 16 20 ObjectListElement* prev_; 17 21 }; 18 22 23 template <class T> 24 ObjectListElement<T>::ObjectListElement(T* object) 25 { 26 this->object_ = object; 27 this->next_ = 0; 28 this->prev_ = 0; 29 } 30 31 template <class T> 32 ObjectListElement<T>::~ObjectListElement() 33 { 34 } 35 36 37 // ############################### 38 // ### ObjectList ### 39 // ############################### 40 template <class T> 19 41 class ObjectList 20 42 { … … 22 44 ObjectList(); 23 45 ~ObjectList(); 24 void add( OrxonoxClass* object);46 void add(T* object); 25 47 void remove(OrxonoxClass* object, bool bIterateForwards = true); 26 48 27 ObjectListElement * first_;28 ObjectListElement * last_;49 ObjectListElement<T>* first_; 50 ObjectListElement<T>* last_; 29 51 }; 52 53 template <class T> 54 ObjectList<T>::ObjectList() 55 { 56 this->first_ = 0; 57 this->last_ = 0; 58 } 59 60 template <class T> 61 ObjectList<T>::~ObjectList() 62 { 63 ObjectListElement<T>* temp; 64 while (this->first_) 65 { 66 temp = this->first_->next_; 67 delete this->first_; 68 this->first_ = temp; 69 } 70 } 71 72 template <class T> 73 void ObjectList<T>::add(T* object) 74 { 75 if (!this->last_) 76 { 77 this->last_ = new ObjectListElement<T>(object); 78 this->first_ = this->last_; 79 } 80 else 81 { 82 ObjectListElement<T>* temp = this->last_; 83 this->last_ = new ObjectListElement<T>(object); 84 this->last_->prev_ = temp; 85 temp->next_ = this->last_; 86 } 87 } 88 89 template <class T> 90 void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards) 91 { 92 if (!object || !this->first_ || !this->last_) 93 return; 94 95 if (this->first_ == this->last_) 96 { 97 if (this->first_->object_ == object) 98 { 99 delete this->first_; 100 this->first_ = 0; 101 this->last_ = 0; 102 } 103 104 return; 105 } 106 107 if (bIterateForwards) 108 { 109 if (this->first_->object_ == object) 110 { 111 ObjectListElement<T>* temp = this->first_->next_; 112 delete this->first_; 113 this->first_ = temp; 114 this->first_->prev_ = 0; 115 116 return; 117 } 118 119 ObjectListElement<T>* temp = this->first_; 120 while (temp->next_) 121 { 122 if (temp->next_->object_ == object) 123 { 124 ObjectListElement<T>* temp2 = temp->next_->next_; 125 delete temp->next_; 126 temp->next_ = temp2; 127 if (temp2) 128 temp2->prev_ = temp; 129 else 130 this->last_ = temp; 131 132 return; 133 } 134 135 temp = temp->next_; 136 } 137 } 138 else 139 { 140 if (this->last_->object_ == object) 141 { 142 ObjectListElement<T>* temp = this->last_->prev_; 143 delete this->last_; 144 this->last_ = temp; 145 this->last_->next_ = 0; 146 147 return; 148 } 149 150 ObjectListElement<T>* temp = this->last_; 151 while (temp->prev_) 152 { 153 if (temp->prev_->object_ == object) 154 { 155 ObjectListElement<T>* temp2 = temp->prev_->prev_; 156 delete temp->prev_; 157 temp->prev_ = temp2; 158 if (temp2) 159 temp2->next_ = temp; 160 else 161 this->first_ = temp; 162 163 return; 164 } 165 166 temp = temp->prev_; 167 } 168 } 169 } 30 170 } 31 171 -
code/branches/objecthierarchie/src/orxonox.cc
r221 r224 528 528 */ 529 529 std::cout << "Test 10\n"; 530 Identifier* test 9_01 = Class(A1B2);531 Identifier* test 9_02 = Class(A2);532 Identifier* test 9_03 = Class(A3B1C1);533 534 535 BaseObject* test 9_04 = test9_01->fabricate();536 BaseObject* test 9_05 = test9_02->fabricate();537 BaseObject* test 9_06 = test9_03->fabricate();538 539 BaseObject* test 9_07;530 Identifier* test10_01 = Class(A1B2); 531 Identifier* test10_02 = Class(A2); 532 Identifier* test10_03 = Class(A3B1C1); 533 534 535 BaseObject* test10_04 = test10_01->fabricate(); 536 BaseObject* test10_05 = test10_02->fabricate(); 537 BaseObject* test10_06 = test10_03->fabricate(); 538 539 BaseObject* test10_07; 540 540 for (int i = 0; i < 10; i++) 541 test 9_07 = Factory("A1B1C1");541 test10_07 = Factory("A1B1C1"); 542 542 543 543 std::cout << "1\n"; … … 569 569 570 570 std::cout << "2\n"; 571 BaseObject* test9_08; 571 BaseObject* test10_08; 572 BaseObject* test10_09; 573 BaseObject* test10_10; 572 574 for (int i = 0; i < 10; i++) 573 575 { 574 test9_08 = Factory("A2B1C1"); 575 test9_08->name_ = "A2B1C1#"; 576 test9_08->name_ += ('0' + i); 576 test10_08 = Factory("A2B1C1"); 577 test10_08->name_ = "A2B1C1#"; 578 test10_08->name_ += ('0' + i); 579 580 if (i == 0) 581 test10_09 = test10_08; 582 583 if (i == 5) 584 test10_10 = test10_08; 577 585 } 578 586 … … 585 593 586 594 std::cout << "4\n"; 595 delete test10_08; 596 597 std::cout << "5\n"; 598 for (Iterator<A2B1C1> it; it; it++) 599 std::cout << "Name: " << it->name_ << "\n"; 600 601 std::cout << "6\n"; 602 for (Iterator<A2B1C1> it; it; it--) 603 std::cout << "Name: " << it->name_ << "\n"; 604 605 std::cout << "7\n"; 606 delete test10_09; 607 608 std::cout << "8\n"; 609 for (Iterator<A2B1C1> it; it; it++) 610 std::cout << "Name: " << it->name_ << "\n"; 611 612 std::cout << "9\n"; 613 for (Iterator<A2B1C1> it; it; it--) 614 std::cout << "Name: " << it->name_ << "\n"; 615 616 std::cout << "10\n"; 617 delete test10_10; 618 619 std::cout << "11\n"; 620 for (Iterator<A2B1C1> it; it; it++) 621 std::cout << "Name: " << it->name_ << "\n"; 622 623 std::cout << "12\n"; 624 for (Iterator<A2B1C1> it; it; it--) 625 std::cout << "Name: " << it->name_ << "\n"; 587 626 588 627 }
Note: See TracChangeset
for help on using the changeset viewer.