Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added some "const" qualifiers to the identifier-functions

File size: 3.0 KB
RevLine 
[197]1#include "Identifier.h"
2
3namespace orxonox
4{
5    // ###############################
6    // ###       Identifier        ###
7    // ###############################
[219]8    int Identifier::hierarchyCreatingCounter_s = 0;
9
[197]10    Identifier::Identifier()
11    {
12        this->bCreatedOneObject_ = false;
[239]13
14        this->directChildren_ = new IdentifierList;
15        this->allChildren_ = new IdentifierList;
16        this->directParents_ = new IdentifierList;
17        this->allParents_ = new IdentifierList;
[197]18    }
19
20    Identifier::~Identifier()
21    {
22        delete &this->name_;
[239]23
24        delete this->directChildren_;
25        delete this->allChildren_;
26        delete this->directParents_;
27        delete this->allParents_;
[197]28    }
29
[239]30    void Identifier::initialize(const IdentifierList* parents)
[197]31    {
[231]32#if HIERARCHY_VERBOSE
[197]33        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
[231]34#endif
[197]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            {
[239]46                temp2 = temp1->identifier_->directParents_->first_;
[197]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                {
[239]68                    this->directParents_->add(temp1->identifier_);
69                    temp1->identifier_->directChildren_->add(this);
[197]70                }
71
[239]72                this->allParents_->add(temp1->identifier_);
73                temp1->identifier_->allChildren_->add(this);
[197]74
75                temp1 = temp1->next_;
76            }
77        }
78    }
79
[239]80    bool Identifier::isA(const Identifier* identifier) const
[197]81    {
[239]82        return (identifier == this || this->allParents_->isInList(identifier));
[197]83    }
84
[239]85    bool Identifier::isDirectlyA(const Identifier* identifier) const
[197]86    {
87        return (identifier == this);
88    }
89
[239]90    bool Identifier::isChildOf(const Identifier* identifier) const
[197]91    {
[239]92        return this->allParents_->isInList(identifier);
[197]93    }
94
[239]95    bool Identifier::isDirectChildOf(const Identifier* identifier) const
[197]96    {
[239]97        return this->directParents_->isInList(identifier);
[197]98    }
99
[239]100    bool Identifier::isParentOf(const Identifier* identifier) const
[197]101    {
[239]102        return this->allChildren_->isInList(identifier);
[197]103    }
104
[239]105    bool Identifier::isDirectParentOf(const Identifier* identifier) const
[197]106    {
[239]107        return this->directChildren_->isInList(identifier);
[197]108    }
109}
Note: See TracBrowser for help on using the repository browser.