Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed mutual friend declarations between Identifier and IdentifierManager

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