Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

moved static functions from Identifier.cc/h to IdentifierManager.cc/h (still static though)

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