Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

it starts to work, but there is still much to do.

@bensch: thanks for you mail, but i can't tell you much at the moment - i'm still changing lots of things and i have no idea if everything will work as intendet, so i'll write you as soon as i have reliable informations :)
</abuse log for pms>

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