[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> |
---|
[790] | 40 | #include <string> |
---|
| 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
[9564] | 44 | class _CoreExport IdentifierManager |
---|
| 45 | { |
---|
[5929] | 46 | public: |
---|
[9640] | 47 | static IdentifierManager& getInstance(); |
---|
| 48 | |
---|
[5929] | 49 | ///////////////////////////// |
---|
| 50 | ////// Class Hierarchy ////// |
---|
| 51 | ///////////////////////////// |
---|
[9641] | 52 | Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); |
---|
| 53 | |
---|
| 54 | unsigned int getUniqueClassId() |
---|
| 55 | { return this->classIDCounter_s++; } |
---|
| 56 | |
---|
| 57 | void registerIdentifier(Identifier* identifier); |
---|
| 58 | |
---|
[9640] | 59 | void createClassHierarchy(); |
---|
[790] | 60 | |
---|
[7401] | 61 | /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. |
---|
[9640] | 62 | inline bool isCreatingHierarchy() |
---|
[9564] | 63 | { return (hierarchyCreatingCounter_s > 0); } |
---|
[790] | 64 | |
---|
[1052] | 65 | |
---|
[5929] | 66 | ////////////////////////// |
---|
| 67 | ///// Identifier Map ///// |
---|
| 68 | ////////////////////////// |
---|
[9640] | 69 | void destroyAllIdentifiers(); |
---|
[1052] | 70 | |
---|
[9640] | 71 | Identifier* getIdentifierByString(const std::string& name); |
---|
| 72 | Identifier* getIdentifierByLowercaseString(const std::string& name); |
---|
| 73 | Identifier* getIdentifierByID(uint32_t id); |
---|
[5929] | 74 | |
---|
[9640] | 75 | void clearNetworkIDs(); |
---|
[5929] | 76 | |
---|
[7401] | 77 | /// Returns the map that stores all Identifiers with their names. |
---|
[9640] | 78 | inline const std::map<std::string, Identifier*>& getStringIdentifierMap() |
---|
| 79 | { return this->identifierByString_; } |
---|
[7401] | 80 | /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. |
---|
[9640] | 81 | inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() |
---|
| 82 | { return this->identifierByString_.begin(); } |
---|
[7401] | 83 | /// Returns a const_iterator to the end of the map that stores all Identifiers with their names. |
---|
[9640] | 84 | inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() |
---|
| 85 | { return this->identifierByString_.end(); } |
---|
[5929] | 86 | |
---|
[7401] | 87 | /// Returns the map that stores all Identifiers with their names in lowercase. |
---|
[9640] | 88 | inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() |
---|
| 89 | { return this->identifierByLowercaseString_; } |
---|
[7401] | 90 | /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. |
---|
[9640] | 91 | inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() |
---|
| 92 | { return this->identifierByLowercaseString_.begin(); } |
---|
[7401] | 93 | /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. |
---|
[9640] | 94 | inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() |
---|
| 95 | { return this->identifierByLowercaseString_.end(); } |
---|
[1052] | 96 | |
---|
[7401] | 97 | /// Returns the map that stores all Identifiers with their IDs. |
---|
[9640] | 98 | inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() |
---|
| 99 | { return this->identifierByNetworkId_; } |
---|
[7401] | 100 | /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. |
---|
[9640] | 101 | inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() |
---|
| 102 | { return this->identifierByNetworkId_.begin(); } |
---|
[7401] | 103 | /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. |
---|
[9640] | 104 | inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() |
---|
| 105 | { return this->identifierByNetworkId_.end(); } |
---|
[1052] | 106 | |
---|
[9640] | 107 | private: |
---|
| 108 | IdentifierManager(); |
---|
| 109 | IdentifierManager(const IdentifierManager&); |
---|
| 110 | ~IdentifierManager() {} |
---|
[1052] | 111 | |
---|
[7401] | 112 | /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. |
---|
[9640] | 113 | inline void startCreatingHierarchy() |
---|
[9564] | 114 | { hierarchyCreatingCounter_s++; } |
---|
[7401] | 115 | /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. |
---|
[9640] | 116 | inline void stopCreatingHierarchy() |
---|
[9564] | 117 | { hierarchyCreatingCounter_s--; } |
---|
[790] | 118 | |
---|
[9640] | 119 | std::map<std::string, Identifier*> identifierByTypeId_; //!< Map with the names as received by typeid(). This is only used internally. |
---|
[2662] | 120 | |
---|
[9640] | 121 | std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. |
---|
| 122 | std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. |
---|
| 123 | std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. |
---|
| 124 | |
---|
| 125 | 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) |
---|
| 126 | unsigned int classIDCounter_s; //!< counter for the unique classIDs |
---|
[790] | 127 | }; |
---|
| 128 | } |
---|
| 129 | |
---|
[9564] | 130 | #endif /* _IdentifierManager_H__ */ |
---|