Changeset 243 for code/branches/objecthierarchie
- Timestamp:
- Nov 25, 2007, 4:07:56 AM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/BaseObject.h
r242 r243 18 18 inline bool isChildOf(const Identifier* identifier) 19 19 { this->getIdentifier()->isChildOf(identifier); } 20 inline bool isDirectChildOf(const Identifier* identifier)21 { this->getIdentifier()->isDirectChildOf(identifier); }22 20 inline bool isParentOf(const Identifier* identifier) 23 21 { this->getIdentifier()->isParentOf(identifier); } 24 inline bool isDirectParentOf(const Identifier* identifier)25 { this->getIdentifier()->isDirectParentOf(identifier); }26 22 27 23 inline bool isA(const SubclassIdentifier<class B>* identifier) … … 31 27 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 32 28 { this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 33 inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier)34 { this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }35 29 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 36 30 { this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 37 inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier)38 { this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }39 31 40 32 inline bool isA(const SubclassIdentifier<class B> identifier) … … 44 36 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 45 37 { this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 46 inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier)47 { this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }48 38 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 49 39 { this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 50 inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier)51 { this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }52 40 53 41 inline bool isA(const OrxonoxClass* object) … … 57 45 inline bool isChildOf(const OrxonoxClass* object) 58 46 { this->getIdentifier()->isChildOf(object->getIdentifier()); } 59 inline bool isDirectChildOf(const OrxonoxClass* object)60 { this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }61 47 inline bool isParentOf(const OrxonoxClass* object) 62 48 { this->getIdentifier()->isParentOf(object->getIdentifier()); } 63 inline bool isDirectParentOf(const OrxonoxClass* object)64 { this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }65 49 66 50 std::string name_; // test -
code/branches/objecthierarchie/src/Identifier.cc
r241 r243 12 12 this->bCreatedOneObject_ = false; 13 13 14 this->directChildren_ = new IdentifierList; 15 this->allChildren_ = new IdentifierList; 14 this->children_ = new IdentifierList; 16 15 } 17 16 … … 20 19 delete &this->name_; 21 20 22 delete this->directChildren_; 23 delete this->allChildren_; 21 delete this->children_; 24 22 } 25 23 … … 33 31 this->bCreatedOneObject_ = true; 34 32 35 IdentifierListElement* temp1; 36 IdentifierListElement* temp2; 37 IdentifierListElement* temp3; 38 39 temp1 = parents->first_; 33 IdentifierListElement* temp1 = parents->first_; 40 34 while (temp1) 41 35 { 42 temp2 = temp1->identifier_->directParents_.first_; 43 while (temp2) 44 { 45 temp3 = parents->first_; 46 while(temp3) 47 { 48 if (temp3->identifier_ == temp2->identifier_) 49 temp3->bDirect_ = false; 50 51 temp3 = temp3->next_; 52 } 53 54 temp2 = temp2->next_; 55 } 56 temp1 = temp1->next_; 57 } 58 59 temp1 = parents->first_; 60 while (temp1) 61 { 62 if (temp1->bDirect_) 63 { 64 this->directParents_.add(temp1->identifier_); 65 temp1->identifier_->getDirectChildren().add(this); 66 } 67 68 this->allParents_.add(temp1->identifier_); 69 temp1->identifier_->getAllChildren().add(this); 36 this->parents_.add(temp1->identifier_); 37 temp1->identifier_->getChildren().add(this); 70 38 71 39 temp1 = temp1->next_; … … 76 44 bool Identifier::isA(const Identifier* identifier) const 77 45 { 78 return (identifier == this || this-> allParents_.isInList(identifier));46 return (identifier == this || this->parents_.isInList(identifier)); 79 47 } 80 48 … … 86 54 bool Identifier::isChildOf(const Identifier* identifier) const 87 55 { 88 return this->allParents_.isInList(identifier); 89 } 90 91 bool Identifier::isDirectChildOf(const Identifier* identifier) const 92 { 93 return this->directParents_.isInList(identifier); 56 return this->parents_.isInList(identifier); 94 57 } 95 58 96 59 bool Identifier::isParentOf(const Identifier* identifier) const 97 60 { 98 return this->allChildren_->isInList(identifier); 99 } 100 101 bool Identifier::isDirectParentOf(const Identifier* identifier) const 102 { 103 return this->directChildren_->isInList(identifier); 61 return this->children_->isInList(identifier); 104 62 } 105 63 } -
code/branches/objecthierarchie/src/Identifier.h
r242 r243 28 28 public: 29 29 virtual void removeObject(OrxonoxClass* object) const = 0; 30 virtual void removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const = 0; 30 31 31 32 virtual BaseObject* fabricate() const = 0; … … 34 35 bool isDirectlyA(const Identifier* identifier) const; 35 36 bool isChildOf(const Identifier* identifier) const; 36 bool isDirectChildOf(const Identifier* identifier) const;37 37 bool isParentOf(const Identifier* identifier) const; 38 bool isDirectParentOf(const Identifier* identifier) const;39 38 40 39 const std::string& getName() const { return this->name_; } 41 const IdentifierList& getDirectParents() const { return this->directParents_; } 42 const IdentifierList& getAllParents() const { return this->allParents_; } 43 IdentifierList& getDirectChildren() const { return *this->directChildren_; } 44 IdentifierList& getAllChildren() const { return *this->allChildren_; } 40 const IdentifierList& getParents() const { return this->parents_; } 41 IdentifierList& getChildren() const { return *this->children_; } 45 42 46 43 static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } … … 68 65 } 69 66 70 IdentifierList directParents_; 71 IdentifierList allParents_; 72 IdentifierList* directChildren_; 73 IdentifierList* allChildren_; 67 IdentifierList parents_; 68 IdentifierList* children_; 74 69 75 70 std::string name_; … … 98 93 static void addObject(T* object); 99 94 void removeObject(OrxonoxClass* object) const; 95 void removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const; 100 96 101 97 private: … … 212 208 bool bIterateForwards = !Identifier::isCreatingHierarchy(); 213 209 210 this->removeObjectIntern(object, bIterateForwards); 211 212 IdentifierListElement* temp = this->parents_.first_; 213 while (temp) 214 { 215 temp->identifier_->removeObjectIntern(object, bIterateForwards); 216 temp = temp->next_; 217 } 218 } 219 220 template <class T> 221 void ClassIdentifier<T>::removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const 222 { 214 223 #if HIERARCHY_VERBOSE 215 224 if (bIterateForwards) … … 220 229 221 230 this->objects_->remove(object, bIterateForwards); 222 223 IdentifierListElement* temp = this->directParents_.first_;224 while (temp)225 {226 temp->identifier_->removeObject(object);227 temp = temp->next_;228 }229 231 } 230 232 … … 295 297 inline bool isChildOf(const Identifier* identifier) const 296 298 { return this->identifier_->isChildOf(identifier); } 297 inline bool isDirectChildOf(const Identifier* identifier) const298 { return this->identifier_->isDirectChildOf(identifier); }299 299 inline bool isParentOf(const Identifier* identifier) const 300 300 { return this->identifier_->isParentOf(identifier); } 301 inline bool isDirectParentOf(const Identifier* identifier) const302 { return this->identifier_->isDirectParentOf(identifier); }303 301 304 302 private: -
code/branches/objecthierarchie/src/IdentifierList.cc
r241 r243 98 98 this->identifier_ = identifier; 99 99 this->next_ = 0; 100 this->bDirect_ = true;101 100 } 102 101 -
code/branches/objecthierarchie/src/IdentifierList.h
r241 r243 16 16 const Identifier* identifier_; 17 17 IdentifierListElement* next_; 18 bool bDirect_;19 18 }; 20 19 -
code/branches/objecthierarchie/src/orxonox.cc
r242 r243 147 147 A3B2C1* test5_17 = new A3B2C1(); 148 148 A3B2C2* test5_18 = new A3B2C2(); 149 */ 150 /* 149 151 150 OrxonoxClass* test5; 152 151 for (int i = 0; i <= 18; i++) 153 152 { 154 if (i == 0) test5 = test1;153 if (i == 0) test5 = new BaseObject; 155 154 if (i == 1) test5 = test5_01; 156 155 if (i == 2) test5 = test5_02; … … 173 172 174 173 std::cout << "\n"; 175 std::cout << test5->getIdentifier()->getName() << ": directParents: " << test5->getIdentifier()->getDirectParents()->toString() << "\n"; 176 std::cout << test5->getIdentifier()->getName() << ": allParents: " << test5->getIdentifier()->getAllParents()->toString() << "\n"; 177 std::cout << test5->getIdentifier()->getName() << ": directChildren: " << test5->getIdentifier()->getDirectChildren()->toString() << "\n"; 178 std::cout << test5->getIdentifier()->getName() << ": allChildren: " << test5->getIdentifier()->getAllChildren()->toString() << "\n"; 174 std::cout << test5->getIdentifier()->getName() << ": parents: " << test5->getIdentifier()->getParents().toString() << "\n"; 175 std::cout << test5->getIdentifier()->getName() << ": children: " << test5->getIdentifier()->getChildren().toString() << "\n"; 179 176 } 180 177 */ … … 284 281 285 282 std::cout << "\n"; 286 std::cout << "isDirectChildOf(XYZ)-Test:\n";287 std::cout << "test5_04 = A1B1, Erwartet: 1 0 0 0 0 0 0\n";288 testandcout(test5_04->isDirectChildOf(Class(A1)));289 testandcout(test5_04->isDirectChildOf(Class(A2)));290 testandcout(test5_04->isDirectChildOf(Class(BaseObject)));291 testandcout(test5_04->isDirectChildOf(Class(Interface1)));292 testandcout(test5_04->isDirectChildOf(Class(Interface2)));293 testandcout(test5_04->isDirectChildOf(Class(A1B1C2)));294 testandcout(test5_04->isDirectChildOf(Class(A1B1)));295 296 std::cout << "\n";297 std::cout << "test5_06 = A2B1, Erwartet: 0 1 0 0 0 0 0\n";298 testandcout(test5_06->isDirectChildOf(Class(A1)));299 testandcout(test5_06->isDirectChildOf(Class(A2)));300 testandcout(test5_06->isDirectChildOf(Class(BaseObject)));301 testandcout(test5_06->isDirectChildOf(Class(Interface1)));302 testandcout(test5_06->isDirectChildOf(Class(Interface2)));303 testandcout(test5_06->isDirectChildOf(Class(A1B1C2)));304 testandcout(test5_06->isDirectChildOf(Class(A1B1)));305 306 std::cout << "\n";307 std::cout << "test5_07 = A2B2, Erwartet: 0 1 0 1 0 0\n";308 testandcout(test5_07->isDirectChildOf(Class(A1)));309 testandcout(test5_07->isDirectChildOf(Class(A2)));310 testandcout(test5_07->isDirectChildOf(Class(BaseObject)));311 testandcout(test5_07->isDirectChildOf(Class(Interface1)));312 testandcout(test5_07->isDirectChildOf(Class(Interface2)));313 testandcout(test5_07->isDirectChildOf(Class(A1B1C2)));314 315 std::cout << "\n";316 std::cout << "test5_08 = A3B1, Erwartet: 0 0 0 0 0 0\n";317 testandcout(test5_08->isDirectChildOf(Class(A1)));318 testandcout(test5_08->isDirectChildOf(Class(A2)));319 testandcout(test5_08->isDirectChildOf(Class(BaseObject)));320 testandcout(test5_08->isDirectChildOf(Class(Interface1)));321 testandcout(test5_08->isDirectChildOf(Class(Interface2)));322 testandcout(test5_08->isDirectChildOf(Class(A1B1C2)));323 324 std::cout << "\n";325 std::cout << "test5_09 = A3B2, Erwartet: 0 0 0 0 1 0\n";326 testandcout(test5_09->isDirectChildOf(Class(A1)));327 testandcout(test5_09->isDirectChildOf(Class(A2)));328 testandcout(test5_09->isDirectChildOf(Class(BaseObject)));329 testandcout(test5_09->isDirectChildOf(Class(Interface1)));330 testandcout(test5_09->isDirectChildOf(Class(Interface2)));331 testandcout(test5_09->isDirectChildOf(Class(A1B1C2)));332 333 std::cout << "\n";334 283 std::cout << "isParentOf(XYZ)-Test:\n"; 335 284 std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 1 1 1\n"; … … 361 310 testandcout(Class(Interface1)->isParentOf(Class(A2B2))); 362 311 testandcout(Class(Interface1)->isParentOf(Class(A3B1C2))); 363 364 std::cout << "\n";365 std::cout << "isDirectParentOf(XYZ)-Test:\n";366 std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 0 0 0\n";367 testandcout(test1->isDirectParentOf(Class(BaseObject)));368 testandcout(test1->isDirectParentOf(Class(Interface1)));369 testandcout(test1->isDirectParentOf(Class(A1)));370 testandcout(test1->isDirectParentOf(Class(A2)));371 testandcout(test1->isDirectParentOf(Class(A1B1)));372 testandcout(test1->isDirectParentOf(Class(A2B2)));373 testandcout(test1->isDirectParentOf(Class(A3B1C2)));374 375 std::cout << "\n";376 std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n";377 testandcout(test5_01->isDirectParentOf(Class(BaseObject)));378 testandcout(test5_01->isDirectParentOf(Class(Interface1)));379 testandcout(test5_01->isDirectParentOf(Class(A1)));380 testandcout(test5_01->isDirectParentOf(Class(A2)));381 testandcout(test5_01->isDirectParentOf(Class(A1B1)));382 testandcout(test5_01->isDirectParentOf(Class(A2B2)));383 testandcout(test5_01->isDirectParentOf(Class(A3B1C2)));384 385 std::cout << "\n";386 std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 0\n";387 testandcout(Class(Interface1)->isDirectParentOf(Class(BaseObject)));388 testandcout(Class(Interface1)->isDirectParentOf(Class(Interface1)));389 testandcout(Class(Interface1)->isDirectParentOf(Class(A1)));390 testandcout(Class(Interface1)->isDirectParentOf(Class(A2)));391 testandcout(Class(Interface1)->isDirectParentOf(Class(A1B1)));392 testandcout(Class(Interface1)->isDirectParentOf(Class(A2B2)));393 testandcout(Class(Interface1)->isDirectParentOf(Class(A3B1C2)));394 312 */ 395 313 /* … … 407 325 std::cout << "6:\n"; 408 326 Identifier* test6_06 = Class(A1B1C1); 409 */ 410 /* 411 std::cout << "\n"; 412 std::cout << "BaseObject: directParents: " << Class(BaseObject)->getDirectParents()->toString() << "\n"; 413 std::cout << "BaseObject: allParents: " << Class(BaseObject)->getAllParents()->toString() << "\n"; 414 std::cout << "BaseObject: directChildren: " << Class(BaseObject)->getDirectChildren()->toString() << "\n"; 415 std::cout << "BaseObject: allChildren: " << Class(BaseObject)->getAllChildren()->toString() << "\n"; 416 417 std::cout << "\n"; 418 std::cout << "A1: directParents: " << Class(A1)->getDirectParents()->toString() << "\n"; 419 std::cout << "A1: allParents: " << Class(A1)->getAllParents()->toString() << "\n"; 420 std::cout << "A1: directChildren: " << Class(A1)->getDirectChildren()->toString() << "\n"; 421 std::cout << "A1: allChildren: " << Class(A1)->getAllChildren()->toString() << "\n"; 422 423 std::cout << "\n"; 424 std::cout << "A1B1: directParents: " << Class(A1B1)->getDirectParents()->toString() << "\n"; 425 std::cout << "A1B1: allParents: " << Class(A1B1)->getAllParents()->toString() << "\n"; 426 std::cout << "A1B1: directChildren: " << Class(A1B1)->getDirectChildren()->toString() << "\n"; 427 std::cout << "A1B1: allChildren: " << Class(A1B1)->getAllChildren()->toString() << "\n"; 428 429 std::cout << "\n"; 430 std::cout << "A1B1C1: directParents: " << Class(A1B1C1)->getDirectParents()->toString() << "\n"; 431 std::cout << "A1B1C1: allParents: " << Class(A1B1C1)->getAllParents()->toString() << "\n"; 432 std::cout << "A1B1C1: directChildren: " << Class(A1B1C1)->getDirectChildren()->toString() << "\n"; 433 std::cout << "A1B1C1: allChildren: " << Class(A1B1C1)->getAllChildren()->toString() << "\n"; 327 328 std::cout << "\n"; 329 std::cout << "BaseObject: parents: " << Class(BaseObject)->getParents().toString() << "\n"; 330 std::cout << "BaseObject: children: " << Class(BaseObject)->getChildren().toString() << "\n"; 331 332 std::cout << "\n"; 333 std::cout << "A1: parents: " << Class(A1)->getParents().toString() << "\n"; 334 std::cout << "A1: children: " << Class(A1)->getChildren().toString() << "\n"; 335 336 std::cout << "\n"; 337 std::cout << "A1B1: parents: " << Class(A1B1)->getParents().toString() << "\n"; 338 std::cout << "A1B1: children: " << Class(A1B1)->getChildren().toString() << "\n"; 339 340 std::cout << "\n"; 341 std::cout << "A1B1C1: parents: " << Class(A1B1C1)->getParents().toString() << "\n"; 342 std::cout << "A1B1C1: children: " << Class(A1B1C1)->getChildren().toString() << "\n"; 434 343 435 344 std::cout << "\n"; … … 437 346 std::cout << "\n"; 438 347 std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n"; 439 */ 440 /* 348 349 441 350 std::cout << "Test 7\n"; 442 351 std::cout << "1\n"; … … 527 436 delete test9_06; 528 437 */ 438 529 439 std::cout << "Test 10\n"; 530 440 Identifier* test10_01 = Class(A1B2); … … 624 534 for (Iterator<A2B1C1> it; it; --it) 625 535 std::cout << "Name: " << it->name_ << "\n"; 536 626 537 627 538 }
Note: See TracChangeset
for help on using the changeset viewer.