1 | #include "Identifier.h" |
---|
2 | |
---|
3 | namespace orxonox |
---|
4 | { |
---|
5 | // ############################### |
---|
6 | // ### Identifier ### |
---|
7 | // ############################### |
---|
8 | int Identifier::hierarchyCreatingCounter_s = 0; |
---|
9 | |
---|
10 | Identifier::Identifier() |
---|
11 | { |
---|
12 | this->bCreatedOneObject_ = false; |
---|
13 | |
---|
14 | this->directChildren_ = new IdentifierList; |
---|
15 | this->allChildren_ = new IdentifierList; |
---|
16 | } |
---|
17 | |
---|
18 | Identifier::~Identifier() |
---|
19 | { |
---|
20 | delete &this->name_; |
---|
21 | |
---|
22 | delete this->directChildren_; |
---|
23 | delete this->allChildren_; |
---|
24 | } |
---|
25 | |
---|
26 | void Identifier::initialize(const IdentifierList* parents) |
---|
27 | { |
---|
28 | #if HIERARCHY_VERBOSE |
---|
29 | std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; |
---|
30 | #endif |
---|
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_->getDirectChildren().add(this); |
---|
66 | } |
---|
67 | |
---|
68 | this->allParents_.add(temp1->identifier_); |
---|
69 | temp1->identifier_->getAllChildren().add(this); |
---|
70 | |
---|
71 | temp1 = temp1->next_; |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | bool Identifier::isA(const Identifier* identifier) const |
---|
77 | { |
---|
78 | return (identifier == this || this->allParents_.isInList(identifier)); |
---|
79 | } |
---|
80 | |
---|
81 | bool Identifier::isDirectlyA(const Identifier* identifier) const |
---|
82 | { |
---|
83 | return (identifier == this); |
---|
84 | } |
---|
85 | |
---|
86 | bool Identifier::isChildOf(const Identifier* identifier) const |
---|
87 | { |
---|
88 | return this->allParents_.isInList(identifier); |
---|
89 | } |
---|
90 | |
---|
91 | bool Identifier::isDirectChildOf(const Identifier* identifier) const |
---|
92 | { |
---|
93 | return this->directParents_.isInList(identifier); |
---|
94 | } |
---|
95 | |
---|
96 | bool Identifier::isParentOf(const Identifier* identifier) const |
---|
97 | { |
---|
98 | return this->allChildren_->isInList(identifier); |
---|
99 | } |
---|
100 | |
---|
101 | bool Identifier::isDirectParentOf(const Identifier* identifier) const |
---|
102 | { |
---|
103 | return this->directChildren_->isInList(identifier); |
---|
104 | } |
---|
105 | } |
---|