Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchie/src/Identifier.cc @ 239

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

added some "const" qualifiers to the identifier-functions

File size: 3.0 KB
Line 
1#include "Identifier.h"
2
3namespace 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        this->directParents_ = new IdentifierList;
17        this->allParents_ = new IdentifierList;
18    }
19
20    Identifier::~Identifier()
21    {
22        delete &this->name_;
23
24        delete this->directChildren_;
25        delete this->allChildren_;
26        delete this->directParents_;
27        delete this->allParents_;
28    }
29
30    void Identifier::initialize(const IdentifierList* parents)
31    {
32#if HIERARCHY_VERBOSE
33        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
34#endif
35        if (parents)
36        {
37            this->bCreatedOneObject_ = true;
38
39            IdentifierListElement* temp1;
40            IdentifierListElement* temp2;
41            IdentifierListElement* temp3;
42
43            temp1 = parents->first_;
44            while (temp1)
45            {
46                temp2 = temp1->identifier_->directParents_->first_;
47                while (temp2)
48                {
49                    temp3 = parents->first_;
50                    while(temp3)
51                    {
52                        if (temp3->identifier_ == temp2->identifier_)
53                            temp3->bDirect_ = false;
54
55                        temp3 = temp3->next_;
56                    }
57
58                    temp2 = temp2->next_;
59                }
60                temp1 = temp1->next_;
61            }
62
63            temp1 = parents->first_;
64            while (temp1)
65            {
66                if (temp1->bDirect_)
67                {
68                    this->directParents_->add(temp1->identifier_);
69                    temp1->identifier_->directChildren_->add(this);
70                }
71
72                this->allParents_->add(temp1->identifier_);
73                temp1->identifier_->allChildren_->add(this);
74
75                temp1 = temp1->next_;
76            }
77        }
78    }
79
80    bool Identifier::isA(const Identifier* identifier) const
81    {
82        return (identifier == this || this->allParents_->isInList(identifier));
83    }
84
85    bool Identifier::isDirectlyA(const Identifier* identifier) const
86    {
87        return (identifier == this);
88    }
89
90    bool Identifier::isChildOf(const Identifier* identifier) const
91    {
92        return this->allParents_->isInList(identifier);
93    }
94
95    bool Identifier::isDirectChildOf(const Identifier* identifier) const
96    {
97        return this->directParents_->isInList(identifier);
98    }
99
100    bool Identifier::isParentOf(const Identifier* identifier) const
101    {
102        return this->allChildren_->isInList(identifier);
103    }
104
105    bool Identifier::isDirectParentOf(const Identifier* identifier) const
106    {
107        return this->directChildren_->isInList(identifier);
108    }
109}
Note: See TracBrowser for help on using the repository browser.