[197] | 1 | #include "Identifier.h" |
---|
| 2 | |
---|
| 3 | namespace orxonox |
---|
| 4 | { |
---|
| 5 | // ############################### |
---|
| 6 | // ### Identifier ### |
---|
| 7 | // ############################### |
---|
[219] | 8 | int Identifier::hierarchyCreatingCounter_s = 0; |
---|
| 9 | |
---|
[197] | 10 | Identifier::Identifier() |
---|
| 11 | { |
---|
| 12 | this->bCreatedOneObject_ = false; |
---|
[219] | 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(); |
---|
[197] | 18 | } |
---|
| 19 | |
---|
| 20 | Identifier::~Identifier() |
---|
| 21 | { |
---|
[219] | 22 | // delete this->directParents_; |
---|
| 23 | // delete this->allParents_; |
---|
| 24 | // delete this->directChildren_; |
---|
| 25 | // delete this->allChildren_; |
---|
| 26 | // delete this->objects_; |
---|
[197] | 27 | delete &this->name_; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | void Identifier::initialize(IdentifierList* parents) |
---|
| 31 | { |
---|
| 32 | std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; |
---|
| 33 | if (parents) |
---|
| 34 | { |
---|
| 35 | this->bCreatedOneObject_ = true; |
---|
| 36 | |
---|
| 37 | IdentifierListElement* temp1; |
---|
| 38 | IdentifierListElement* temp2; |
---|
| 39 | IdentifierListElement* temp3; |
---|
| 40 | |
---|
| 41 | temp1 = parents->first_; |
---|
| 42 | while (temp1) |
---|
| 43 | { |
---|
[219] | 44 | temp2 = temp1->identifier_->directParents_.first_; |
---|
[197] | 45 | while (temp2) |
---|
| 46 | { |
---|
| 47 | temp3 = parents->first_; |
---|
| 48 | while(temp3) |
---|
| 49 | { |
---|
| 50 | if (temp3->identifier_ == temp2->identifier_) |
---|
| 51 | temp3->bDirect_ = false; |
---|
| 52 | |
---|
| 53 | temp3 = temp3->next_; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | temp2 = temp2->next_; |
---|
| 57 | } |
---|
| 58 | temp1 = temp1->next_; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | temp1 = parents->first_; |
---|
| 62 | while (temp1) |
---|
| 63 | { |
---|
| 64 | if (temp1->bDirect_) |
---|
| 65 | { |
---|
[219] | 66 | this->directParents_.add(temp1->identifier_); |
---|
| 67 | temp1->identifier_->directChildren_.add(this); |
---|
[197] | 68 | } |
---|
| 69 | |
---|
[219] | 70 | this->allParents_.add(temp1->identifier_); |
---|
| 71 | temp1->identifier_->allChildren_.add(this); |
---|
[197] | 72 | |
---|
| 73 | temp1 = temp1->next_; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void Identifier::addObject(OrxonoxClass* object) |
---|
| 79 | { |
---|
[220] | 80 | std::cout << "*** Added object to " << this->name_ << "-list.\n"; |
---|
[219] | 81 | this->objects_.add(object); |
---|
[197] | 82 | } |
---|
| 83 | |
---|
| 84 | void Identifier::removeObject(OrxonoxClass* object) |
---|
| 85 | { |
---|
[221] | 86 | bool bIterateForwards = !Identifier::isCreatingHierarchy(); |
---|
[220] | 87 | |
---|
[221] | 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); |
---|
| 94 | |
---|
[220] | 95 | IdentifierListElement* temp = this->directParents_.first_; |
---|
| 96 | while (temp) |
---|
| 97 | { |
---|
| 98 | temp->identifier_->removeObject(object); |
---|
| 99 | temp = temp->next_; |
---|
| 100 | } |
---|
[197] | 101 | } |
---|
| 102 | |
---|
| 103 | bool Identifier::isA(Identifier* identifier) |
---|
| 104 | { |
---|
[219] | 105 | return (identifier == this || this->allParents_.isInList(identifier)); |
---|
[197] | 106 | } |
---|
| 107 | |
---|
| 108 | bool Identifier::isDirectlyA(Identifier* identifier) |
---|
| 109 | { |
---|
| 110 | return (identifier == this); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | bool Identifier::isChildOf(Identifier* identifier) |
---|
| 114 | { |
---|
[219] | 115 | return this->allParents_.isInList(identifier); |
---|
[197] | 116 | } |
---|
| 117 | |
---|
| 118 | bool Identifier::isDirectChildOf(Identifier* identifier) |
---|
| 119 | { |
---|
[219] | 120 | return this->directParents_.isInList(identifier); |
---|
[197] | 121 | } |
---|
| 122 | |
---|
| 123 | bool Identifier::isParentOf(Identifier* identifier) |
---|
| 124 | { |
---|
[219] | 125 | return this->allChildren_.isInList(identifier); |
---|
[197] | 126 | } |
---|
| 127 | |
---|
| 128 | bool Identifier::isDirectParentOf(Identifier* identifier) |
---|
| 129 | { |
---|
[219] | 130 | return this->directChildren_.isInList(identifier); |
---|
[197] | 131 | } |
---|
| 132 | } |
---|