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 | // this->directParents_ = new IdentifierList(); |
---|
14 | // this->allParents_ = new IdentifierList(); |
---|
15 | // this->directChildren_ = new IdentifierList(); |
---|
16 | // this->allChildren_ = new IdentifierList(); |
---|
17 | // this->objects_ = new ObjectList(); |
---|
18 | } |
---|
19 | |
---|
20 | Identifier::~Identifier() |
---|
21 | { |
---|
22 | // delete this->directParents_; |
---|
23 | // delete this->allParents_; |
---|
24 | // delete this->directChildren_; |
---|
25 | // delete this->allChildren_; |
---|
26 | // delete this->objects_; |
---|
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 | { |
---|
44 | temp2 = temp1->identifier_->directParents_.first_; |
---|
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 | { |
---|
66 | this->directParents_.add(temp1->identifier_); |
---|
67 | temp1->identifier_->directChildren_.add(this); |
---|
68 | } |
---|
69 | |
---|
70 | this->allParents_.add(temp1->identifier_); |
---|
71 | temp1->identifier_->allChildren_.add(this); |
---|
72 | |
---|
73 | temp1 = temp1->next_; |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | void Identifier::addObject(OrxonoxClass* object) |
---|
79 | { |
---|
80 | std::cout << "*** Added object to " << this->name_ << "-list.\n"; |
---|
81 | this->objects_.add(object); |
---|
82 | } |
---|
83 | |
---|
84 | void Identifier::removeObject(OrxonoxClass* object) |
---|
85 | { |
---|
86 | std::cout << "*** Removed object from " << this->name_ << "-list.\n"; |
---|
87 | this->objects_.remove(object); |
---|
88 | |
---|
89 | IdentifierListElement* temp = this->directParents_.first_; |
---|
90 | while (temp) |
---|
91 | { |
---|
92 | temp->identifier_->removeObject(object); |
---|
93 | temp = temp->next_; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | bool Identifier::isA(Identifier* identifier) |
---|
98 | { |
---|
99 | return (identifier == this || this->allParents_.isInList(identifier)); |
---|
100 | } |
---|
101 | |
---|
102 | bool Identifier::isDirectlyA(Identifier* identifier) |
---|
103 | { |
---|
104 | return (identifier == this); |
---|
105 | } |
---|
106 | |
---|
107 | bool Identifier::isChildOf(Identifier* identifier) |
---|
108 | { |
---|
109 | return this->allParents_.isInList(identifier); |
---|
110 | } |
---|
111 | |
---|
112 | bool Identifier::isDirectChildOf(Identifier* identifier) |
---|
113 | { |
---|
114 | return this->directParents_.isInList(identifier); |
---|
115 | } |
---|
116 | |
---|
117 | bool Identifier::isParentOf(Identifier* identifier) |
---|
118 | { |
---|
119 | return this->allChildren_.isInList(identifier); |
---|
120 | } |
---|
121 | |
---|
122 | bool Identifier::isDirectParentOf(Identifier* identifier) |
---|
123 | { |
---|
124 | return this->directChildren_.isInList(identifier); |
---|
125 | } |
---|
126 | } |
---|