[1505] | 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 | /** |
---|
[2171] | 30 | @file |
---|
[1755] | 31 | @brief Declaration of the OrxonoxClass Class. |
---|
[1505] | 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" |
---|
[3327] | 41 | |
---|
[1505] | 42 | #include <set> |
---|
[3327] | 43 | #include <vector> |
---|
[1505] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
| 47 | //! The class all objects and interfaces of the game-logic (not the engine) are derived from. |
---|
| 48 | /** |
---|
| 49 | The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. |
---|
| 50 | OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. |
---|
| 51 | */ |
---|
| 52 | class _CoreExport OrxonoxClass |
---|
| 53 | { |
---|
[3325] | 54 | template <class T> |
---|
| 55 | friend class ClassIdentifier; |
---|
| 56 | |
---|
[1505] | 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 | bool isA(const Identifier* identifier); |
---|
| 68 | bool isExactlyA(const Identifier* identifier); |
---|
| 69 | bool isChildOf(const Identifier* identifier); |
---|
| 70 | bool isDirectChildOf(const Identifier* identifier); |
---|
| 71 | bool isParentOf(const Identifier* identifier); |
---|
| 72 | bool isDirectParentOf(const Identifier* identifier); |
---|
| 73 | |
---|
[6038] | 74 | template <class B> inline bool isA(const SubclassIdentifier<B>* identifier) |
---|
| 75 | { return this->isA(*identifier); } |
---|
| 76 | template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier) |
---|
| 77 | { return this->isExactlyA(*identifier); } |
---|
| 78 | template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier) |
---|
| 79 | { return this->isChildOf(*identifier); } |
---|
| 80 | template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier) |
---|
| 81 | { return this->isDirectChildOf(*identifier); } |
---|
| 82 | template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier) |
---|
| 83 | { return this->isParentOf(*identifier); } |
---|
| 84 | template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier) |
---|
| 85 | { return this->isDirectParentOf(*identifier); } |
---|
[1505] | 86 | |
---|
| 87 | bool isA(const OrxonoxClass* object); |
---|
| 88 | bool isExactlyA(const OrxonoxClass* object); |
---|
| 89 | bool isChildOf(const OrxonoxClass* object); |
---|
| 90 | bool isDirectChildOf(const OrxonoxClass* object); |
---|
| 91 | bool isParentOf(const OrxonoxClass* object); |
---|
| 92 | bool isDirectParentOf(const OrxonoxClass* object); |
---|
| 93 | |
---|
[3325] | 94 | /** |
---|
| 95 | @brief |
---|
| 96 | Returns a valid pointer of any derived type that is |
---|
| 97 | registered in the class hierarchy. |
---|
| 98 | @return |
---|
| 99 | Returns NULL if the no pointer was found. |
---|
| 100 | */ |
---|
[6038] | 101 | FORCEINLINE void* getDerivedPointer(unsigned int classID) |
---|
[3325] | 102 | { |
---|
| 103 | for (int i = this->objectPointers_.size() - 1; i >= 0; --i) |
---|
| 104 | { |
---|
| 105 | if (this->objectPointers_[i].first == classID) |
---|
[6038] | 106 | return this->objectPointers_[i].second; |
---|
[3325] | 107 | } |
---|
| 108 | return NULL; |
---|
| 109 | } |
---|
| 110 | |
---|
[6038] | 111 | //! Version of getDerivedPointer with template |
---|
| 112 | template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID) |
---|
| 113 | { return static_cast<T*>(this->getDerivedPointer(classID)); } |
---|
| 114 | //! Const version of getDerivedPointer with template |
---|
| 115 | template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const |
---|
| 116 | { return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); } |
---|
| 117 | |
---|
[1505] | 118 | private: |
---|
| 119 | Identifier* identifier_; //!< The Identifier of the object |
---|
| 120 | std::set<const Identifier*>* parents_; //!< List of all parents of the object |
---|
| 121 | MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in |
---|
[3325] | 122 | //! 'Fast map' that holds this-pointers of all derived types |
---|
| 123 | std::vector<std::pair<unsigned int, void*> > objectPointers_; |
---|
[1505] | 124 | }; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | #endif /* _OrxonoxClass_H__ */ |
---|