Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/class/IdentifierManager.h @ 11007

Last change on this file since 11007 was 10624, checked in by landauf, 9 years ago

merged branch core7 back to trunk

  • Property svn:eol-style set to native
File size: 5.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 <set>
41#include <list>
42#include <string>
43
44#include "util/Singleton.h"
45
46namespace orxonox
47{
48    class _CoreExport IdentifierManager : public Singleton<IdentifierManager>
49    {
50        friend class Singleton<IdentifierManager>;
51
52        public:
53            IdentifierManager();
54            ~IdentifierManager() {}
55
56            void addIdentifier(Identifier* identifier);
57            void removeIdentifier(Identifier* identifier);
58
59
60            /////////////////////////////
61            ////// Class Hierarchy //////
62            /////////////////////////////
63            void createClassHierarchy();
64            void verifyClassHierarchy(const std::set<Identifier*>& initializedIdentifiers);
65            void destroyClassHierarchy();
66
67            void createdObject(Identifiable* identifiable);
68
69            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
70            inline bool isCreatingHierarchy()
71                { return (hierarchyCreatingCounter_s > 0); }
72
73
74            //////////////////////////
75            ///// Identifier Map /////
76            //////////////////////////
77            Identifier* getIdentifierByString(const std::string& name);
78            Identifier* getIdentifierByLowercaseString(const std::string& name);
79            Identifier* getIdentifierByID(uint32_t id);
80            Identifier* getIdentifierByTypeInfo(const std::type_info& typeInfo);
81
82            void clearNetworkIDs();
83
84            /// Returns the map that stores all Identifiers with their names.
85            inline const std::map<std::string, Identifier*>& getIdentifierByStringMap()
86                { return this->identifierByString_; }
87            /// Returns the map that stores all Identifiers with their names in lowercase.
88            inline const std::map<std::string, Identifier*>& getIdentifierByLowercaseStringMap()
89                { return this->identifierByLowercaseString_; }
90            /// Returns the map that stores all Identifiers with their IDs.
91            inline const std::map<uint32_t, Identifier*>& getIdentifierByNetworkIdMap()
92                { return this->identifierByNetworkId_; }
93
94        private:
95            IdentifierManager(const IdentifierManager&); // not implemented
96
97            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
98            inline void startCreatingHierarchy()
99                { hierarchyCreatingCounter_s++; }
100            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
101            inline void stopCreatingHierarchy()
102                { hierarchyCreatingCounter_s--; }
103
104            std::set<Identifier*> identifiers_;                              //!< All identifiers. This is only used internally.
105            std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
106            std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
107            std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
108
109            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)
110
111            /// Used while creating the object hierarchy to keep track of the identifiers of a newly created object (and all other objects that get created as
112            /// a consequence of this, e.g. nested member objects).
113            std::map<Identifiable*, std::list<const Identifier*> > identifierTraceOfNewObject_;
114            Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded.
115
116            static IdentifierManager* singletonPtr_s;
117    };
118}
119
120#endif /* _IdentifierManager_H__ */
Note: See TracBrowser for help on using the repository browser.