Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/src/libraries/core/class/IdentifierManager.h @ 9640

Last change on this file since 9640 was 9640, checked in by landauf, 11 years ago

made IdentifierManager a self-initializing singleton

  • Property svn:eol-style set to native
File size: 6.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    @ingroup Class Identifier
32*/
33
34#ifndef _IdentifierManager_H__
35#define _IdentifierManager_H__
36
37#include "core/CorePrereqs.h"
38
39#include <map>
40#include <string>
41
42namespace orxonox
43{
44    class _CoreExport IdentifierManager
45    {
46        friend class Identifier;
47        template <class T> friend class ClassIdentifier;
48
49        public:
50            static IdentifierManager& getInstance();
51
52            /////////////////////////////
53            ////// Class Hierarchy //////
54            /////////////////////////////
55            void createClassHierarchy();
56
57            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
58            inline bool isCreatingHierarchy()
59                { return (hierarchyCreatingCounter_s > 0); }
60
61
62            //////////////////////////
63            ///// Identifier Map /////
64            //////////////////////////
65            void destroyAllIdentifiers();
66
67            Identifier* getIdentifierByString(const std::string& name);
68            Identifier* getIdentifierByLowercaseString(const std::string& name);
69            Identifier* getIdentifierByID(uint32_t id);
70
71            void clearNetworkIDs();
72
73            /// Returns the map that stores all Identifiers with their names.
74            inline const std::map<std::string, Identifier*>& getStringIdentifierMap()
75                { return this->identifierByString_; }
76            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names.
77            inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin()
78                { return this->identifierByString_.begin(); }
79            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names.
80            inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd()
81                { return this->identifierByString_.end(); }
82
83            /// Returns the map that stores all Identifiers with their names in lowercase.
84            inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap()
85                { return this->identifierByLowercaseString_; }
86            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase.
87            inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin()
88                { return this->identifierByLowercaseString_.begin(); }
89            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase.
90            inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd()
91                { return this->identifierByLowercaseString_.end(); }
92
93            /// Returns the map that stores all Identifiers with their IDs.
94            inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap()
95                { return this->identifierByNetworkId_; }
96            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs.
97            inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin()
98                { return this->identifierByNetworkId_.begin(); }
99            /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs.
100            inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd()
101                { return this->identifierByNetworkId_.end(); }
102
103        protected:
104            Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
105
106        private:
107            IdentifierManager();
108            IdentifierManager(const IdentifierManager&);
109            ~IdentifierManager() {}
110
111            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
112            inline void startCreatingHierarchy()
113                { hierarchyCreatingCounter_s++; }
114            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
115            inline void stopCreatingHierarchy()
116                { hierarchyCreatingCounter_s--; }
117
118            std::map<std::string, Identifier*> identifierByTypeId_;          //!< Map with the names as received by typeid(). This is only used internally.
119
120            std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
121            std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
122            std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
123
124            int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
125            unsigned int classIDCounter_s;                          //!< counter for the unique classIDs
126    };
127}
128
129#endif /* _IdentifierManager_H__ */
Note: See TracBrowser for help on using the repository browser.