Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/libs/src/libraries/core/class/IdentifierManager.h @ 10077

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

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 4.7 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 <string>
42
43namespace orxonox
44{
45    class _CoreExport IdentifierManager
46    {
47        public:
48            static IdentifierManager& getInstance();
49
50            Identifier* getGloballyUniqueIdentifier(Identifier* proposal);
51            void addIdentifierToLookupMaps(Identifier* identifier);
52
53            unsigned int getUniqueClassId()
54                { return this->classIDCounter_s++; }
55
56
57            /////////////////////////////
58            ////// Class Hierarchy //////
59            /////////////////////////////
60            void createClassHierarchy();
61            void destroyAllIdentifiers();
62
63            void createdObject(Identifiable* identifiable);
64
65            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
66            inline bool isCreatingHierarchy()
67                { return (hierarchyCreatingCounter_s > 0); }
68
69
70            //////////////////////////
71            ///// Identifier Map /////
72            //////////////////////////
73            Identifier* getIdentifierByString(const std::string& name);
74            Identifier* getIdentifierByLowercaseString(const std::string& name);
75            Identifier* getIdentifierByID(uint32_t id);
76
77            void clearNetworkIDs();
78
79            /// Returns the map that stores all Identifiers with their names.
80            inline const std::map<std::string, Identifier*>& getIdentifierByStringMap()
81                { return this->identifierByString_; }
82            /// Returns the map that stores all Identifiers with their names in lowercase.
83            inline const std::map<std::string, Identifier*>& getIdentifierByLowercaseStringMap()
84                { return this->identifierByLowercaseString_; }
85            /// Returns the map that stores all Identifiers with their IDs.
86            inline const std::map<uint32_t, Identifier*>& getIdentifierByNetworkIdMap()
87                { return this->identifierByNetworkId_; }
88
89        private:
90            IdentifierManager();
91            IdentifierManager(const IdentifierManager&);
92            ~IdentifierManager() {}
93
94            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
95            inline void startCreatingHierarchy()
96                { hierarchyCreatingCounter_s++; }
97            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
98            inline void stopCreatingHierarchy()
99                { hierarchyCreatingCounter_s--; }
100
101            std::map<std::string, Identifier*> identifierByTypeidName_;      //!< Map with the names as received by typeid(). This is only used internally.
102
103            std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
104            std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
105            std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
106
107            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)
108            std::set<const Identifier*> identifiersOfNewObject_;    //!< Used while creating the object hierarchy to keep track of the identifiers of a newly created object
109            unsigned int classIDCounter_s;                          //!< counter for the unique classIDs
110    };
111}
112
113#endif /* _IdentifierManager_H__ */
Note: See TracBrowser for help on using the repository browser.