| 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 OrxonoxClass.h |
|---|
| 31 | @brief Definition of the OrxonoxClass Class. |
|---|
| 32 | |
|---|
| 33 | All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass. |
|---|
| 34 | It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy. |
|---|
| 35 | */ |
|---|
| 36 | |
|---|
| 37 | #ifndef _OrxonoxClass_H__ |
|---|
| 38 | #define _OrxonoxClass_H__ |
|---|
| 39 | |
|---|
| 40 | #include "CorePrereqs.h" |
|---|
| 41 | |
|---|
| 42 | #include <set> |
|---|
| 43 | #include <string> |
|---|
| 44 | |
|---|
| 45 | #include "MetaObjectList.h" |
|---|
| 46 | #include "Iterator.h" |
|---|
| 47 | |
|---|
| 48 | namespace orxonox |
|---|
| 49 | { |
|---|
| 50 | //! The class all objects and interfaces of the game-logic (not the engine) are derived from. |
|---|
| 51 | /** |
|---|
| 52 | The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. |
|---|
| 53 | OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. |
|---|
| 54 | */ |
|---|
| 55 | class _CoreExport OrxonoxClass |
|---|
| 56 | { |
|---|
| 57 | public: |
|---|
| 58 | OrxonoxClass(); |
|---|
| 59 | virtual ~OrxonoxClass(); |
|---|
| 60 | |
|---|
| 61 | /** @brief Function to collect the SetConfigValue-macro calls. */ |
|---|
| 62 | void setConfigValues() {}; |
|---|
| 63 | |
|---|
| 64 | /** @brief Returns the Identifier of the object. @return The Identifier */ |
|---|
| 65 | inline Identifier* getIdentifier() const { return this->identifier_; } |
|---|
| 66 | |
|---|
| 67 | /** @brief Sets the Identifier of the object. Used by the RegisterObject-macro. */ |
|---|
| 68 | inline void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; } |
|---|
| 69 | |
|---|
| 70 | /** @brief Returns the list of all parents of the object. @return The list */ |
|---|
| 71 | inline std::set<const Identifier*>* getParents() const { return this->parents_; } |
|---|
| 72 | |
|---|
| 73 | /** @brief Creates the parents-list. */ |
|---|
| 74 | inline void createParents() { this->parents_ = new std::set<const Identifier*>(); } |
|---|
| 75 | |
|---|
| 76 | /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */ |
|---|
| 77 | inline MetaObjectList& getMetaList() { return this->metaList_; } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | /** @brief Returns true if the objects class is of the given type or a derivative. */ |
|---|
| 81 | inline bool isA(const Identifier* identifier) |
|---|
| 82 | { return this->getIdentifier()->isA(identifier); } |
|---|
| 83 | /** @brief Returns true if the objects class is exactly of the given type. */ |
|---|
| 84 | inline bool isExactlyA(const Identifier* identifier) |
|---|
| 85 | { return this->getIdentifier()->isExactlyA(identifier); } |
|---|
| 86 | /** @brief Returns true if the objects class is a child of the given type. */ |
|---|
| 87 | inline bool isChildOf(const Identifier* identifier) |
|---|
| 88 | { return this->getIdentifier()->isChildOf(identifier); } |
|---|
| 89 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 90 | inline bool isDirectChildOf(const Identifier* identifier) |
|---|
| 91 | { return this->getIdentifier()->isDirectChildOf(identifier); } |
|---|
| 92 | /** @brief Returns true if the objects class is a parent of the given type. */ |
|---|
| 93 | inline bool isParentOf(const Identifier* identifier) |
|---|
| 94 | { return this->getIdentifier()->isParentOf(identifier); } |
|---|
| 95 | /** @brief Returns true if the objects class is a direct parent of the given type. */ |
|---|
| 96 | inline bool isDirectParentOf(const Identifier* identifier) |
|---|
| 97 | { return this->getIdentifier()->isDirectParentOf(identifier); } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | /** @brief Returns true if the objects class is of the given type or a derivative. */ |
|---|
| 101 | inline bool isA(const SubclassIdentifier<class B>* identifier) |
|---|
| 102 | { return this->getIdentifier()->isA(identifier->getIdentifier()); } |
|---|
| 103 | /** @brief Returns true if the objects class is exactly of the given type. */ |
|---|
| 104 | inline bool isExactlyA(const SubclassIdentifier<class B>* identifier) |
|---|
| 105 | { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } |
|---|
| 106 | /** @brief Returns true if the objects class is a child of the given type. */ |
|---|
| 107 | inline bool isChildOf(const SubclassIdentifier<class B>* identifier) |
|---|
| 108 | { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } |
|---|
| 109 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 110 | inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier) |
|---|
| 111 | { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } |
|---|
| 112 | /** @brief Returns true if the objects class is a parent of the given type. */ |
|---|
| 113 | inline bool isParentOf(const SubclassIdentifier<class B>* identifier) |
|---|
| 114 | { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } |
|---|
| 115 | /** @brief Returns true if the objects class is a direct parent of the given type. */ |
|---|
| 116 | inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier) |
|---|
| 117 | { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | /** @brief Returns true if the objects class is of the given type or a derivative. */ |
|---|
| 121 | inline bool isA(const SubclassIdentifier<class B> identifier) |
|---|
| 122 | { return this->getIdentifier()->isA(identifier.getIdentifier()); } |
|---|
| 123 | /** @brief Returns true if the objects class is exactly of the given type. */ |
|---|
| 124 | inline bool isExactlyA(const SubclassIdentifier<class B> identifier) |
|---|
| 125 | { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } |
|---|
| 126 | /** @brief Returns true if the objects class is a child of the given type. */ |
|---|
| 127 | inline bool isChildOf(const SubclassIdentifier<class B> identifier) |
|---|
| 128 | { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } |
|---|
| 129 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 130 | inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier) |
|---|
| 131 | { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } |
|---|
| 132 | /** @brief Returns true if the objects class is a parent of the given type. */ |
|---|
| 133 | inline bool isParentOf(const SubclassIdentifier<class B> identifier) |
|---|
| 134 | { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } |
|---|
| 135 | /** @brief Returns true if the objects class is a direct parent of the given type. */ |
|---|
| 136 | inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier) |
|---|
| 137 | { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | /** @brief Returns true if the objects class is of the given type or a derivative. */ |
|---|
| 141 | inline bool isA(const OrxonoxClass* object) |
|---|
| 142 | { return this->getIdentifier()->isA(object->getIdentifier()); } |
|---|
| 143 | /** @brief Returns true if the objects class is exactly of the given type. */ |
|---|
| 144 | inline bool isExactlyA(const OrxonoxClass* object) |
|---|
| 145 | { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } |
|---|
| 146 | /** @brief Returns true if the objects class is a child of the given type. */ |
|---|
| 147 | inline bool isChildOf(const OrxonoxClass* object) |
|---|
| 148 | { return this->getIdentifier()->isChildOf(object->getIdentifier()); } |
|---|
| 149 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 150 | inline bool isDirectChildOf(const OrxonoxClass* object) |
|---|
| 151 | { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } |
|---|
| 152 | /** @brief Returns true if the objects class is a parent of the given type. */ |
|---|
| 153 | inline bool isParentOf(const OrxonoxClass* object) |
|---|
| 154 | { return this->getIdentifier()->isParentOf(object->getIdentifier()); } |
|---|
| 155 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 156 | inline bool isDirectParentOf(const OrxonoxClass* object) |
|---|
| 157 | { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } |
|---|
| 158 | |
|---|
| 159 | private: |
|---|
| 160 | Identifier* identifier_; //!< The Identifier of the object |
|---|
| 161 | std::set<const Identifier*>* parents_; //!< List of all parents of the object |
|---|
| 162 | MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in |
|---|
| 163 | }; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | #endif /* _OrxonoxClass_H__ */ |
|---|