[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; |
---|
[239] | 13 | |
---|
| 14 | this->directChildren_ = new IdentifierList; |
---|
| 15 | this->allChildren_ = new IdentifierList; |
---|
[197] | 16 | } |
---|
| 17 | |
---|
| 18 | Identifier::~Identifier() |
---|
| 19 | { |
---|
| 20 | delete &this->name_; |
---|
[239] | 21 | |
---|
| 22 | delete this->directChildren_; |
---|
| 23 | delete this->allChildren_; |
---|
[197] | 24 | } |
---|
| 25 | |
---|
[239] | 26 | void Identifier::initialize(const IdentifierList* parents) |
---|
[197] | 27 | { |
---|
[231] | 28 | #if HIERARCHY_VERBOSE |
---|
[197] | 29 | std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; |
---|
[231] | 30 | #endif |
---|
[197] | 31 | if (parents) |
---|
| 32 | { |
---|
| 33 | this->bCreatedOneObject_ = true; |
---|
| 34 | |
---|
| 35 | IdentifierListElement* temp1; |
---|
| 36 | IdentifierListElement* temp2; |
---|
| 37 | IdentifierListElement* temp3; |
---|
| 38 | |
---|
| 39 | temp1 = parents->first_; |
---|
| 40 | while (temp1) |
---|
| 41 | { |
---|
[241] | 42 | temp2 = temp1->identifier_->directParents_.first_; |
---|
[197] | 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 | { |
---|
[241] | 64 | this->directParents_.add(temp1->identifier_); |
---|
| 65 | temp1->identifier_->getDirectChildren().add(this); |
---|
[197] | 66 | } |
---|
| 67 | |
---|
[241] | 68 | this->allParents_.add(temp1->identifier_); |
---|
| 69 | temp1->identifier_->getAllChildren().add(this); |
---|
[197] | 70 | |
---|
| 71 | temp1 = temp1->next_; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[239] | 76 | bool Identifier::isA(const Identifier* identifier) const |
---|
[197] | 77 | { |
---|
[241] | 78 | return (identifier == this || this->allParents_.isInList(identifier)); |
---|
[197] | 79 | } |
---|
| 80 | |
---|
[239] | 81 | bool Identifier::isDirectlyA(const Identifier* identifier) const |
---|
[197] | 82 | { |
---|
| 83 | return (identifier == this); |
---|
| 84 | } |
---|
| 85 | |
---|
[239] | 86 | bool Identifier::isChildOf(const Identifier* identifier) const |
---|
[197] | 87 | { |
---|
[241] | 88 | return this->allParents_.isInList(identifier); |
---|
[197] | 89 | } |
---|
| 90 | |
---|
[239] | 91 | bool Identifier::isDirectChildOf(const Identifier* identifier) const |
---|
[197] | 92 | { |
---|
[241] | 93 | return this->directParents_.isInList(identifier); |
---|
[197] | 94 | } |
---|
| 95 | |
---|
[239] | 96 | bool Identifier::isParentOf(const Identifier* identifier) const |
---|
[197] | 97 | { |
---|
[239] | 98 | return this->allChildren_->isInList(identifier); |
---|
[197] | 99 | } |
---|
| 100 | |
---|
[239] | 101 | bool Identifier::isDirectParentOf(const Identifier* identifier) const |
---|
[197] | 102 | { |
---|
[239] | 103 | return this->directChildren_->isInList(identifier); |
---|
[197] | 104 | } |
---|
| 105 | } |
---|