[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 | |
---|
[11071] | 39 | #include <typeindex> |
---|
[3196] | 40 | #include <map> |
---|
[11071] | 41 | #include <unordered_map> |
---|
[9667] | 42 | #include <set> |
---|
[10624] | 43 | #include <list> |
---|
[790] | 44 | #include <string> |
---|
| 45 | |
---|
[10624] | 46 | #include "util/Singleton.h" |
---|
| 47 | |
---|
[790] | 48 | namespace orxonox |
---|
| 49 | { |
---|
[10624] | 50 | class _CoreExport IdentifierManager : public Singleton<IdentifierManager> |
---|
[9564] | 51 | { |
---|
[10624] | 52 | friend class Singleton<IdentifierManager>; |
---|
| 53 | |
---|
[9667] | 54 | public: |
---|
[10624] | 55 | IdentifierManager(); |
---|
[11071] | 56 | ~IdentifierManager() = default; |
---|
[790] | 57 | |
---|
[10624] | 58 | void addIdentifier(Identifier* identifier); |
---|
| 59 | void removeIdentifier(Identifier* identifier); |
---|
[9667] | 60 | |
---|
| 61 | |
---|
[5929] | 62 | ///////////////////////////// |
---|
| 63 | ////// Class Hierarchy ////// |
---|
| 64 | ///////////////////////////// |
---|
[9667] | 65 | void createClassHierarchy(); |
---|
[10624] | 66 | void verifyClassHierarchy(const std::set<Identifier*>& initializedIdentifiers); |
---|
| 67 | void destroyClassHierarchy(); |
---|
[790] | 68 | |
---|
[9667] | 69 | void createdObject(Identifiable* identifiable); |
---|
| 70 | |
---|
[7401] | 71 | /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. |
---|
[9667] | 72 | inline bool isCreatingHierarchy() |
---|
[9564] | 73 | { return (hierarchyCreatingCounter_s > 0); } |
---|
[790] | 74 | |
---|
[1052] | 75 | |
---|
[5929] | 76 | ////////////////////////// |
---|
| 77 | ///// Identifier Map ///// |
---|
| 78 | ////////////////////////// |
---|
[9667] | 79 | Identifier* getIdentifierByString(const std::string& name); |
---|
| 80 | Identifier* getIdentifierByLowercaseString(const std::string& name); |
---|
| 81 | Identifier* getIdentifierByID(uint32_t id); |
---|
[10624] | 82 | Identifier* getIdentifierByTypeInfo(const std::type_info& typeInfo); |
---|
[1052] | 83 | |
---|
[9667] | 84 | void clearNetworkIDs(); |
---|
[5929] | 85 | |
---|
[7401] | 86 | /// Returns the map that stores all Identifiers with their names. |
---|
[9667] | 87 | inline const std::map<std::string, Identifier*>& getIdentifierByStringMap() |
---|
| 88 | { return this->identifierByString_; } |
---|
[7401] | 89 | /// Returns the map that stores all Identifiers with their names in lowercase. |
---|
[9667] | 90 | inline const std::map<std::string, Identifier*>& getIdentifierByLowercaseStringMap() |
---|
| 91 | { return this->identifierByLowercaseString_; } |
---|
[7401] | 92 | /// Returns the map that stores all Identifiers with their IDs. |
---|
[9667] | 93 | inline const std::map<uint32_t, Identifier*>& getIdentifierByNetworkIdMap() |
---|
| 94 | { return this->identifierByNetworkId_; } |
---|
[1052] | 95 | |
---|
[9667] | 96 | private: |
---|
[11071] | 97 | // non-copyable: |
---|
| 98 | IdentifierManager(const IdentifierManager&) = delete; |
---|
| 99 | IdentifierManager& operator=(const IdentifierManager&) = delete; |
---|
[1747] | 100 | |
---|
[7401] | 101 | /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. |
---|
[9667] | 102 | inline void startCreatingHierarchy() |
---|
[9564] | 103 | { hierarchyCreatingCounter_s++; } |
---|
[7401] | 104 | /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. |
---|
[9667] | 105 | inline void stopCreatingHierarchy() |
---|
[9564] | 106 | { hierarchyCreatingCounter_s--; } |
---|
[790] | 107 | |
---|
[11071] | 108 | std::set<Identifier*> identifiers_; //!< All identifiers. This is only used internally. |
---|
| 109 | std::unordered_map<std::type_index, Identifier*> identifierByTypeIndex_; //!< Map that stores all Identifiers with their type_index. |
---|
| 110 | std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. |
---|
| 111 | std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. |
---|
| 112 | std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. |
---|
[9667] | 113 | |
---|
| 114 | 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) |
---|
[10624] | 115 | |
---|
| 116 | /// 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 |
---|
| 117 | /// a consequence of this, e.g. nested member objects). |
---|
[11071] | 118 | std::map<Identifiable*, std::list<const Identifier*>> identifierTraceOfNewObject_; |
---|
[10624] | 119 | Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded. |
---|
| 120 | |
---|
| 121 | static IdentifierManager* singletonPtr_s; |
---|
[790] | 122 | }; |
---|
| 123 | } |
---|
| 124 | |
---|
[9564] | 125 | #endif /* _IdentifierManager_H__ */ |
---|