Changeset 248 for code/branches
- Timestamp:
- Nov 26, 2007, 1:57:37 AM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/IdentifierIncludes.h
r246 r248 2 2 #include "Factory.h" 3 3 #include "ClassFactory.h" 4 //#include "IdentifierList.h"5 //#include "ObjectList.h"6 4 #include "Iterator.h" 7 5 #include "OrxonoxClass.h" -
code/branches/objecthierarchie/src/Iterator.h
r239 r248 10 10 Iterator() 11 11 { 12 this->elementForwards_ = ClassIdentifier<T>::getIdentifier()->objects_->first_; 13 this->elementBackwards_ = ClassIdentifier<T>::getIdentifier()->objects_->last_; 14 this->iteratingForwards_ = true; 12 this->element_ = 0; 15 13 } 16 14 17 Iterator <T> operator++(int step)15 Iterator(ObjectListElement<T>* element) 18 16 { 19 Iterator<T> copy = *this; 20 21 if (step < 1) 22 step = 1; 23 24 for (int i = 0; i < step; i++) 25 this->elementForwards_ = this->elementForwards_->next_; 26 27 return copy; 17 this->element_ = element; 28 18 } 29 19 30 20 Iterator<T> operator++() 31 21 { 32 this->element Forwards_ = this->elementForwards_->next_;22 this->element_ = this->element_->next_; 33 23 return *this; 34 }35 36 Iterator<T> operator--(int step)37 {38 Iterator<T> copy = *this;39 40 if (this->iteratingForwards_)41 {42 this->iteratingForwards_ = false;43 }44 else45 {46 if (step < 1)47 step = 1;48 49 for (int i = 0; i < step; i++)50 this->elementBackwards_ = this->elementBackwards_->prev_;51 }52 24 } 53 25 54 26 Iterator<T> operator--() 55 27 { 56 if (this->iteratingForwards_) 57 this->iteratingForwards_ = false; 58 else 59 this->elementBackwards_ = this->elementBackwards_->prev_; 60 28 this->element_ = this->element_->prev_; 61 29 return *this; 62 30 } … … 64 32 T* operator*() 65 33 { 66 if (this->iteratingForwards_) 67 return this->elementForwards_->object_; 68 else 69 return this->elementBackwards_->object_; 34 return this->element_->object_; 70 35 } 71 36 72 37 T* operator->() const 73 38 { 74 if (this->iteratingForwards_) 75 return this->elementForwards_->object_; 76 else 77 return this->elementBackwards_->object_; 39 return this->element_->object_; 78 40 79 41 } … … 81 43 operator bool() 82 44 { 83 if (this->iteratingForwards_) 84 return (this->elementForwards_ != 0); 85 else 86 return (this->elementBackwards_->prev_ != 0); 45 return (this->element_ != 0); 87 46 } 88 47 … … 92 51 std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n"; 93 52 94 if (this->iteratingForwards_) 95 return (this->elementForwards_ != 0); 96 else 97 return (this->elementBackwards_->prev_ != 0); 53 return (this->element_ != 0); 98 54 } 99 55 100 101 56 private: 102 ObjectListElement<T>* elementForwards_; 103 ObjectListElement<T>* elementBackwards_; 104 bool iteratingForwards_; 57 ObjectListElement<T>* element_; 105 58 }; 106 59 } -
code/branches/objecthierarchie/src/ObjectList.h
r246 r248 39 39 // ############################### 40 40 template <class T> 41 class Iterator; 42 43 template <class T> 41 44 class ObjectList 42 45 { … … 47 50 void remove(OrxonoxClass* object, bool bIterateForwards = true); 48 51 52 inline static Iterator<T> start() 53 { Iterator<T>(pointer_s->first_); } 54 inline static Iterator<T> end() 55 { Iterator<T>(pointer_s->last_); } 56 49 57 ObjectListElement<T>* first_; 50 58 ObjectListElement<T>* last_; 59 60 private: 61 static ObjectList<T>* pointer_s; 51 62 }; 63 64 template <class T> 65 ObjectList<T>* ObjectList<T>::pointer_s = 0; 52 66 53 67 template <class T> … … 56 70 this->first_ = 0; 57 71 this->last_ = 0; 72 73 this->pointer_s = this; 58 74 } 59 75 -
code/branches/objecthierarchie/src/orxonox.cc
r246 r248 435 435 delete test9_06; 436 436 */ 437 /* 437 438 438 std::cout << "Test 10\n"; 439 439 Identifier* test10_01 = Class(A1B2); … … 451 451 std::cout << "1\n"; 452 452 int count; 453 count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; } 453 454 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 454 455 std::cout << "Anzahl BaseObjects: " << count << "\n"; 455 count = 0; for (Iterator<A1> it ; it != 0; ++it) { count++; }456 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 456 457 std::cout << "Anzahl A1: " << count << "\n"; 457 count = 0; for (Iterator<A1B1> it ; it; ++it) { count++; }458 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 458 459 std::cout << "Anzahl A1B1: " << count << "\n"; 459 count = 0; for (Iterator<A1B1C1> it ; it; ++it) { count++; }460 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 460 461 std::cout << "Anzahl A1B1C1: " << count << "\n"; 461 count = 0; for (Iterator<A2> it ; it; ++it) { count++; }462 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 462 463 std::cout << "Anzahl A2: " << count << "\n"; 463 464 … … 479 480 } 480 481 481 count = 0; for (Iterator<BaseObject> it ; it != 0; ++it) { count++; }482 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 482 483 std::cout << "Anzahl BaseObjects: " << count << "\n"; 483 count = 0; for (Iterator<A1> it ; it != 0; ++it) { count++; }484 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 484 485 std::cout << "Anzahl A1: " << count << "\n"; 485 count = 0; for (Iterator<A1B1> it ; it; ++it) { count++; }486 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 486 487 std::cout << "Anzahl A1B1: " << count << "\n"; 487 count = 0; for (Iterator<A1B1C1> it ; it; ++it) { count++; }488 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 488 489 std::cout << "Anzahl A1B1C1: " << count << "\n"; 489 count = 0; for (Iterator<A2> it ; it; ++it) { count++; }490 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 490 491 std::cout << "Anzahl A2: " << count << "\n"; 491 492 492 for (Iterator<A2B1C1> it ; it; ++it)493 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 493 494 std::cout << "Name: " << it->name_ << "\n"; 494 495 495 496 std::cout << "3\n"; 496 for (Iterator<A2B1C1> it ; it; --it)497 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 497 498 std::cout << "Name: " << it->name_ << "\n"; 498 499 … … 500 501 delete test10_08; 501 502 502 count = 0; for (Iterator<BaseObject> it ; it != 0; ++it) { count++; }503 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 503 504 std::cout << "Anzahl BaseObjects: " << count << "\n"; 504 count = 0; for (Iterator<A1> it ; it != 0; ++it) { count++; }505 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 505 506 std::cout << "Anzahl A1: " << count << "\n"; 506 count = 0; for (Iterator<A1B1> it ; it; ++it) { count++; }507 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 507 508 std::cout << "Anzahl A1B1: " << count << "\n"; 508 count = 0; for (Iterator<A1B1C1> it ; it; ++it) { count++; }509 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 509 510 std::cout << "Anzahl A1B1C1: " << count << "\n"; 510 count = 0; for (Iterator<A2> it ; it; ++it) { count++; }511 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 511 512 std::cout << "Anzahl A2: " << count << "\n"; 512 513 513 514 std::cout << "5\n"; 514 for (Iterator<A2B1C1> it ; it; ++it)515 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 515 516 std::cout << "Name: " << it->name_ << "\n"; 516 517 517 518 std::cout << "6\n"; 518 for (Iterator<A2B1C1> it ; it; --it)519 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 519 520 std::cout << "Name: " << it->name_ << "\n"; 520 521 … … 522 523 delete test10_09; 523 524 524 count = 0; for (Iterator<BaseObject> it ; it != 0; ++it) { count++; }525 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it != 0; --it) { count++; } 525 526 std::cout << "Anzahl BaseObjects: " << count << "\n"; 526 count = 0; for (Iterator<A1> it ; it != 0; ++it) { count++; }527 count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it != 0; --it) { count++; } 527 528 std::cout << "Anzahl A1: " << count << "\n"; 528 count = 0; for (Iterator<A1B1> it ; it; ++it) { count++; }529 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::end(); it; --it) { count++; } 529 530 std::cout << "Anzahl A1B1: " << count << "\n"; 530 count = 0; for (Iterator<A1B1C1> it ; it; ++it) { count++; }531 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::end(); it; --it) { count++; } 531 532 std::cout << "Anzahl A1B1C1: " << count << "\n"; 532 count = 0; for (Iterator<A2> it ; it; ++it) { count++; }533 count = 0; for (Iterator<A2> it = ObjectList<A2>::end(); it; --it) { count++; } 533 534 std::cout << "Anzahl A2: " << count << "\n"; 534 535 535 536 std::cout << "8\n"; 536 for (Iterator<A2B1C1> it ; it; ++it)537 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 537 538 std::cout << "Name: " << it->name_ << "\n"; 538 539 539 540 std::cout << "9\n"; 540 for (Iterator<A2B1C1> it ; it; --it)541 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 541 542 std::cout << "Name: " << it->name_ << "\n"; 542 543 … … 544 545 delete test10_10; 545 546 546 count = 0; for (Iterator<BaseObject> it ; it != 0; ++it) { count++; }547 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 547 548 std::cout << "Anzahl BaseObjects: " << count << "\n"; 548 count = 0; for (Iterator<A1> it ; it != 0; ++it) { count++; }549 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 549 550 std::cout << "Anzahl A1: " << count << "\n"; 550 count = 0; for (Iterator<A1B1> it ; it; ++it) { count++; }551 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 551 552 std::cout << "Anzahl A1B1: " << count << "\n"; 552 count = 0; for (Iterator<A1B1C1> it ; it; ++it) { count++; }553 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 553 554 std::cout << "Anzahl A1B1C1: " << count << "\n"; 554 count = 0; for (Iterator<A2> it ; it; ++it) { count++; }555 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 555 556 std::cout << "Anzahl A2: " << count << "\n"; 556 557 557 558 std::cout << "11\n"; 558 for (Iterator<A2B1C1> it ; it; ++it)559 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 559 560 std::cout << "Name: " << it->name_ << "\n"; 560 561 561 562 std::cout << "12\n"; 562 for (Iterator<A2B1C1> it ; it; --it)563 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 563 564 std::cout << "Name: " << it->name_ << "\n"; 564 */ 565 565 566 566 567 }
Note: See TracChangeset
for help on using the changeset viewer.