Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: sandbox/src/libraries/core/Factory.cc @ 5782

Last change on this file since 5782 was 5782, checked in by rgrieder, 15 years ago

Applied changes to the real sandbox this time.

  • Property svn:eol-style set to native
File size: 3.1 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
31    @brief Implementation of the Factory class.
32*/
33
34#include "Factory.h"
35
36#include "util/Debug.h"
37#include "Identifier.h"
38#include "BaseObject.h"
39
40namespace orxonox
41{
42    /**
43        @brief Returns the Identifier with a given name.
44        @param name The name of the wanted Identifier
45        @return The Identifier
46    */
47    Identifier* Factory::getIdentifier(const std::string& name)
48    {
49        std::map<std::string, Identifier*>::const_iterator it = getFactoryPointer()->identifierStringMap_.find(name);
50        if (it != getFactoryPointer()->identifierStringMap_.end())
51            return it->second;
52        else
53            return 0;
54    }
55
56    /**
57        @brief Adds a new Identifier to both maps.
58        @param name The name of the identifier
59        @param identifier The identifier to add
60    */
61    void Factory::add(const std::string& name, Identifier* identifier)
62    {
63        getFactoryPointer()->identifierStringMap_[name] = identifier;
64    }
65
66    /**
67        @brief Creates the class-hierarchy by creating and destroying one object of each type.
68    */
69    void Factory::createClassHierarchy()
70    {
71        COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
72        std::map<std::string, Identifier*>::iterator it;
73        it = getFactoryPointer()->identifierStringMap_.begin();
74        (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
75        for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
76        {
77            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
78            BaseObject* temp = (*it).second->fabricate(0);
79            delete temp;
80        }
81        (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
82        COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
83    }
84
85    /**
86        @brief Ensures the Factory gets created in the right moment.
87        @return The Factory.
88    */
89    Factory* Factory::getFactoryPointer()
90    {
91      static Factory theOneAndOnlyFactoryInstance = Factory();
92      return &theOneAndOnlyFactoryInstance;
93    }
94}
Note: See TracBrowser for help on using the repository browser.