Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/Identifier.cc @ 668

Last change on this file since 668 was 668, checked in by rgrieder, 16 years ago
  • updated weapon system file names
  • some code style modifications in a few other files
  • removed some compiler warnings
File size: 4.8 KB
RevLine 
[513]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      ...
23 *   Co-authors:
24 *      ...
25 *
26 */
27
[384]28/*!
29    @file Identifier.cc
30    @brief Implementation of the Identifier class.
31*/
32
[197]33#include "Identifier.h"
34
35namespace orxonox
36{
37    // ###############################
38    // ###       Identifier        ###
39    // ###############################
[384]40    int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero
[496]41    unsigned int Identifier::classIDcounter_s = 0;  // Set the static member variable classIDcounter_s to zero
[219]42
[384]43    /**
44        @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
45    */
[197]46    Identifier::Identifier()
47    {
48        this->bCreatedOneObject_ = false;
[244]49        this->factory_ = 0;
[239]50
[243]51        this->children_ = new IdentifierList;
[363]52        this->classID_ = Identifier::classIDcounter_s++;
[197]53    }
54
[384]55    /**
56        @brief Destructor: Deletes the name and the IdentifierList containing the children.
57    */
[197]58    Identifier::~Identifier()
59    {
60        delete &this->name_;
[243]61        delete this->children_;
[197]62    }
63
[384]64    /**
65        @brief Initializes the Identifier with an IdentifierList containing all parents of the class the Identifier belongs to.
66        @param parents The IdentifierList containing all parents
67    */
[239]68    void Identifier::initialize(const IdentifierList* parents)
[197]69    {
[496]70        COUT(4) << "*** Initialize " << this->name_ << "-Singleton.\n";
[244]71        this->bCreatedOneObject_ = true;
72
[197]73        if (parents)
74        {
[243]75            IdentifierListElement* temp1 = parents->first_;
[197]76            while (temp1)
77            {
[243]78                this->parents_.add(temp1->identifier_);
[384]79                temp1->identifier_->getChildren().add(this); // We're a child of our parents
[197]80
81                temp1 = temp1->next_;
82            }
83        }
84    }
85
[384]86    /**
87        @brief Creates an object of the type the Identifier belongs to.
88        @return The new object
89    */
[244]90    BaseObject* Identifier::fabricate()
91    {
92        if (this->factory_)
93        {
[384]94            return this->factory_->fabricate(); // We have to return a BaseObject, because we don't know the exact type.
[244]95        }
96        else
97        {
[384]98            // Abstract classes don't have a factory and therefore can't create new objects
[496]99            COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n";
100            COUT(1) << "Aborting...";
[244]101            abort();
[668]102            return NULL;
[244]103        }
104    }
105
[384]106    /**
[496]107        @brief Sets the network ID to a new value and changes the entry in the Factory.
108        @param id The new network ID
[384]109    */
[363]110    void Identifier::setNetworkID(unsigned int id)
111    {
112        Factory::changeNetworkID(this, this->classID_, id);
113        this->classID_ = id;
114    }
115
[384]116    /**
117        @returns true, if the Identifier is at least of the given type.
118        @param identifier The identifier to compare with
119    */
[239]120    bool Identifier::isA(const Identifier* identifier) const
[197]121    {
[243]122        return (identifier == this || this->parents_.isInList(identifier));
[197]123    }
124
[384]125    /**
126        @returns true, if the Identifier is exactly of the given type.
127        @param identifier The identifier to compare with
128    */
[239]129    bool Identifier::isDirectlyA(const Identifier* identifier) const
[197]130    {
131        return (identifier == this);
132    }
133
[384]134    /**
135        @returns true, if the assigned identifier is a child of the given identifier.
136        @param identifier The identifier to compare with
137    */
[239]138    bool Identifier::isChildOf(const Identifier* identifier) const
[197]139    {
[243]140        return this->parents_.isInList(identifier);
[197]141    }
142
[384]143    /**
144        @returns true, if the assigned identifier is a parent of the given identifier.
145        @param identifier The identifier to compare with
146    */
[239]147    bool Identifier::isParentOf(const Identifier* identifier) const
[197]148    {
[243]149        return this->children_->isInList(identifier);
[197]150    }
151}
Note: See TracBrowser for help on using the repository browser.