Changeset 221 for code/branches/objecthierarchie/src
- Timestamp:
- Nov 20, 2007, 2:57:59 AM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/BaseObject.h
r220 r221 64 64 { this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 65 65 66 std::string name_; // test 67 66 68 }; 67 69 } -
code/branches/objecthierarchie/src/CMakeLists.txt
r219 r221 3 3 # create a few variables to simplify life 4 4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.cc Identifier.cc Factory.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc) 5 SET(INC_FILES IdentifierIncludes.h Identifier.h Factory.h IdentifierList.h ObjectList.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h)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 7 7 #Creates an executable -
code/branches/objecthierarchie/src/Identifier.cc
r220 r221 84 84 void Identifier::removeObject(OrxonoxClass* object) 85 85 { 86 std::cout << "*** Removed object from " << this->name_ << "-list.\n"; 87 this->objects_.remove(object); 86 bool bIterateForwards = !Identifier::isCreatingHierarchy(); 87 88 if (bIterateForwards) 89 std::cout << "*** Removed object from " << this->name_ << "-list, iterating forwards.\n"; 90 else 91 std::cout << "*** Removed object from " << this->name_ << "-list, iterating backwards.\n"; 92 93 this->objects_.remove(object, bIterateForwards); 88 94 89 95 IdentifierListElement* temp = this->directParents_.first_; -
code/branches/objecthierarchie/src/Identifier.h
r220 r221 35 35 friend class BaseIdentifier; 36 36 37 template <class T> 38 friend class Iterator; 39 37 40 public: 38 41 void addObject(OrxonoxClass* object); … … 172 175 Identifier::startCreatingHierarchy(); 173 176 T* temp = new T(); 177 delete temp; 174 178 Identifier::stopCreatingHierarchy(); 175 delete temp;176 179 } 177 180 … … 186 189 BaseIdentifier(); 187 190 188 BaseIdentifier<B>& operator= 191 BaseIdentifier<B>& operator=(Identifier* identifier) 189 192 { 190 193 if (!identifier->isA(ClassIdentifier<B>::getIdentifier())) … … 199 202 } 200 203 201 Identifier* operator* 204 Identifier* operator*() 202 205 { 203 206 return this->identifier_; 204 207 } 205 208 206 Identifier* operator-> 209 Identifier* operator->() const 207 210 { 208 211 return this->identifier_; -
code/branches/objecthierarchie/src/IdentifierIncludes.h
r220 r221 3 3 #include "IdentifierList.h" 4 4 #include "ObjectList.h" 5 #include "Iterator.h" 5 6 #include "OrxonoxClass.h" 6 7 -
code/branches/objecthierarchie/src/ObjectList.cc
r197 r221 9 9 { 10 10 this->first_ = 0; 11 this->last_ = 0; 11 12 } 12 13 … … 24 25 void ObjectList::add(OrxonoxClass* object) 25 26 { 26 ObjectListElement* temp = this->first_; 27 this->first_ = new ObjectListElement(object); 28 this->first_->next_ = temp; 27 if (!this->last_) 28 { 29 this->last_ = new ObjectListElement(object); 30 this->first_ = this->last_; 31 } 32 else 33 { 34 ObjectListElement* temp = this->last_; 35 this->last_ = new ObjectListElement(object); 36 this->last_->prev_ = temp; 37 temp->next_ = this->last_; 38 } 29 39 } 30 40 31 void ObjectList::remove(OrxonoxClass* object )41 void ObjectList::remove(OrxonoxClass* object, bool bIterateForwards) 32 42 { 33 if (!object )43 if (!object || !this->first_ || !this->last_) 34 44 return; 35 45 36 if (this->first_ ->object_ == object)46 if (this->first_ == this->last_) 37 47 { 38 ObjectListElement* temp = this->first_->next_; 39 delete this->first_; 40 this->first_ = temp; 48 if (this->first_->object_ == object) 49 { 50 delete this->first_; 51 this->first_ = 0; 52 this->last_ = 0; 53 } 41 54 42 55 return; 43 56 } 44 57 45 ObjectListElement* temp = this->first_; 46 while (temp->next_) 58 if (bIterateForwards) 47 59 { 48 if (t emp->next_->object_ == object)60 if (this->first_->object_ == object) 49 61 { 50 ObjectListElement* temp 2 = temp->next_->next_;51 delete t emp->next_;52 t emp->next_ = temp2;62 ObjectListElement* temp = this->first_->next_; 63 delete this->first_; 64 this->first_ = temp; 53 65 54 66 return; 55 67 } 56 68 57 temp = temp->next_; 69 ObjectListElement* temp = this->first_; 70 while (temp->next_) 71 { 72 if (temp->next_->object_ == object) 73 { 74 ObjectListElement* temp2 = temp->next_->next_; 75 delete temp->next_; 76 temp->next_ = temp2; 77 temp2->prev_ = temp; 78 79 return; 80 } 81 82 temp = temp->next_; 83 } 84 } 85 else 86 { 87 if (this->last_->object_ == object) 88 { 89 ObjectListElement* temp = this->last_->prev_; 90 delete this->last_; 91 this->last_ = temp; 92 93 return; 94 } 95 96 ObjectListElement* temp = this->last_; 97 while (temp->prev_) 98 { 99 if (temp->prev_->object_ == object) 100 { 101 ObjectListElement* temp2 = temp->prev_->prev_; 102 delete temp->prev_; 103 temp->prev_ = temp2; 104 temp2->next_ = temp; 105 106 return; 107 } 108 109 temp = temp->prev_; 110 } 58 111 } 59 112 } … … 67 120 this->object_ = object; 68 121 this->next_ = 0; 122 this->prev_ = 0; 69 123 } 70 124 -
code/branches/objecthierarchie/src/ObjectList.h
r197 r221 14 14 OrxonoxClass* object_; 15 15 ObjectListElement* next_; 16 ObjectListElement* prev_; 16 17 }; 17 18 … … 22 23 ~ObjectList(); 23 24 void add(OrxonoxClass* object); 24 void remove(OrxonoxClass* object );25 void remove(OrxonoxClass* object, bool bIterateForwards = true); 25 26 26 27 ObjectListElement* first_; 28 ObjectListElement* last_; 27 29 }; 28 30 } -
code/branches/objecthierarchie/src/orxonox.cc
r219 r221 500 500 delete test8_03; 501 501 */ 502 502 /* 503 503 std::cout << "Test 9\n"; 504 504 std::cout << "1\n"; … … 526 526 delete test9_05; 527 527 delete test9_06; 528 */ 529 std::cout << "Test 10\n"; 530 Identifier* test9_01 = Class(A1B2); 531 Identifier* test9_02 = Class(A2); 532 Identifier* test9_03 = Class(A3B1C1); 533 534 535 BaseObject* test9_04 = test9_01->fabricate(); 536 BaseObject* test9_05 = test9_02->fabricate(); 537 BaseObject* test9_06 = test9_03->fabricate(); 538 539 BaseObject* test9_07; 540 for (int i = 0; i < 10; i++) 541 test9_07 = Factory("A1B1C1"); 542 543 std::cout << "1\n"; 544 int count = 0; 545 for (Iterator<BaseObject> it; it != 0; it++) 546 count++; 547 std::cout << "Anzahl BaseObjects: " << count << "\n"; 548 549 count = 0; 550 for (Iterator<A1> it; it != 0; it++) 551 count++; 552 std::cout << "Anzahl A1: " << count << "\n"; 553 554 count = 0; 555 for (Iterator<A1B1> it; it; it++) 556 count++; 557 std::cout << "Anzahl A1B1: " << count << "\n"; 558 559 count = 0; 560 for (Iterator<A1B1C1> it; it; it++) 561 count++; 562 std::cout << "Anzahl A1B1C1: " << count << "\n"; 563 564 count = 0; 565 for (Iterator<A2> it; it; it++) 566 count++; 567 std::cout << "Anzahl A2: " << count << "\n"; 568 569 570 std::cout << "2\n"; 571 BaseObject* test9_08; 572 for (int i = 0; i < 10; i++) 573 { 574 test9_08 = Factory("A2B1C1"); 575 test9_08->name_ = "A2B1C1#"; 576 test9_08->name_ += ('0' + i); 577 } 578 579 for (Iterator<A2B1C1> it; it; it++) 580 std::cout << "Name: " << it->name_ << "\n"; 581 582 std::cout << "3\n"; 583 for (Iterator<A2B1C1> it; it; it--) 584 std::cout << "Name: " << it->name_ << "\n"; 585 586 std::cout << "4\n"; 528 587 529 588 }
Note: See TracChangeset
for help on using the changeset viewer.