Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchie/src/ClassHierarchy.cc @ 172

Last change on this file since 172 was 172, checked in by landauf, 16 years ago

some features work perfectly,
some features are fucked up,
some features arent yet implemented.

x3n→hair→brightness++;

theres still a lot to do, but i can see the light on the end of the tunnel.
templates, makros, operator overloading, function pointers… the beauty of the beast. i'm in love and still dying piece by piece with every line of code i'm writing.
</film noir>

File size: 8.2 KB
Line 
1#include "ClassHierarchy.h"
2#include "OrxonoxClass.h"
3
4namespace orxonox
5{
6    // ###############################
7    // ###       Identifier        ###
8    // ###############################
9//    Identifier* Identifier::pointer_ = NULL;
10/*
11    Identifier* Identifier::registerClass(IdentifierList* parents)
12    {
13        if (!pointer_)
14        {
15            pointer_ = new Identifier();
16            pointer_->initialize(parents);
17        }
18
19        return pointer_;
20    }
21*/
22    Identifier::Identifier()
23    {
24        this->bCreatedOneObject_ = false;
25        this->directParents_ = new IdentifierList();
26        this->allParents_ = new IdentifierList();
27        this->directChildren_ = new IdentifierList();
28        this->allChildren_ = new IdentifierList();
29        this->objects_ = new ObjectList();
30    }
31
32    Identifier::~Identifier()
33    {
34        delete this->directParents_;
35        delete this->allParents_;
36        delete this->directChildren_;
37        delete this->allChildren_;
38        delete this->objects_;
39        delete &this->name_;
40    }
41
42    void Identifier::initialize(IdentifierList* parents)
43    {
44        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
45        if (parents)
46        {
47            this->bCreatedOneObject_ = true;
48
49            IdentifierListElement* temp1;
50            IdentifierListElement* temp2;
51            IdentifierListElement* temp3;
52
53            temp1 = parents->first_;
54            while (temp1)
55            {
56                temp2 = temp1->identifier_->directParents_->first_;
57                while (temp2)
58                {
59                    temp3 = parents->first_;
60                    while(temp3)
61                    {
62                        if (temp3->identifier_ == temp2->identifier_)
63                            temp3->bDirect_ = false;
64
65                        temp3 = temp3->next_;
66                    }
67
68                    temp2 = temp2->next_;
69                }
70                temp1 = temp1->next_;
71            }
72
73            temp1 = parents->first_;
74            while (temp1)
75            {
76                if (temp1->bDirect_)
77                {
78                    this->directParents_->add(temp1->identifier_);
79                    temp1->identifier_->directChildren_->add(this);
80                }
81
82                this->allParents_->add(temp1->identifier_);
83                temp1->identifier_->allChildren_->add(this);
84
85                temp1 = temp1->next_;
86            }
87        }
88    }
89
90    void Identifier::addObject(OrxonoxClass* object)
91    {
92        std::cout << "*** Added " << this->name_ << " to list.\n";
93        this->objects_->add(object);
94    }
95
96    void Identifier::removeObject(OrxonoxClass* object)
97    {
98        std::cout << "*** Removed " << this->name_ << " from list.\n";
99        this->objects_->remove(object);
100    }
101
102    bool Identifier::isA(Identifier* identifier)
103    {
104        return (identifier == this || this->allParents_->isInList(identifier));
105    }
106
107    bool Identifier::isDirectlyA(Identifier* identifier)
108    {
109        return (identifier == this);
110    }
111
112    bool Identifier::isChildOf(Identifier* identifier)
113    {
114        return this->allParents_->isInList(identifier);
115    }
116
117    bool Identifier::isDirectChildOf(Identifier* identifier)
118    {
119        return this->directParents_->isInList(identifier);
120    }
121
122    bool Identifier::isParentOf(Identifier* identifier)
123    {
124        return this->allChildren_->isInList(identifier);
125    }
126
127    bool Identifier::isDirectParentOf(Identifier* identifier)
128    {
129        return this->directChildren_->isInList(identifier);
130    }
131
132
133    // ###############################
134    // ###     IdentifierList      ###
135    // ###############################
136    IdentifierList::IdentifierList()
137    {
138        this->first_ = NULL;
139    }
140
141    IdentifierList::~IdentifierList()
142    {
143        IdentifierListElement* temp;
144        while (this->first_)
145        {
146            temp = this->first_->next_;
147            delete this->first_;
148            this->first_ = temp;
149        }
150    }
151
152    void IdentifierList::add(Identifier* identifier)
153    {
154        IdentifierListElement* temp = this->first_;
155        this->first_ = new IdentifierListElement(identifier);
156        this->first_->next_ = temp;
157    }
158
159    void IdentifierList::remove(Identifier* identifier)
160    {
161        if (!identifier)
162            return;
163
164        if (this->first_->identifier_ == identifier)
165        {
166            IdentifierListElement* temp = this->first_->next_;
167            delete this->first_;
168            this->first_ = temp;
169
170            return;
171        }
172
173        IdentifierListElement* temp = this->first_;
174        while (temp->next_)
175        {
176            if (temp->next_->identifier_ == identifier)
177            {
178                IdentifierListElement* temp2 = temp->next_->next_;
179                delete temp->next_;
180                temp->next_ = temp2;
181
182                return;
183            }
184
185            temp = temp->next_;
186        }
187    }
188
189    bool IdentifierList::isInList(Identifier* identifier)
190    {
191        IdentifierListElement* temp = this->first_;
192        while (temp)
193        {
194            if (temp->identifier_ == identifier)
195                return true;
196
197            temp = temp->next_;
198        }
199
200        return false;
201    }
202
203    std::string IdentifierList::toString()
204    {
205        IdentifierListElement* temp = this->first_;
206        std::string output = "";
207
208        while (temp)
209        {
210            output += temp->identifier_->getName();
211            output += " ";
212
213            temp = temp->next_;
214        }
215
216        return output;
217    }
218
219
220    // ###############################
221    // ###  IdentifierListElement  ###
222    // ###############################
223    IdentifierListElement::IdentifierListElement(Identifier* identifier)
224    {
225        this->identifier_ = identifier;
226        this->next_ = NULL;
227        this->bDirect_ = true;
228    }
229
230    IdentifierListElement::~IdentifierListElement()
231    {
232    }
233
234
235    // ###############################
236    // ###       ObjectList        ###
237    // ###############################
238    ObjectList::ObjectList()
239    {
240        this->first_ = NULL;
241    }
242
243    ObjectList::~ObjectList()
244    {
245        ObjectListElement* temp;
246        while (this->first_)
247        {
248            temp = this->first_->next_;
249            delete this->first_;
250            this->first_ = temp;
251        }
252    }
253
254    void ObjectList::add(OrxonoxClass* object)
255    {
256        ObjectListElement* temp = this->first_;
257        this->first_ = new ObjectListElement(object);
258        this->first_->next_ = temp;
259    }
260
261    void ObjectList::remove(OrxonoxClass* object)
262    {
263        if (!object)
264            return;
265
266        if (this->first_->object_ == object)
267        {
268            ObjectListElement* temp = this->first_->next_;
269            delete this->first_;
270            this->first_ = temp;
271
272            return;
273        }
274
275        ObjectListElement* temp = this->first_;
276        while (temp->next_)
277        {
278            if (temp->next_->object_ == object)
279            {
280                ObjectListElement* temp2 = temp->next_->next_;
281                delete temp->next_;
282                temp->next_ = temp2;
283
284                return;
285            }
286
287            temp = temp->next_;
288        }
289    }
290
291
292    // ###############################
293    // ###    ObjectListElement    ###
294    // ###############################
295    ObjectListElement::ObjectListElement(OrxonoxClass* object)
296    {
297        this->object_ = object;
298        this->next_ = NULL;
299    }
300
301    ObjectListElement::~ObjectListElement()
302    {
303    }
304
305
306    // ###############################
307    // ###     ClassHierarchy      ###
308    // ###############################
309    ClassHierarchy* ClassHierarchy::pointer_ = NULL;
310
311    ClassHierarchy* ClassHierarchy::getSingleton()
312    {
313        if (!pointer_)
314            pointer_ = new ClassHierarchy();
315
316        return pointer_;
317    }
318
319    ClassHierarchy::ClassHierarchy()
320    {
321        this->hierarchyCreatingCounter_ = 0;
322    }
323
324    ClassHierarchy::~ClassHierarchy()
325    {
326      this->pointer_ = NULL;
327    }
328}
Note: See TracBrowser for help on using the repository browser.