Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource2/src/core/Factory.h @ 5610

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

Improved CMake performance for runs after the first one.
There are some optimisations in the macro argument parser and I manually added the header files for util and network (since they don't change too much and it still compiles with a missing header files).

  • Property svn:eol-style set to native
File size: 4.0 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 Definition of the Factory and the BaseFactory class.
32
33    The Factory is a singleton, containing two maps to map either the name or the network ID
34    of a class with the corresponding Identifier.
35
36    Usage:
37    ID(classname) or ID(networkID) returns the corresponding Identifier.
38
39
40    BaseObject is the parent of ClassFactory which is defined in ClassFactory.h.
41    It can't be defined in ClassFactory.h, because of circular dependencies.
42*/
43
44#ifndef _Factory_H__
45#define _Factory_H__
46
47#include "CorePrereqs.h"
48
49#include <map>
50#include <string>
51
52namespace orxonox
53{
54    // ###############################
55    // ###         Factory         ###
56    // ###############################
57    //! The Factory is used to map the name or the network ID of a class with its Identifier.
58    class _CoreExport Factory
59    {
60        public:
61            static Identifier* getIdentifier(const std::string& name);
62            static Identifier* getIdentifier(const uint32_t id);
63            static void add(const std::string& name, BaseFactory* factory);
64            static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID);
65            static void cleanNetworkIDs();
66            static void createClassHierarchy();
67
68            static Factory* getFactoryPointer();    // avoid overriding order problem in the static intialisation process
69
70            /** @brief Returns the factory-map. */
71            static const std::map<std::string, Identifier*>& getFactoryMap()
72                { return Factory::getFactoryPointer()->identifierStringMap_; }
73            /** @brief Returns the begin-iterator of the factory-map. */
74            static std::map<std::string, Identifier*>::const_iterator getFactoryMapBegin()
75                { return Factory::getFactoryPointer()->identifierStringMap_.begin(); }
76            /** @brief Returns the end-iterator of the factory-map. */
77            static std::map<std::string, Identifier*>::const_iterator getFactoryMapEnd()
78                { return Factory::getFactoryPointer()->identifierStringMap_.end(); }
79
80        private:
81            Factory() {}                            // don't create
82            Factory(const Factory& factory);        // don't copy
83            ~Factory() {}                           // don't delete
84
85            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
86            std::map<uint32_t, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
87            std::map<std::string, BaseFactory*> factoryMap_;
88    };
89
90    // ###############################
91    // ###       BaseFactory       ###
92    // ###############################
93    //! Base-class of ClassFactory. Has to be defined separate because of circular dependencies.
94    class _CoreExport BaseFactory
95    {
96        public:
97            virtual BaseObject* fabricate(BaseObject* creator) = 0;
98            virtual Identifier* createIdentifier(const std::string& name) = 0;
99            virtual ~BaseFactory() {};
100    };
101}
102
103#endif /* _Factory_H__ */
Note: See TracBrowser for help on using the repository browser.