[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 |
---|
[5929] | 31 | @brief Definition of macros for Identifiers |
---|
[1505] | 32 | |
---|
| 33 | Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface |
---|
| 34 | or the BaseObject itself, it needs the macro RegisterRootObject(class) instead. |
---|
| 35 | |
---|
| 36 | To allow the object being created through the factory, use the CreateFactory(class) macro outside |
---|
| 37 | the of the class implementation, so it gets executed before main(). |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #ifndef _CoreIncludes_H__ |
---|
| 41 | #define _CoreIncludes_H__ |
---|
| 42 | |
---|
| 43 | #include "CorePrereqs.h" |
---|
| 44 | |
---|
[3196] | 45 | #include "util/Debug.h" |
---|
[1505] | 46 | #include "Identifier.h" |
---|
[5929] | 47 | #include "SubclassIdentifier.h" |
---|
[1505] | 48 | #include "ClassFactory.h" |
---|
[3196] | 49 | #include "ObjectList.h" |
---|
[1505] | 50 | |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. |
---|
| 54 | @param ClassName The name of the class |
---|
| 55 | @param bRootClass True if the class is directly derived from OrxonoxClass |
---|
| 56 | */ |
---|
| 57 | #define InternRegisterObject(ClassName, bRootClass) \ |
---|
[3325] | 58 | if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \ |
---|
[1747] | 59 | return; \ |
---|
[3325] | 60 | else \ |
---|
| 61 | ((void)0) |
---|
[1505] | 62 | |
---|
| 63 | /** |
---|
| 64 | @brief RegisterObject - with and without debug output. |
---|
| 65 | @param ClassName The name of the class |
---|
| 66 | */ |
---|
| 67 | #define RegisterObject(ClassName) \ |
---|
| 68 | InternRegisterObject(ClassName, false) |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | @brief RegisterRootObject - with and without debug output. |
---|
| 72 | @param ClassName The name of the class |
---|
| 73 | */ |
---|
| 74 | #define RegisterRootObject(ClassName) \ |
---|
[3325] | 75 | InternRegisterObject(ClassName, true) |
---|
[1505] | 76 | |
---|
| 77 | /** |
---|
[5929] | 78 | @brief Creates the Factory. |
---|
[1856] | 79 | @param ClassName The name of the class |
---|
| 80 | */ |
---|
| 81 | #define CreateFactory(ClassName) \ |
---|
[5929] | 82 | Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true) |
---|
[1856] | 83 | |
---|
| 84 | /** |
---|
[5929] | 85 | @brief Creates the Factory for classes which should not be loaded through XML. |
---|
[5781] | 86 | @param ClassName The name of the class |
---|
| 87 | */ |
---|
| 88 | #define CreateUnloadableFactory(ClassName) \ |
---|
[5929] | 89 | Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false) |
---|
[5781] | 90 | |
---|
| 91 | /** |
---|
[1505] | 92 | @brief Returns the Identifier of the given class. |
---|
| 93 | @param ClassName The name of the class |
---|
| 94 | */ |
---|
[1789] | 95 | #define Class(ClassName) \ |
---|
[2087] | 96 | orxonox::ClassIdentifier<ClassName>::getIdentifier() |
---|
[1505] | 97 | |
---|
| 98 | |
---|
[3325] | 99 | namespace orxonox |
---|
| 100 | { |
---|
| 101 | /** |
---|
[5929] | 102 | @brief Returns the Identifier with a given name. |
---|
[7297] | 103 | @param name The name of the class |
---|
[3325] | 104 | */ |
---|
| 105 | inline Identifier* ClassByString(const std::string& name) |
---|
| 106 | { |
---|
[5929] | 107 | return Identifier::getIdentifierByString(name); |
---|
[3325] | 108 | } |
---|
[1505] | 109 | |
---|
[3325] | 110 | /** |
---|
[5929] | 111 | @brief Returns the Identifier with a given lowercase name. |
---|
[7297] | 112 | @param name The lowercase name of the class |
---|
[5929] | 113 | */ |
---|
| 114 | inline Identifier* ClassByLowercaseString(const std::string& name) |
---|
| 115 | { |
---|
| 116 | return Identifier::getIdentifierByLowercaseString(name); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | @brief Returns the Identifier with a given network ID. |
---|
[7297] | 121 | @param id The network ID of the class |
---|
[3325] | 122 | */ |
---|
| 123 | inline Identifier* ClassByID(uint32_t id) |
---|
| 124 | { |
---|
[5929] | 125 | return Identifier::getIdentifierByID(id); |
---|
[3325] | 126 | } |
---|
[6423] | 127 | |
---|
| 128 | /** |
---|
| 129 | @brief Returns the Identifier with a given 'this' pointer. |
---|
| 130 | @note This of course only works with OrxonoxClasses. |
---|
| 131 | The only use is in conjunction with macros that don't know the class type. |
---|
[7297] | 132 | @param object Pointer to an OrxonoxClass |
---|
[6423] | 133 | */ |
---|
| 134 | template <class T> |
---|
| 135 | inline Identifier* ClassByObjectType(const T* object) |
---|
| 136 | { |
---|
| 137 | return ClassIdentifier<T>::getIdentifier(); |
---|
| 138 | } |
---|
[3325] | 139 | } |
---|
| 140 | |
---|
[1505] | 141 | #endif /* _CoreIncludes_H__ */ |
---|