[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 | { |
---|
[220] | 86 | std::cout << "*** Removed object from " << this->name_ << "-list.\n"; |
---|
[219] | 87 | this->objects_.remove(object); |
---|
[220] | 88 | |
---|
| 89 | IdentifierListElement* temp = this->directParents_.first_; |
---|
| 90 | while (temp) |
---|
| 91 | { |
---|
| 92 | temp->identifier_->removeObject(object); |
---|
| 93 | temp = temp->next_; |
---|
| 94 | } |
---|
[197] | 95 | } |
---|
| 96 | |
---|
| 97 | bool Identifier::isA(Identifier* identifier) |
---|
| 98 | { |
---|
[219] | 99 | return (identifier == this || this->allParents_.isInList(identifier)); |
---|
[197] | 100 | } |
---|
| 101 | |
---|
| 102 | bool Identifier::isDirectlyA(Identifier* identifier) |
---|
| 103 | { |
---|
| 104 | return (identifier == this); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | bool Identifier::isChildOf(Identifier* identifier) |
---|
| 108 | { |
---|
[219] | 109 | return this->allParents_.isInList(identifier); |
---|
[197] | 110 | } |
---|
| 111 | |
---|
| 112 | bool Identifier::isDirectChildOf(Identifier* identifier) |
---|
| 113 | { |
---|
[219] | 114 | return this->directParents_.isInList(identifier); |
---|
[197] | 115 | } |
---|
| 116 | |
---|
| 117 | bool Identifier::isParentOf(Identifier* identifier) |
---|
| 118 | { |
---|
[219] | 119 | return this->allChildren_.isInList(identifier); |
---|
[197] | 120 | } |
---|
| 121 | |
---|
| 122 | bool Identifier::isDirectParentOf(Identifier* identifier) |
---|
| 123 | { |
---|
[219] | 124 | return this->directChildren_.isInList(identifier); |
---|
[197] | 125 | } |
---|
| 126 | } |
---|