[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 | |
---|
[9641] | 49 | Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); |
---|
[9642] | 50 | void registerIdentifier(Identifier* identifier); |
---|
[9641] | 51 | |
---|
| 52 | unsigned int getUniqueClassId() |
---|
| 53 | { return this->classIDCounter_s++; } |
---|
| 54 | |
---|
| 55 | |
---|
[9642] | 56 | ///////////////////////////// |
---|
| 57 | ////// Class Hierarchy ////// |
---|
| 58 | ///////////////////////////// |
---|
[9640] | 59 | void createClassHierarchy(); |
---|
[9642] | 60 | void destroyAllIdentifiers(); |
---|
[790] | 61 | |
---|
[7401] | 62 | /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. |
---|
[9640] | 63 | inline bool isCreatingHierarchy() |
---|
[9564] | 64 | { return (hierarchyCreatingCounter_s > 0); } |
---|
[790] | 65 | |
---|
[1052] | 66 | |
---|
[5929] | 67 | ////////////////////////// |
---|
| 68 | ///// Identifier Map ///// |
---|
| 69 | ////////////////////////// |
---|
[9640] | 70 | Identifier* getIdentifierByString(const std::string& name); |
---|
| 71 | Identifier* getIdentifierByLowercaseString(const std::string& name); |
---|
| 72 | Identifier* getIdentifierByID(uint32_t id); |
---|
[5929] | 73 | |
---|
[9640] | 74 | void clearNetworkIDs(); |
---|
[5929] | 75 | |
---|
[7401] | 76 | /// Returns the map that stores all Identifiers with their names. |
---|
[9642] | 77 | inline const std::map<std::string, Identifier*>& getIdentifierByStringMap() |
---|
[9640] | 78 | { return this->identifierByString_; } |
---|
[7401] | 79 | /// Returns the map that stores all Identifiers with their names in lowercase. |
---|
[9642] | 80 | inline const std::map<std::string, Identifier*>& getIdentifierByLowercaseStringMap() |
---|
[9640] | 81 | { return this->identifierByLowercaseString_; } |
---|
[7401] | 82 | /// Returns the map that stores all Identifiers with their IDs. |
---|
[9642] | 83 | inline const std::map<uint32_t, Identifier*>& getIdentifierByNetworkIdMap() |
---|
[9640] | 84 | { return this->identifierByNetworkId_; } |
---|
[1052] | 85 | |
---|
[9640] | 86 | private: |
---|
| 87 | IdentifierManager(); |
---|
| 88 | IdentifierManager(const IdentifierManager&); |
---|
| 89 | ~IdentifierManager() {} |
---|
[1052] | 90 | |
---|
[7401] | 91 | /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. |
---|
[9640] | 92 | inline void startCreatingHierarchy() |
---|
[9564] | 93 | { hierarchyCreatingCounter_s++; } |
---|
[7401] | 94 | /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. |
---|
[9640] | 95 | inline void stopCreatingHierarchy() |
---|
[9564] | 96 | { hierarchyCreatingCounter_s--; } |
---|
[790] | 97 | |
---|
[9640] | 98 | std::map<std::string, Identifier*> identifierByTypeId_; //!< Map with the names as received by typeid(). This is only used internally. |
---|
[2662] | 99 | |
---|
[9640] | 100 | std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. |
---|
| 101 | std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. |
---|
| 102 | std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. |
---|
| 103 | |
---|
| 104 | 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) |
---|
| 105 | unsigned int classIDCounter_s; //!< counter for the unique classIDs |
---|
[790] | 106 | }; |
---|
| 107 | } |
---|
| 108 | |
---|
[9564] | 109 | #endif /* _IdentifierManager_H__ */ |
---|