Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/shader/src/core/Factory.cc @ 12380

Last change on this file since 12380 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file Factory.cc
31    @brief Implementation of the Factory class.
32*/
33
34#include "Factory.h"
35#include "Identifier.h"
36#include "Debug.h"
37#include "BaseObject.h"
38
39namespace orxonox
40{
41    /**
42        @brief Returns the Identifier with a given name.
43        @param name The name of the wanted Identifier
44        @return The Identifier
45    */
46    Identifier* Factory::getIdentifier(const std::string& name)
47    {
48        return getFactoryPointer()->identifierStringMap_[name];
49    }
50
51    /**
52        @brief Returns the Identifier with a given network ID.
53        @param id The network ID of the wanted Identifier
54        @return The Identifier
55    */
56    Identifier* Factory::getIdentifier(const unsigned int id)
57    {
58        return getFactoryPointer()->identifierNetworkIDMap_[id];
59    }
60
61    /**
62        @brief Adds a new Identifier to both maps.
63        @param name The name of the identifier
64        @param identifier The identifier to add
65    */
66    void Factory::add(const std::string& name, Identifier* identifier)
67    {
68        getFactoryPointer()->identifierStringMap_[name] = identifier;
69        getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
70    }
71
72    /**
73        @brief Removes the entry with the old network ID and adds a new one.
74        @param identifier The identifier to change
75        @param oldID The old networkID
76        @param newID The new networkID
77    */
78    void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID)
79    {
80        getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
81        getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier;
82    }
83
84    /**
85        @brief Creates the class-hierarchy by creating and destroying one object of each type.
86    */
87    void Factory::createClassHierarchy()
88    {
89        COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
90        std::map<std::string, Identifier*>::iterator it;
91        it = getFactoryPointer()->identifierStringMap_.begin();
92        (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
93        for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
94        {
95            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
96            BaseObject* temp = (*it).second->fabricate();
97            delete temp;
98        }
99        (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
100        COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
101    }
102
103    /**
104        @brief Ensures the Factory gets created in the right moment.
105        @return The Factory.
106    */
107    Factory* Factory::getFactoryPointer()
108    {
109      static Factory theOneAndOnlyFactoryInstance = Factory();
110      return &theOneAndOnlyFactoryInstance;
111    }
112
113    /**
114        @brief Returns the begin-iterator of the factory-map.
115        @return The begin-iterator
116    */
117    std::map<std::string, Identifier*>::const_iterator Factory::getFactoryBegin()
118    {
119        return Factory::getFactoryPointer()->identifierStringMap_.begin();
120    }
121
122    /**
123        @brief Returns the end-iterator of the factory-map.
124        @return The end-iterator
125    */
126    std::map<std::string, Identifier*>::const_iterator Factory::getFactoryEnd()
127    {
128        return Factory::getFactoryPointer()->identifierStringMap_.end();
129    }
130}
Note: See TracBrowser for help on using the repository browser.