Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 541 was 453, checked in by landauf, 17 years ago

added benschs Debug.h from orxonox_v1

include Debug.h or CoreIncludes.h and use it in the following way:
COUT(int) << bla;
PRINT(int)(bla);
PRINTF(int)(bla);

where 'bla' is the same as if you would use the normal std::cout or printf function
and 'int' is a value between 0 and 5:
0 = no debug output
1 = errors
2 = warnings
3 = info
4 = debug
5 = more debug

so to print a warning, use int = 2
for some unimportant debug information, use int = 4
and so on…

the level of the output is configured in the Debug.h file (later i'll add an entry to the config-file for the soft-level).

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        COUT(4) << "*** Initialize " << this->name_ << "-Singleton.\n";
44        this->bCreatedOneObject_ = true;
45
46        if (parents)
47        {
48            IdentifierListElement* temp1 = parents->first_;
49            while (temp1)
50            {
51                this->parents_.add(temp1->identifier_);
52                temp1->identifier_->getChildren().add(this); // We're a child of our parents
53
54                temp1 = temp1->next_;
55            }
56        }
57    }
58
59    /**
60        @brief Creates an object of the type the Identifier belongs to.
61        @return The new object
62    */
63    BaseObject* Identifier::fabricate()
64    {
65        if (this->factory_)
66        {
67            return this->factory_->fabricate(); // We have to return a BaseObject, because we don't know the exact type.
68        }
69        else
70        {
71            // Abstract classes don't have a factory and therefore can't create new objects
72            COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n";
73            COUT(1) << "Aborting...";
74            abort();
75        }
76    }
77
78    /**
79        @brief Sets the network ID to a new value and changes the entry in the Factory.
80        @param id The new network ID
81    */
82    void Identifier::setNetworkID(unsigned int id)
83    {
84        Factory::changeNetworkID(this, this->classID_, id);
85        this->classID_ = id;
86    }
87
88    /**
89        @returns true, if the Identifier is at least of the given type.
90        @param identifier The identifier to compare with
91    */
92    bool Identifier::isA(const Identifier* identifier) const
93    {
94        return (identifier == this || this->parents_.isInList(identifier));
95    }
96
97    /**
98        @returns true, if the Identifier is exactly of the given type.
99        @param identifier The identifier to compare with
100    */
101    bool Identifier::isDirectlyA(const Identifier* identifier) const
102    {
103        return (identifier == this);
104    }
105
106    /**
107        @returns true, if the assigned identifier is a child of the given identifier.
108        @param identifier The identifier to compare with
109    */
110    bool Identifier::isChildOf(const Identifier* identifier) const
111    {
112        return this->parents_.isInList(identifier);
113    }
114
115    /**
116        @returns true, if the assigned identifier is a parent of the given identifier.
117        @param identifier The identifier to compare with
118    */
119    bool Identifier::isParentOf(const Identifier* identifier) const
120    {
121        return this->children_->isInList(identifier);
122    }
123}
Note: See TracBrowser for help on using the repository browser.