[790] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1505] | 3 | * > www.orxonox.net < |
---|
[790] | 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 | |
---|
[871] | 29 | /** |
---|
[2171] | 30 | @file |
---|
[7401] | 31 | @ingroup Class Identifier |
---|
[790] | 32 | */ |
---|
| 33 | |
---|
[9564] | 34 | #ifndef _IdentifierManager_H__ |
---|
| 35 | #define _IdentifierManager_H__ |
---|
[1052] | 36 | |
---|
[9563] | 37 | #include "core/CorePrereqs.h" |
---|
[1062] | 38 | |
---|
[3196] | 39 | #include <map> |
---|
[10399] | 40 | #include <set> |
---|
[10372] | 41 | #include <list> |
---|
[790] | 42 | #include <string> |
---|
| 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[9564] | 46 | class _CoreExport IdentifierManager |
---|
| 47 | { |
---|
[9667] | 48 | public: |
---|
| 49 | static IdentifierManager& getInstance(); |
---|
[790] | 50 | |
---|
[10395] | 51 | void addIdentifier(Identifier* identifier); |
---|
[9667] | 52 | |
---|
| 53 | unsigned int getUniqueClassId() |
---|
| 54 | { return this->classIDCounter_s++; } |
---|
| 55 | |
---|
| 56 | |
---|
[5929] | 57 | ///////////////////////////// |
---|
| 58 | ////// Class Hierarchy ////// |
---|
| 59 | ///////////////////////////// |
---|
[9667] | 60 | void createClassHierarchy(); |
---|
[10361] | 61 | void verifyClassHierarchy(); |
---|
[10403] | 62 | void destroyClassHierarchy(); |
---|
[790] | 63 | |
---|
[9667] | 64 | void createdObject(Identifiable* identifiable); |
---|
| 65 | |
---|
[7401] | 66 | /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. |
---|
[9667] | 67 | inline bool isCreatingHierarchy() |
---|
[9564] | 68 | { return (hierarchyCreatingCounter_s > 0); } |
---|
[790] | 69 | |
---|
[1052] | 70 | |
---|
[5929] | 71 | ////////////////////////// |
---|
| 72 | ///// Identifier Map ///// |
---|
| 73 | ////////////////////////// |
---|
[9667] | 74 | Identifier* getIdentifierByString(const std::string& name); |
---|
| 75 | Identifier* getIdentifierByLowercaseString(const std::string& name); |
---|
| 76 | Identifier* getIdentifierByID(uint32_t id); |
---|
[10399] | 77 | Identifier* getIdentifierByTypeInfo(const std::type_info& typeInfo); |
---|
[1052] | 78 | |
---|
[9667] | 79 | void clearNetworkIDs(); |
---|
[5929] | 80 | |
---|
[7401] | 81 | /// Returns the map that stores all Identifiers with their names. |
---|
[9667] | 82 | inline const std::map<std::string, Identifier*>& getIdentifierByStringMap() |
---|
| 83 | { return this->identifierByString_; } |
---|
[7401] | 84 | /// Returns the map that stores all Identifiers with their names in lowercase. |
---|
[9667] | 85 | inline const std::map<std::string, Identifier*>& getIdentifierByLowercaseStringMap() |
---|
| 86 | { return this->identifierByLowercaseString_; } |
---|
[7401] | 87 | /// Returns the map that stores all Identifiers with their IDs. |
---|
[9667] | 88 | inline const std::map<uint32_t, Identifier*>& getIdentifierByNetworkIdMap() |
---|
| 89 | { return this->identifierByNetworkId_; } |
---|
[1052] | 90 | |
---|
[10403] | 91 | void destroyAllIdentifiers(); |
---|
| 92 | |
---|
[9667] | 93 | private: |
---|
| 94 | IdentifierManager(); |
---|
| 95 | IdentifierManager(const IdentifierManager&); |
---|
| 96 | ~IdentifierManager() {} |
---|
[1747] | 97 | |
---|
[7401] | 98 | /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. |
---|
[9667] | 99 | inline void startCreatingHierarchy() |
---|
[9564] | 100 | { hierarchyCreatingCounter_s++; } |
---|
[7401] | 101 | /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. |
---|
[9667] | 102 | inline void stopCreatingHierarchy() |
---|
[9564] | 103 | { hierarchyCreatingCounter_s--; } |
---|
[790] | 104 | |
---|
[10399] | 105 | std::set<Identifier*> identifiers_; //!< All identifiers. This is only used internally. |
---|
[9667] | 106 | std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. |
---|
| 107 | std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. |
---|
| 108 | std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. |
---|
| 109 | |
---|
| 110 | 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) |
---|
| 111 | unsigned int classIDCounter_s; //!< counter for the unique classIDs |
---|
[10366] | 112 | |
---|
| 113 | /// 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 |
---|
| 114 | /// a consequence of this, e.g. nested member objects). |
---|
[10372] | 115 | std::map<Identifiable*, std::list<const Identifier*> > identifierTraceOfNewObject_; |
---|
[10370] | 116 | Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded. |
---|
[790] | 117 | }; |
---|
| 118 | } |
---|
| 119 | |
---|
[9564] | 120 | #endif /* _IdentifierManager_H__ */ |
---|