Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/Factory.cc @ 552

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

removed stupid hack

File size: 3.7 KB
Line 
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
28/*!
29    @file Factory.cc
30    @brief Implementation of the Factory class.
31*/
32
33#include "Factory.h"
34#include "Identifier.h"
35#include "Debug.h"
36#include "../objects/BaseObject.h"
37
38namespace orxonox
39{
40    Factory* Factory::pointer_s = NULL; // Set the static member variable pointer_s to zero
41
42    /**
43        @returns the Identifier with a given name.
44        @param name The name of the wanted Identifier
45    */
46    Identifier* Factory::getIdentifier(const std::string& name)
47    {
48        Factory::checkPointer();
49
50        return pointer_s->identifierStringMap_[name];
51    }
52
53    /**
54        @returns the Identifier with a given network ID.
55        @param id The network ID of the wanted Identifier
56    */
57    Identifier* Factory::getIdentifier(const unsigned int id)
58    {
59        Factory::checkPointer();
60
61        return pointer_s->identifierNetworkIDMap_[id];
62    }
63
64    /**
65        @brief Adds a new Identifier to both maps.
66        @param name The name of the identifier
67        @param identifier The identifier to add
68    */
69    void Factory::add(const std::string& name, Identifier* identifier)
70    {
71        Factory::checkPointer();
72
73        pointer_s->identifierStringMap_[name] = identifier;
74        pointer_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
75    }
76
77    /**
78        @brief Removes the entry with the old network ID and adds a new one.
79        @param identifier The identifier to change
80        @param oldID The old networkID
81        @param newID The new networkID
82    */
83    void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID)
84    {
85        Factory::checkPointer();
86
87        pointer_s->identifierNetworkIDMap_.erase(oldID);
88        pointer_s->identifierNetworkIDMap_[newID] = identifier;
89    }
90
91    /**
92        @brief Creates the class-hierarchy by creating and destroying one object of each type.
93    */
94    void Factory::createClassHierarchy()
95    {
96        Factory::checkPointer();
97
98        COUT(4) << "*** Factory -> Create class-hierarchy\n";
99        std::map<std::string, Identifier*>::iterator it;
100        it = pointer_s->identifierStringMap_.begin();
101        (*pointer_s->identifierStringMap_.begin()).second->startCreatingHierarchy();
102        for (it = pointer_s->identifierStringMap_.begin(); it != pointer_s->identifierStringMap_.end(); ++it)
103        {
104            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
105            BaseObject* temp = (*it).second->fabricate();
106            delete temp;
107        }
108        (*pointer_s->identifierStringMap_.begin()).second->stopCreatingHierarchy();
109        COUT(4) << "*** Factory -> Finished class-hierarchy creation\n";
110    }
111}
Note: See TracBrowser for help on using the repository browser.