1 | #include "ClassHierarchy.h" |
---|
2 | |
---|
3 | namespace orxonox |
---|
4 | { |
---|
5 | // ############################### |
---|
6 | // ### Identifier ### |
---|
7 | // ############################### |
---|
8 | // Identifier* Identifier::pointer_ = NULL; |
---|
9 | /* |
---|
10 | Identifier* Identifier::registerClass(IdentifierList* parents) |
---|
11 | { |
---|
12 | if (!pointer_) |
---|
13 | { |
---|
14 | pointer_ = new Identifier(); |
---|
15 | pointer_->initialize(parents); |
---|
16 | } |
---|
17 | |
---|
18 | return pointer_; |
---|
19 | } |
---|
20 | */ |
---|
21 | Identifier::Identifier() |
---|
22 | { |
---|
23 | this->bCreatedOneObject_ = false; |
---|
24 | this->directParents_ = new IdentifierList(); |
---|
25 | this->allParents_ = new IdentifierList(); |
---|
26 | this->directChildren_ = new IdentifierList(); |
---|
27 | this->allChildren_ = new IdentifierList(); |
---|
28 | this->objects_ = new ObjectList(); |
---|
29 | } |
---|
30 | |
---|
31 | void Identifier::initialize(IdentifierList* parents) |
---|
32 | { |
---|
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(BaseObject* object) |
---|
79 | { |
---|
80 | this->objects_->add(object); |
---|
81 | } |
---|
82 | |
---|
83 | void Identifier::removeObject(BaseObject* object) |
---|
84 | { |
---|
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::isDirectA(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 | |
---|
118 | |
---|
119 | // ############################### |
---|
120 | // ### IdentifierList ### |
---|
121 | // ############################### |
---|
122 | IdentifierList::IdentifierList() |
---|
123 | { |
---|
124 | this->first_ = NULL; |
---|
125 | } |
---|
126 | |
---|
127 | IdentifierList::~IdentifierList() |
---|
128 | { |
---|
129 | IdentifierListElement* temp; |
---|
130 | while (this->first_) |
---|
131 | { |
---|
132 | temp = this->first_->next_; |
---|
133 | delete this->first_; |
---|
134 | this->first_ = temp; |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | void IdentifierList::add(Identifier* identifier) |
---|
139 | { |
---|
140 | IdentifierListElement* temp = this->first_; |
---|
141 | this->first_ = new IdentifierListElement(identifier); |
---|
142 | this->first_->next_ = temp; |
---|
143 | } |
---|
144 | |
---|
145 | void IdentifierList::remove(Identifier* identifier) |
---|
146 | { |
---|
147 | if (!identifier) |
---|
148 | return; |
---|
149 | |
---|
150 | if (this->first_->identifier_ == identifier) |
---|
151 | { |
---|
152 | IdentifierListElement* temp = this->first_->next_; |
---|
153 | delete this->first_; |
---|
154 | this->first_ = temp; |
---|
155 | |
---|
156 | return; |
---|
157 | } |
---|
158 | |
---|
159 | IdentifierListElement* temp = this->first_; |
---|
160 | while (temp->next_) |
---|
161 | { |
---|
162 | if (temp->next_->identifier_ == identifier) |
---|
163 | { |
---|
164 | IdentifierListElement* temp2 = temp->next_->next_; |
---|
165 | delete temp->next_; |
---|
166 | temp->next_ = temp2; |
---|
167 | |
---|
168 | return; |
---|
169 | } |
---|
170 | |
---|
171 | temp = temp->next_; |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | bool IdentifierList::isInList(Identifier* identifier) |
---|
176 | { |
---|
177 | IdentifierListElement* temp = this->first_; |
---|
178 | while (temp) |
---|
179 | { |
---|
180 | if (temp->identifier_ == identifier) |
---|
181 | return true; |
---|
182 | |
---|
183 | temp = temp->next_; |
---|
184 | } |
---|
185 | |
---|
186 | return false; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | // ############################### |
---|
191 | // ### IdentifierListElement ### |
---|
192 | // ############################### |
---|
193 | IdentifierListElement::IdentifierListElement(Identifier* identifier) |
---|
194 | { |
---|
195 | this->identifier_ = identifier; |
---|
196 | this->next_ = NULL; |
---|
197 | this->bDirect_ = true; |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | // ############################### |
---|
202 | // ### ObjectList ### |
---|
203 | // ############################### |
---|
204 | ObjectList::ObjectList() |
---|
205 | { |
---|
206 | this->first_ = NULL; |
---|
207 | } |
---|
208 | |
---|
209 | ObjectList::~ObjectList() |
---|
210 | { |
---|
211 | ObjectListElement* temp; |
---|
212 | while (this->first_) |
---|
213 | { |
---|
214 | temp = this->first_->next_; |
---|
215 | delete this->first_; |
---|
216 | this->first_ = temp; |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | void ObjectList::add(BaseObject* object) |
---|
221 | { |
---|
222 | ObjectListElement* temp = this->first_; |
---|
223 | this->first_ = new ObjectListElement(object); |
---|
224 | this->first_->next_ = temp; |
---|
225 | } |
---|
226 | |
---|
227 | void ObjectList::remove(BaseObject* object) |
---|
228 | { |
---|
229 | if (!object) |
---|
230 | return; |
---|
231 | |
---|
232 | if (this->first_->object_ == object) |
---|
233 | { |
---|
234 | ObjectListElement* temp = this->first_->next_; |
---|
235 | delete this->first_; |
---|
236 | this->first_ = temp; |
---|
237 | |
---|
238 | return; |
---|
239 | } |
---|
240 | |
---|
241 | ObjectListElement* temp = this->first_; |
---|
242 | while (temp->next_) |
---|
243 | { |
---|
244 | if (temp->next_->object_ == object) |
---|
245 | { |
---|
246 | ObjectListElement* temp2 = temp->next_->next_; |
---|
247 | delete temp->next_; |
---|
248 | temp->next_ = temp2; |
---|
249 | |
---|
250 | return; |
---|
251 | } |
---|
252 | |
---|
253 | temp = temp->next_; |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | // ############################### |
---|
259 | // ### ObjectListElement ### |
---|
260 | // ############################### |
---|
261 | ObjectListElement::ObjectListElement(BaseObject* object) |
---|
262 | { |
---|
263 | this->object_ = object; |
---|
264 | this->next_ = NULL; |
---|
265 | } |
---|
266 | } |
---|