Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/core/Identifier.cc @ 362

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

added NetworkID

File size: 2.2 KB
Line 
1#include "Identifier.h"
2
3namespace orxonox
4{
5    // ###############################
6    // ###       Identifier        ###
7    // ###############################
8    int Identifier::hierarchyCreatingCounter_s = 0;
9    unsigned int Identifier::classIDcounter_s = 0;
10
11    Identifier::Identifier()
12    {
13        this->bCreatedOneObject_ = false;
14        this->factory_ = 0;
15
16        this->children_ = new IdentifierList;
17        this->classID_ = Identifier::classIDcounter_s++;
18    }
19
20    Identifier::~Identifier()
21    {
22        delete &this->name_;
23
24        delete this->children_;
25    }
26
27    void Identifier::initialize(const IdentifierList* parents)
28    {
29#if HIERARCHY_VERBOSE
30        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
31#endif
32        this->bCreatedOneObject_ = true;
33
34        if (parents)
35        {
36            IdentifierListElement* temp1 = parents->first_;
37            while (temp1)
38            {
39                this->parents_.add(temp1->identifier_);
40                temp1->identifier_->getChildren().add(this);
41
42                temp1 = temp1->next_;
43            }
44        }
45    }
46
47    BaseObject* Identifier::fabricate()
48    {
49        if (this->factory_)
50        {
51            return this->factory_->fabricate();
52        }
53        else
54        {
55            std::cout << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n";
56            std::cout << "Aborting...";
57            abort();
58        }
59    }
60
61    void Identifier::setNetworkID(unsigned int id)
62    {
63        Factory::changeNetworkID(this, this->classID_, id);
64        this->classID_ = id;
65    }
66
67    bool Identifier::isA(const Identifier* identifier) const
68    {
69        return (identifier == this || this->parents_.isInList(identifier));
70    }
71
72    bool Identifier::isDirectlyA(const Identifier* identifier) const
73    {
74        return (identifier == this);
75    }
76
77    bool Identifier::isChildOf(const Identifier* identifier) const
78    {
79        return this->parents_.isInList(identifier);
80    }
81
82    bool Identifier::isParentOf(const Identifier* identifier) const
83    {
84        return this->children_->isInList(identifier);
85    }
86}
Note: See TracBrowser for help on using the repository browser.