| [270] | 1 | #include "Identifier.h" |
|---|
| 2 | |
|---|
| 3 | namespace orxonox |
|---|
| 4 | { |
|---|
| 5 | // ############################### |
|---|
| 6 | // ### Identifier ### |
|---|
| 7 | // ############################### |
|---|
| 8 | Identifier::Identifier() |
|---|
| 9 | { |
|---|
| 10 | this->bCreatedOneObject_ = false; |
|---|
| 11 | this->directParents_ = new IdentifierList(); |
|---|
| 12 | this->allParents_ = new IdentifierList(); |
|---|
| 13 | this->directChildren_ = new IdentifierList(); |
|---|
| 14 | this->allChildren_ = new IdentifierList(); |
|---|
| 15 | this->objects_ = new ObjectList(); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | Identifier::~Identifier() |
|---|
| 19 | { |
|---|
| 20 | delete this->directParents_; |
|---|
| 21 | delete this->allParents_; |
|---|
| 22 | delete this->directChildren_; |
|---|
| 23 | delete this->allChildren_; |
|---|
| 24 | delete this->objects_; |
|---|
| 25 | delete &this->name_; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | void Identifier::initialize(IdentifierList* parents) |
|---|
| 29 | { |
|---|
| 30 | std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; |
|---|
| 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 | { |
|---|
| 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_->directChildren_->add(this); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | this->allParents_->add(temp1->identifier_); |
|---|
| 69 | temp1->identifier_->allChildren_->add(this); |
|---|
| 70 | |
|---|
| 71 | temp1 = temp1->next_; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | void Identifier::addObject(OrxonoxClass* object) |
|---|
| 77 | { |
|---|
| 78 | std::cout << "*** Added " << this->name_ << " to list.\n"; |
|---|
| 79 | this->objects_->add(object); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void Identifier::removeObject(OrxonoxClass* object) |
|---|
| 83 | { |
|---|
| 84 | std::cout << "*** Removed " << this->name_ << " from list.\n"; |
|---|
| 85 | this->objects_->remove(object); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | bool Identifier::isA(Identifier* identifier) |
|---|
| 89 | { |
|---|
| 90 | return (identifier == this || this->allParents_->isInList(identifier)); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | bool Identifier::isDirectlyA(Identifier* identifier) |
|---|
| 94 | { |
|---|
| 95 | return (identifier == this); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | bool Identifier::isChildOf(Identifier* identifier) |
|---|
| 99 | { |
|---|
| 100 | return this->allParents_->isInList(identifier); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | bool Identifier::isDirectChildOf(Identifier* identifier) |
|---|
| 104 | { |
|---|
| 105 | return this->directParents_->isInList(identifier); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | bool Identifier::isParentOf(Identifier* identifier) |
|---|
| 109 | { |
|---|
| 110 | return this->allChildren_->isInList(identifier); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | bool Identifier::isDirectParentOf(Identifier* identifier) |
|---|
| 114 | { |
|---|
| 115 | return this->directChildren_->isInList(identifier); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|