1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * |
---|
4 | * |
---|
5 | * License notice: |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | * |
---|
21 | * Author: |
---|
22 | * Fabian 'x3n' Landau |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | /** |
---|
29 | @file CoreIncludes.h |
---|
30 | @brief Definition of macros and typedefs. |
---|
31 | |
---|
32 | Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface |
---|
33 | or the BaseObject itself, it needs the macro RegisterRootObject(class) instead. |
---|
34 | |
---|
35 | To allow the object being created through the factory, use the CreateFactory(class) macro outside |
---|
36 | the of the class implementation, so it gets executed before main(). |
---|
37 | */ |
---|
38 | |
---|
39 | #ifndef _CoreIncludes_H__ |
---|
40 | #define _CoreIncludes_H__ |
---|
41 | |
---|
42 | #include "CorePrereqs.h" |
---|
43 | |
---|
44 | // All needed header-files |
---|
45 | #include "Identifier.h" |
---|
46 | #include "ClassManager.h" |
---|
47 | #include "Factory.h" |
---|
48 | #include "ClassFactory.h" |
---|
49 | #include "Iterator.h" |
---|
50 | #include "OrxonoxClass.h" |
---|
51 | #include "ConfigValueContainer.h" |
---|
52 | #include "Debug.h" |
---|
53 | |
---|
54 | |
---|
55 | // All needed macros |
---|
56 | /** |
---|
57 | @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. |
---|
58 | @param ClassName The name of the class |
---|
59 | @param bRootClass True if the class is directly derived from OrxonoxClass |
---|
60 | */ |
---|
61 | #define InternRegisterObject(ClassName, bRootClass) \ |
---|
62 | this->setIdentifier(orxonox::ClassManager<ClassName>::getIdentifier()->registerClass(this->getParents(), #ClassName, bRootClass)); \ |
---|
63 | if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \ |
---|
64 | this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \ |
---|
65 | orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this) |
---|
66 | |
---|
67 | /** |
---|
68 | @brief Intern macro, containing the specific part of RegisterRootObject. |
---|
69 | @param ClassName The name of the class |
---|
70 | */ |
---|
71 | #define InternRegisterRootObject(ClassName) \ |
---|
72 | if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \ |
---|
73 | this->createParents(); \ |
---|
74 | InternRegisterObject(ClassName, true) |
---|
75 | |
---|
76 | /** |
---|
77 | @brief RegisterObject - with and without debug output. |
---|
78 | @param ClassName The name of the class |
---|
79 | */ |
---|
80 | #define RegisterObject(ClassName) \ |
---|
81 | COUT(5) << "*** Register Object: " << #ClassName << std::endl; \ |
---|
82 | InternRegisterObject(ClassName, false) |
---|
83 | |
---|
84 | /** |
---|
85 | @brief RegisterRootObject - with and without debug output. |
---|
86 | @param ClassName The name of the class |
---|
87 | */ |
---|
88 | #define RegisterRootObject(ClassName) \ |
---|
89 | COUT(5) << "*** Register Root-Object: " << #ClassName << std::endl; \ |
---|
90 | InternRegisterRootObject(ClassName) |
---|
91 | |
---|
92 | /** |
---|
93 | @brief Returns the Identifier of the given class. |
---|
94 | @param ClassName The name of the class |
---|
95 | */ |
---|
96 | #define Class(ClassName) \ |
---|
97 | ClassManager<ClassName>::getIdentifier() |
---|
98 | |
---|
99 | /** |
---|
100 | @brief Creates the entry in the Factory. |
---|
101 | @param ClassName The name of the class |
---|
102 | */ |
---|
103 | #define CreateFactory(ClassName) \ |
---|
104 | bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName) |
---|
105 | |
---|
106 | /** |
---|
107 | @brief Returns the Identifier with either a given name or a given network ID through the factory. |
---|
108 | @param StringOrInt The name or the network ID of the class |
---|
109 | */ |
---|
110 | #define ID(StringOrInt) \ |
---|
111 | orxonox::Factory::getIdentifier(StringOrInt) |
---|
112 | |
---|
113 | /** |
---|
114 | @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file). |
---|
115 | @param varname The name of the variable |
---|
116 | @param defvalue The default-value of the variable |
---|
117 | */ |
---|
118 | #define SetConfigValue(varname, defvalue) \ |
---|
119 | orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ |
---|
120 | if (!container##varname) \ |
---|
121 | { \ |
---|
122 | container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \ |
---|
123 | this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \ |
---|
124 | } \ |
---|
125 | container##varname->getValue(&varname) |
---|
126 | |
---|
127 | /** |
---|
128 | @brief Sets the variable and the config-file entry back to the previously defined default-value. |
---|
129 | @param varname The name of the variable |
---|
130 | */ |
---|
131 | #define ResetConfigValue(varname) \ |
---|
132 | orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \ |
---|
133 | if (container##varname##reset) \ |
---|
134 | { \ |
---|
135 | container##varname##reset->resetConfigValue(); \ |
---|
136 | container##varname##reset->getValue(&varname); \ |
---|
137 | } \ |
---|
138 | else \ |
---|
139 | COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl |
---|
140 | |
---|
141 | #endif /* _CoreIncludes_H__ */ |
---|