Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added comments

File size: 3.9 KB
Line 
1/*!
2    @file Identifier.cc
3    @brief Implementation of the Identifier class.
4*/
5
6#include "Identifier.h"
7
8namespace orxonox
9{
10    // ###############################
11    // ###       Identifier        ###
12    // ###############################
13    int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero
14    unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero
15
16    /**
17        @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
18    */
19    Identifier::Identifier()
20    {
21        this->bCreatedOneObject_ = false;
22        this->factory_ = 0;
23
24        this->children_ = new IdentifierList;
25        this->classID_ = Identifier::classIDcounter_s++;
26    }
27
28    /**
29        @brief Destructor: Deletes the name and the IdentifierList containing the children.
30    */
31    Identifier::~Identifier()
32    {
33        delete &this->name_;
34        delete this->children_;
35    }
36
37    /**
38        @brief Initializes the Identifier with an IdentifierList containing all parents of the class the Identifier belongs to.
39        @param parents The IdentifierList containing all parents
40    */
41    void Identifier::initialize(const IdentifierList* parents)
42    {
43#if HIERARCHY_VERBOSE
44        std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
45#endif
46        this->bCreatedOneObject_ = true;
47
48        if (parents)
49        {
50            IdentifierListElement* temp1 = parents->first_;
51            while (temp1)
52            {
53                this->parents_.add(temp1->identifier_);
54                temp1->identifier_->getChildren().add(this); // We're a child of our parents
55
56                temp1 = temp1->next_;
57            }
58        }
59    }
60
61    /**
62        @brief Creates an object of the type the Identifier belongs to.
63        @return The new object
64    */
65    BaseObject* Identifier::fabricate()
66    {
67        if (this->factory_)
68        {
69            return this->factory_->fabricate(); // We have to return a BaseObject, because we don't know the exact type.
70        }
71        else
72        {
73            // Abstract classes don't have a factory and therefore can't create new objects
74            std::cout << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n";
75            std::cout << "Aborting...";
76            abort();
77        }
78    }
79
80    /**
81        @brief Sets the networkID to a new value and changes the entry in the Factory.
82        @param id The new networkID
83    */
84    void Identifier::setNetworkID(unsigned int id)
85    {
86        Factory::changeNetworkID(this, this->classID_, id);
87        this->classID_ = id;
88    }
89
90    /**
91        @returns true, if the Identifier is at least of the given type.
92        @param identifier The identifier to compare with
93    */
94    bool Identifier::isA(const Identifier* identifier) const
95    {
96        return (identifier == this || this->parents_.isInList(identifier));
97    }
98
99    /**
100        @returns true, if the Identifier is exactly of the given type.
101        @param identifier The identifier to compare with
102    */
103    bool Identifier::isDirectlyA(const Identifier* identifier) const
104    {
105        return (identifier == this);
106    }
107
108    /**
109        @returns true, if the assigned identifier is a child of the given identifier.
110        @param identifier The identifier to compare with
111    */
112    bool Identifier::isChildOf(const Identifier* identifier) const
113    {
114        return this->parents_.isInList(identifier);
115    }
116
117    /**
118        @returns true, if the assigned identifier is a parent of the given identifier.
119        @param identifier The identifier to compare with
120    */
121    bool Identifier::isParentOf(const Identifier* identifier) const
122    {
123        return this->children_->isInList(identifier);
124    }
125}
Note: See TracBrowser for help on using the repository browser.