Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 221 was 221, checked in by landauf, 16 years ago
  • made ObjectList double-linked to allow forward- and backward-iterating. its now a LI(F/L)O list.
  • added an iterator to iterate through object-lists. you can iterate forwards and backwards.

iterating forwards is easy: you get "0 1 2 … last"
iterating backwards is a bit tricky: you still get "0" first, but then "last … 2 1".
thats caused by the structure of the for-loop: you get the first element before the iterator knows if you'll increase or decrease it

File size: 3.8 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//        this->directParents_ = new IdentifierList();
14//        this->allParents_ = new IdentifierList();
15//        this->directChildren_ = new IdentifierList();
16//        this->allChildren_ = new IdentifierList();
17//        this->objects_ = new ObjectList();
18    }
19
20    Identifier::~Identifier()
21    {
22//        delete this->directParents_;
23//        delete this->allParents_;
24//        delete this->directChildren_;
25//        delete this->allChildren_;
26//        delete this->objects_;
27        delete &this->name_;
28    }
29
30    void Identifier::initialize(IdentifierList* parents)
31    {
32        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
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(OrxonoxClass* object)
79    {
80        std::cout << "*** Added object to " << this->name_ << "-list.\n";
81        this->objects_.add(object);
82    }
83
84    void Identifier::removeObject(OrxonoxClass* object)
85    {
86        bool bIterateForwards = !Identifier::isCreatingHierarchy();
87
88        if (bIterateForwards)
89            std::cout << "*** Removed object from " << this->name_ << "-list, iterating forwards.\n";
90        else
91            std::cout << "*** Removed object from " << this->name_ << "-list, iterating backwards.\n";
92
93        this->objects_.remove(object, bIterateForwards);
94
95        IdentifierListElement* temp = this->directParents_.first_;
96        while (temp)
97        {
98            temp->identifier_->removeObject(object);
99            temp = temp->next_;
100        }
101    }
102
103    bool Identifier::isA(Identifier* identifier)
104    {
105        return (identifier == this || this->allParents_.isInList(identifier));
106    }
107
108    bool Identifier::isDirectlyA(Identifier* identifier)
109    {
110        return (identifier == this);
111    }
112
113    bool Identifier::isChildOf(Identifier* identifier)
114    {
115        return this->allParents_.isInList(identifier);
116    }
117
118    bool Identifier::isDirectChildOf(Identifier* identifier)
119    {
120        return this->directParents_.isInList(identifier);
121    }
122
123    bool Identifier::isParentOf(Identifier* identifier)
124    {
125        return this->allChildren_.isInList(identifier);
126    }
127
128    bool Identifier::isDirectParentOf(Identifier* identifier)
129    {
130        return this->directChildren_.isInList(identifier);
131    }
132}
Note: See TracBrowser for help on using the repository browser.