[1679] | 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 | |
---|
[1684] | 29 | /** |
---|
[7363] | 30 | @defgroup Super Super |
---|
| 31 | @ingroup Class |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** |
---|
[2171] | 35 | @file |
---|
[7363] | 36 | @ingroup Class Super |
---|
[1684] | 37 | @brief Definition of all super-function related macros. |
---|
| 38 | |
---|
| 39 | This file defines all macros needed to add a new "super-function". |
---|
| 40 | If you add a super-function, you can call SUPER(myclass, functionname) inside your |
---|
| 41 | code and the function of the parentclass gets called. This is comparable with |
---|
| 42 | super.functionname() in Java or other languages. |
---|
| 43 | |
---|
| 44 | This works only with virtual functions that return nothing (void) and belong to |
---|
| 45 | classes that have an Identifier. Arguments however are supported. |
---|
| 46 | |
---|
[1687] | 47 | To add a new super-function, you have process 4 steps: |
---|
[1684] | 48 | |
---|
| 49 | 1) Add a new SUPER macro |
---|
| 50 | This allows you to call the super-function in your code. |
---|
[1687] | 51 | Location: This file (Super.h), marked with --> HERE <-- comments (1/3) |
---|
[1684] | 52 | |
---|
| 53 | 2) Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros. |
---|
| 54 | This defines some global classes and templates, needed to create and call the super-functions. |
---|
[1687] | 55 | Location: This file (Super.h), marked with --> HERE <-- comments (2/3) |
---|
[1684] | 56 | |
---|
| 57 | 3) Call the SUPER_INTRUSIVE_DECLARATION macro. |
---|
| 58 | This will be included into the declaration of ClassIdentifier<T>. |
---|
[1687] | 59 | Location: This file (Super.h), marked with --> HERE <-- comments (3/3) |
---|
[1684] | 60 | |
---|
[1687] | 61 | 4) Call the SUPER_FUNCTION macro. |
---|
[1684] | 62 | This defines a partially specialized template that will decide if a class is "super" to another class. |
---|
| 63 | If the check returns true, a SuperFunctionCaller gets created, which will be used by the SUPER macro. |
---|
| 64 | You have to add this into the header-file of the baseclass of the super-function (the class that first |
---|
| 65 | implements the function), below the class declaration. You can't call it directly in this file, because |
---|
| 66 | otherwise you had to include the headerfile right here, which would cause some ugly backdependencies, |
---|
| 67 | include loops and slower compilation. |
---|
| 68 | Dont forget to include Super.h in the header-file. |
---|
| 69 | Location: The header-file of the baseclass (Baseclass.h), below the class declaration |
---|
| 70 | */ |
---|
| 71 | |
---|
[1679] | 72 | #ifndef _Super_H__ |
---|
| 73 | #define _Super_H__ |
---|
| 74 | |
---|
[1684] | 75 | #include "CorePrereqs.h" |
---|
[1679] | 76 | |
---|
[1684] | 77 | #include "util/Debug.h" |
---|
[2087] | 78 | #include "Event.h" |
---|
[1679] | 79 | |
---|
[1684] | 80 | /////////////////////// |
---|
| 81 | // Macro definitions // |
---|
| 82 | /////////////////////// |
---|
| 83 | |
---|
| 84 | //// Common macros //// |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | @brief Declares a new super-function by creating a specialized template. Add this below the class declaration of the baseclass. |
---|
| 88 | @param functionnumber Each super-function needs a unique number, starting with zero, increasing by one |
---|
| 89 | @param baseclass The baseclass of the super-function (~the root) |
---|
| 90 | @param functionname The name of the super-function |
---|
| 91 | @param purevirtualbase "true" if the function is pure virtual in the baseclass, "false" if the function is implemented (without "") |
---|
| 92 | */ |
---|
| 93 | #define SUPER_FUNCTION(functionnumber, baseclass, functionname, purevirtualbase) \ |
---|
| 94 | template <class T, int templatehack2> \ |
---|
| 95 | struct SuperFunctionCondition<functionnumber, T, 0, templatehack2> \ |
---|
| 96 | { \ |
---|
| 97 | static void check() \ |
---|
| 98 | { \ |
---|
[3301] | 99 | SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(0)); \ |
---|
[1684] | 100 | SuperFunctionCondition<functionnumber + 1, T, 0, templatehack2>::check(); \ |
---|
| 101 | } \ |
---|
| 102 | \ |
---|
| 103 | static void apply(void* temp) {} \ |
---|
[2662] | 104 | \ |
---|
[1684] | 105 | static void apply(baseclass* temp) \ |
---|
| 106 | { \ |
---|
| 107 | ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); \ |
---|
| 108 | for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \ |
---|
| 109 | { \ |
---|
[2662] | 110 | if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \ |
---|
| 111 | { \ |
---|
| 112 | delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; \ |
---|
| 113 | ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; \ |
---|
| 114 | ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \ |
---|
| 115 | } \ |
---|
| 116 | \ |
---|
[1684] | 117 | if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \ |
---|
| 118 | { \ |
---|
[1736] | 119 | COUT(5) << "Added SuperFunctionCaller for " << #functionname << ": " << ClassIdentifier<T>::getIdentifier()->getName() << " <- " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl; \ |
---|
[1684] | 120 | ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; \ |
---|
| 121 | } \ |
---|
| 122 | } \ |
---|
| 123 | } \ |
---|
| 124 | }; \ |
---|
| 125 | \ |
---|
| 126 | SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND##purevirtualbase(functionnumber, baseclass) |
---|
| 127 | |
---|
| 128 | #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND0(functionnumber, baseclass) SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass) |
---|
| 129 | #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND1(functionnumber, baseclass) SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass) |
---|
| 130 | #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass) |
---|
| 131 | #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass) \ |
---|
| 132 | template <int templatehack2> \ |
---|
| 133 | struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \ |
---|
| 134 | { \ |
---|
| 135 | static void check() \ |
---|
| 136 | { \ |
---|
| 137 | SuperFunctionCondition<functionnumber + 1, baseclass, 0, templatehack2>::check(); \ |
---|
| 138 | } \ |
---|
| 139 | }; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | //// Comments about the macro //// |
---|
| 144 | |
---|
| 145 | // Partially specialized template (templatehack is now specialized too). |
---|
| 146 | // |
---|
| 147 | // This ensures the compiler takes THIS template if the header-file of the super-function |
---|
| 148 | // is included. In any other case, the compiler just uses the fallback template which is |
---|
| 149 | // defined in this file. |
---|
| 150 | template <class T, templatehack2> |
---|
| 151 | struct SuperFunctionCondition<functionnumber, T, 0, templatehack2> |
---|
| 152 | { |
---|
| 153 | static void check() |
---|
| 154 | { |
---|
| 155 | // This call to the apply-function is the whole check. By calling the function with |
---|
| 156 | // a T* pointer, the right function get's called. |
---|
[3301] | 157 | SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(0)); |
---|
[1684] | 158 | |
---|
| 159 | // Go go the check for of next super-function (functionnumber + 1) |
---|
| 160 | SuperFunctionCondition<functionnumber + 1, T, 0, templatehack2>::check(); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // This function gets called if T is not a child of the baseclass. |
---|
| 164 | // The function does nothing. |
---|
| 165 | static void apply(void* temp) {} |
---|
| 166 | |
---|
| 167 | // This function gets called if T is a child of the baseclass and can therefore be converted. |
---|
| 168 | // The function adds a SuperFunctionCaller to the Identifier of all subclasses of T. |
---|
| 169 | static void apply(baseclass* temp) |
---|
| 170 | { |
---|
| 171 | ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); |
---|
| 172 | |
---|
| 173 | // Iterate through all children |
---|
| 174 | for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) |
---|
| 175 | { |
---|
[2662] | 176 | // Check if the caller is a fallback-caller |
---|
| 177 | if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) |
---|
| 178 | { |
---|
| 179 | // Delete the fallback caller an prepare to get a real caller |
---|
| 180 | delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; |
---|
| 181 | ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; |
---|
| 182 | ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; |
---|
| 183 | } |
---|
| 184 | |
---|
[1684] | 185 | // Check if there's not already a caller |
---|
| 186 | if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) |
---|
| 187 | { |
---|
| 188 | // Add the SuperFunctionCaller |
---|
| 189 | COUT(5) << "adding functionpointer to " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl; |
---|
| 190 | ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | }; |
---|
| 195 | SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND##purevirtualbase |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | // The following piece of code is only added if purevirtualbase = true |
---|
| 199 | |
---|
| 200 | // Explicit specialization of the Condition template for the baseclass to avoid |
---|
| 201 | // errors if the function is pure virtual in the baseclass. |
---|
| 202 | template <int templatehack2> \ |
---|
| 203 | struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \ |
---|
| 204 | { \ |
---|
[2662] | 205 | // The check function acts like the fallback - it advances to the check for the next super-function (functionnumber + 1) |
---|
[1684] | 206 | static void check() \ |
---|
| 207 | { \ |
---|
| 208 | SuperFunctionCondition<functionnumber + 1, baseclass, 0, templatehack2>::check(); \ |
---|
| 209 | } \ |
---|
| 210 | }; |
---|
| 211 | */ |
---|
| 212 | |
---|
| 213 | // SUPER-macro: Calls Parent::functionname() where Parent is the direct parent of classname |
---|
[3325] | 214 | #ifdef ORXONOX_COMPILER_MSVC |
---|
| 215 | #define SUPER(classname, functionname, ...) \ |
---|
| 216 | __super::functionname(__VA_ARGS__) |
---|
| 217 | #else |
---|
| 218 | #define SUPER(classname, functionname, ...) \ |
---|
| 219 | SUPER_##functionname(classname, functionname, __VA_ARGS__) |
---|
| 220 | #endif |
---|
[1684] | 221 | |
---|
| 222 | // helper macro: for functions without arguments |
---|
| 223 | #define SUPER_NOARGS(classname, functionname) \ |
---|
| 224 | (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this) |
---|
| 225 | |
---|
| 226 | // helper macro: for functions with arguments |
---|
| 227 | #define SUPER_ARGS(classname, functionname, ...) \ |
---|
| 228 | (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this, __VA_ARGS__) |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | //// Function-specific macros //// |
---|
| 232 | |
---|
| 233 | /* |
---|
| 234 | Add a macro for each super-function |
---|
| 235 | |
---|
| 236 | Example (no arguments): |
---|
| 237 | #define SUPER_myfunction(classname, functionname, ...) \ |
---|
| 238 | SUPER_NOARGS(classname, functionname) |
---|
| 239 | |
---|
| 240 | Example (with arguments): |
---|
| 241 | #define SUPER_myfunction(classname, functionname, ...) \ |
---|
| 242 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
| 243 | */ |
---|
| 244 | |
---|
[1687] | 245 | // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
[1684] | 246 | #define SUPER_XMLPort(classname, functionname, ...) \ |
---|
| 247 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
| 248 | |
---|
| 249 | #define SUPER_tick(classname, functionname, ...) \ |
---|
| 250 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
| 251 | |
---|
| 252 | #define SUPER_changedActivity(classname, functionname, ...) \ |
---|
| 253 | SUPER_NOARGS(classname, functionname) |
---|
| 254 | |
---|
| 255 | #define SUPER_changedVisibility(classname, functionname, ...) \ |
---|
| 256 | SUPER_NOARGS(classname, functionname) |
---|
[2087] | 257 | |
---|
[5929] | 258 | #define SUPER_XMLEventPort(classname, functionname, ...) \ |
---|
[2087] | 259 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
[2662] | 260 | |
---|
| 261 | #define SUPER_changedScale(classname, functionname, ...) \ |
---|
| 262 | SUPER_NOARGS(classname, functionname) |
---|
| 263 | |
---|
| 264 | #define SUPER_changedOwner(classname, functionname, ...) \ |
---|
| 265 | SUPER_NOARGS(classname, functionname) |
---|
| 266 | |
---|
| 267 | #define SUPER_changedOverlayGroup(classname, functionname, ...) \ |
---|
| 268 | SUPER_NOARGS(classname, functionname) |
---|
| 269 | |
---|
| 270 | #define SUPER_changedName(classname, functionname, ...) \ |
---|
| 271 | SUPER_NOARGS(classname, functionname) |
---|
| 272 | |
---|
| 273 | #define SUPER_changedGametype(classname, functionname, ...) \ |
---|
| 274 | SUPER_NOARGS(classname, functionname) |
---|
[7163] | 275 | |
---|
[6524] | 276 | #define SUPER_changedUsed(classname, functionname, ...) \ |
---|
| 277 | SUPER_NOARGS(classname, functionname) |
---|
[7163] | 278 | |
---|
[6524] | 279 | #define SUPER_clone(classname, functionname, ...) \ |
---|
| 280 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
[7163] | 281 | |
---|
[6524] | 282 | #define SUPER_changedCarrier(classname, functionname, ...) \ |
---|
| 283 | SUPER_NOARGS(classname, functionname) |
---|
[7163] | 284 | |
---|
[6524] | 285 | #define SUPER_changedPickedUp(classname, functionname, ...) \ |
---|
| 286 | SUPER_NOARGS(classname, functionname) |
---|
[7163] | 287 | |
---|
[1687] | 288 | // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
[1684] | 289 | |
---|
| 290 | |
---|
[1679] | 291 | namespace orxonox |
---|
| 292 | { |
---|
[1684] | 293 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 294 | // This code gets included by Identifier.h and every other header file that needs a super-function // |
---|
| 295 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[1679] | 296 | |
---|
[1684] | 297 | //// Common code //// |
---|
[1679] | 298 | |
---|
[1687] | 299 | // Base templates |
---|
| 300 | /** |
---|
| 301 | @brief Creates the SuperFunctionCaller if T is a child of the super-functions baseclass. |
---|
| 302 | */ |
---|
[1684] | 303 | template <int functionnumber, class T, int templatehack1, int templatehack2> |
---|
| 304 | struct SuperFunctionCondition |
---|
[1679] | 305 | { |
---|
[1684] | 306 | static void check() {} |
---|
| 307 | }; |
---|
[1679] | 308 | |
---|
[1687] | 309 | /** |
---|
| 310 | @brief Initializes the SuperFunctionCaller-pointer with zero. |
---|
| 311 | */ |
---|
| 312 | template <int functionnumber, class T> |
---|
| 313 | struct SuperFunctionInitialization |
---|
| 314 | { |
---|
| 315 | static void initialize(ClassIdentifier<T>* identifier) {} |
---|
| 316 | }; |
---|
[1679] | 317 | |
---|
[1687] | 318 | /** |
---|
| 319 | @brief Deletes the SuperFunctionCaller. |
---|
| 320 | */ |
---|
| 321 | template <int functionnumber, class T> |
---|
| 322 | struct SuperFunctionDestruction |
---|
| 323 | { |
---|
| 324 | static void destroy(ClassIdentifier<T>* identifier) {} |
---|
| 325 | }; |
---|
| 326 | |
---|
| 327 | |
---|
[1684] | 328 | //// Function-specific code //// |
---|
| 329 | |
---|
| 330 | /** |
---|
| 331 | @brief Creates the needed objects and templates to call a super-function. |
---|
| 332 | @param functionnumber Each super-function needs a unique number, starting with zero, increasing by one |
---|
| 333 | @param functionname The name of the super-function |
---|
| 334 | @param hasarguments "false" if the function doesn't take any arguments, "true" if it does (without "") |
---|
| 335 | @param ... Variadic: If the function takes arguments, add them here with type and name. Example: int myvalue, float myothervalue |
---|
| 336 | */ |
---|
| 337 | #define SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(functionnumber, functionname, hasarguments, ...) \ |
---|
| 338 | template <class T, int templatehack1, int templatehack2> \ |
---|
| 339 | struct SuperFunctionCondition<functionnumber, T, templatehack1, templatehack2> \ |
---|
| 340 | { \ |
---|
| 341 | static void check() \ |
---|
| 342 | { \ |
---|
| 343 | SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); \ |
---|
| 344 | } \ |
---|
| 345 | }; \ |
---|
| 346 | \ |
---|
[2662] | 347 | class _CoreExport SuperFunctionCaller_##functionname \ |
---|
| 348 | { \ |
---|
| 349 | public: \ |
---|
| 350 | virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \ |
---|
| 351 | virtual ~SuperFunctionCaller_##functionname () {} \ |
---|
| 352 | }; \ |
---|
| 353 | \ |
---|
[1687] | 354 | template <class T> \ |
---|
[2662] | 355 | class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname \ |
---|
| 356 | { \ |
---|
| 357 | public: \ |
---|
| 358 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \ |
---|
| 359 | { \ |
---|
| 360 | } \ |
---|
| 361 | }; \ |
---|
| 362 | \ |
---|
| 363 | template <class T> \ |
---|
[1687] | 364 | struct SuperFunctionInitialization<functionnumber, T> \ |
---|
| 365 | { \ |
---|
| 366 | static void initialize(ClassIdentifier<T>* identifier) \ |
---|
| 367 | { \ |
---|
[2662] | 368 | identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; \ |
---|
| 369 | identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; \ |
---|
[1687] | 370 | SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \ |
---|
| 371 | } \ |
---|
| 372 | }; \ |
---|
| 373 | \ |
---|
| 374 | template <class T> \ |
---|
| 375 | struct SuperFunctionDestruction<functionnumber, T> \ |
---|
| 376 | { \ |
---|
| 377 | static void destroy(ClassIdentifier<T>* identifier) \ |
---|
| 378 | { \ |
---|
| 379 | if (identifier->superFunctionCaller_##functionname##_) \ |
---|
| 380 | delete identifier->superFunctionCaller_##functionname##_; \ |
---|
| 381 | SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); \ |
---|
| 382 | } \ |
---|
| 383 | }; \ |
---|
| 384 | \ |
---|
[1684] | 385 | template <class T> \ |
---|
| 386 | class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \ |
---|
| 387 | { \ |
---|
| 388 | public: \ |
---|
| 389 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \ |
---|
| 390 | { \ |
---|
| 391 | (dynamic_cast<T*>(object))->T:: functionname |
---|
| 392 | |
---|
| 393 | /* |
---|
| 394 | JUST ADD THE FUNCTION ARGUMENTS BETWEEN BOTH MACROS, ENCLOSED BY BRACKETS |
---|
| 395 | EXAMPLE: |
---|
| 396 | |
---|
| 397 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, myfunction, true, int myvalue, float myothervalue) <-- !!! DONT ADD A SEMICOLON HERE !!! |
---|
| 398 | (myvalue, myothervalue) |
---|
| 399 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2 |
---|
| 400 | */ |
---|
| 401 | |
---|
| 402 | #define SUPER_FUNCTION_GLOBAL_DECLARATION_PART2 \ |
---|
| 403 | ; \ |
---|
| 404 | } \ |
---|
| 405 | }; |
---|
| 406 | |
---|
| 407 | #define SUPER_CALL_ARGUMENTSfalse(...) OrxonoxClass* object |
---|
| 408 | #define SUPER_CALL_ARGUMENTS0(...) OrxonoxClass* object |
---|
| 409 | #define SUPER_CALL_ARGUMENTStrue(...) OrxonoxClass* object, __VA_ARGS__ |
---|
| 410 | #define SUPER_CALL_ARGUMENTS1(...) OrxonoxClass* object, __VA_ARGS__ |
---|
| 411 | |
---|
| 412 | |
---|
| 413 | /* |
---|
| 414 | //// COMMENTS ABOUT THE MACRO //// |
---|
| 415 | |
---|
| 416 | // Partially specialized template (templatehack not yet specialized, this |
---|
| 417 | // will be done by the real condition in the header-file of the super-function) |
---|
| 418 | // Only used as fallback |
---|
| 419 | template <class T, int templatehack1, int templatehack2> |
---|
| 420 | struct SuperFunctionCondition<functionnumber, T, templatehack1, templatehack2> |
---|
| 421 | { |
---|
| 422 | // If this function gets called, the header-file of the super function is not |
---|
| 423 | // included, so this fallback template (templatehack not specialized) is used |
---|
| 424 | static void check() |
---|
[1679] | 425 | { |
---|
[1684] | 426 | // Calls the condition-check of the next super-function (functionnumber + 1) |
---|
| 427 | SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); |
---|
[1679] | 428 | } |
---|
[1684] | 429 | }; |
---|
| 430 | |
---|
[2662] | 431 | // Baseclass of the super-function caller. The real call will be done by a |
---|
| 432 | // templatized subclass through the virtual () operator. |
---|
| 433 | class _CoreExport SuperFunctionCaller_##functionname |
---|
| 434 | { |
---|
| 435 | public: |
---|
| 436 | virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; |
---|
| 437 | virtual ~SuperFunctionCaller_##functionname () {} |
---|
| 438 | }; |
---|
| 439 | |
---|
| 440 | // Fallback if the base is pure virtual |
---|
[1687] | 441 | template <class T> |
---|
[2662] | 442 | class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname |
---|
| 443 | { |
---|
| 444 | public: |
---|
| 445 | // Fallback does nothing |
---|
| 446 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) |
---|
| 447 | { |
---|
| 448 | } |
---|
| 449 | }; |
---|
| 450 | |
---|
| 451 | // Initializes the SuperFunctionCaller-pointer with a fallback caller in case the base function is pure virtual |
---|
| 452 | template <class T> |
---|
[1687] | 453 | struct SuperFunctionInitialization<functionnumber, T> |
---|
| 454 | { |
---|
| 455 | static void initialize(ClassIdentifier<T>* identifier) |
---|
| 456 | { |
---|
[2662] | 457 | identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; |
---|
| 458 | identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; |
---|
[1687] | 459 | |
---|
| 460 | // Calls the initialization of the next super-function (functionnumber + 1) |
---|
| 461 | SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); |
---|
| 462 | } |
---|
| 463 | }; |
---|
| 464 | |
---|
| 465 | // Deletes the SuperFunctionCaller. |
---|
| 466 | template <class T> |
---|
| 467 | struct SuperFunctionDestruction<functionnumber, T> |
---|
| 468 | { |
---|
| 469 | static void destroy(ClassIdentifier<T>* identifier) |
---|
| 470 | { |
---|
| 471 | if (identifier->superFunctionCaller_##functionname##_) |
---|
| 472 | delete identifier->superFunctionCaller_##functionname##_; |
---|
| 473 | |
---|
| 474 | // Calls the destruction of the next super-function (functionnumber + 1) |
---|
| 475 | SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); |
---|
| 476 | } |
---|
| 477 | }; |
---|
| 478 | |
---|
[1684] | 479 | // The real super-function caller: Calls T::functionname() |
---|
| 480 | // T should be the parent, but this will be done by the spezialized condition template |
---|
| 481 | template <class T> |
---|
| 482 | class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname |
---|
| 483 | { |
---|
| 484 | public: |
---|
| 485 | // @brief Calls the function. |
---|
| 486 | // @param object The object to call the function on |
---|
| 487 | // @param ... The arguments of the function |
---|
| 488 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) |
---|
| 489 | { |
---|
| 490 | (dynamic_cast<T*>(object))->T:: functionname ( Call the function with it's arguments ); |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | */ |
---|
| 494 | |
---|
[1687] | 495 | |
---|
[1684] | 496 | //// Execute the code for each super-function //// |
---|
[1687] | 497 | |
---|
| 498 | // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
[1736] | 499 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, XMLPort, true, Element& xmlelement, XMLPort::Mode mode) |
---|
[1684] | 500 | (xmlelement, mode) |
---|
| 501 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 502 | |
---|
[1736] | 503 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(1, tick, true, float dt) |
---|
[1684] | 504 | (dt) |
---|
| 505 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 506 | |
---|
[1736] | 507 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(2, changedActivity, false) |
---|
[1684] | 508 | () |
---|
| 509 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 510 | |
---|
[1736] | 511 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(3, changedVisibility, false) |
---|
[1684] | 512 | () |
---|
| 513 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
[2087] | 514 | |
---|
[5929] | 515 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, XMLEventPort, true, Element& xmlelement, XMLPort::Mode mode) |
---|
| 516 | (xmlelement, mode) |
---|
[2087] | 517 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
[2662] | 518 | |
---|
| 519 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(5, changedScale, false) |
---|
| 520 | () |
---|
| 521 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 522 | |
---|
[5929] | 523 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedOwner, false) |
---|
[2662] | 524 | () |
---|
| 525 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 526 | |
---|
[5929] | 527 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOverlayGroup, false) |
---|
[2662] | 528 | () |
---|
| 529 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 530 | |
---|
[5929] | 531 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedName, false) |
---|
[2662] | 532 | () |
---|
| 533 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 534 | |
---|
[5929] | 535 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedGametype, false) |
---|
[2662] | 536 | () |
---|
| 537 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
[7163] | 538 | |
---|
[6524] | 539 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedUsed, false) |
---|
| 540 | () |
---|
| 541 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 542 | |
---|
| 543 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(11, clone, true, OrxonoxClass* item) |
---|
| 544 | (item) |
---|
| 545 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
[7163] | 546 | |
---|
[6524] | 547 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false) |
---|
| 548 | () |
---|
| 549 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
[7163] | 550 | |
---|
[6524] | 551 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(13, changedPickedUp, false) |
---|
| 552 | () |
---|
| 553 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
| 554 | |
---|
[1687] | 555 | // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
[1684] | 556 | |
---|
[1679] | 557 | } |
---|
| 558 | |
---|
| 559 | #else /* _Super_H__ */ |
---|
[1684] | 560 | #ifdef SUPER_INTRUSIVE_DECLARATION_INCLUDE |
---|
[1679] | 561 | |
---|
[1684] | 562 | ////////////////////////////////////////////////////////////////////////// |
---|
| 563 | // This code gets included within the declaration of ClassIdentifier<T> // |
---|
| 564 | ////////////////////////////////////////////////////////////////////////// |
---|
[1679] | 565 | |
---|
[1684] | 566 | //// Common code //// |
---|
[1679] | 567 | |
---|
[1684] | 568 | private: |
---|
[1687] | 569 | |
---|
[1684] | 570 | template <int functionnumber, class TT, int templatehack1, int templatehack2> |
---|
| 571 | friend struct SuperFunctionCondition; |
---|
[1679] | 572 | |
---|
[1684] | 573 | // Creates the super-function-callers by calling the first SuperFunctionCondition check |
---|
| 574 | // This get's called within the initialization of an Identifier |
---|
| 575 | virtual void createSuperFunctionCaller() const |
---|
| 576 | { |
---|
| 577 | SuperFunctionCondition<0, T, 0, 0>::check(); |
---|
| 578 | } |
---|
[1679] | 579 | |
---|
| 580 | |
---|
[1684] | 581 | //// Function-specific code //// |
---|
| 582 | |
---|
| 583 | public: |
---|
| 584 | /** |
---|
| 585 | @brief Adds a pointer to the SuperFunctionCaller as a member of ClassIdentifier. |
---|
| 586 | @param functionname The name of the super-function |
---|
| 587 | */ |
---|
| 588 | #ifndef SUPER_INTRUSIVE_DECLARATION |
---|
| 589 | #define SUPER_INTRUSIVE_DECLARATION(functionname) \ |
---|
[2662] | 590 | SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_; \ |
---|
| 591 | bool bSuperFunctionCaller_##functionname##_isFallback_ |
---|
[1684] | 592 | #endif |
---|
| 593 | |
---|
| 594 | |
---|
| 595 | //// Execute the code for each super-function //// |
---|
[1687] | 596 | |
---|
| 597 | // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
[1684] | 598 | SUPER_INTRUSIVE_DECLARATION(XMLPort); |
---|
| 599 | SUPER_INTRUSIVE_DECLARATION(tick); |
---|
| 600 | SUPER_INTRUSIVE_DECLARATION(changedActivity); |
---|
| 601 | SUPER_INTRUSIVE_DECLARATION(changedVisibility); |
---|
[5929] | 602 | SUPER_INTRUSIVE_DECLARATION(XMLEventPort); |
---|
[2662] | 603 | SUPER_INTRUSIVE_DECLARATION(changedScale); |
---|
| 604 | SUPER_INTRUSIVE_DECLARATION(changedOwner); |
---|
| 605 | SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup); |
---|
| 606 | SUPER_INTRUSIVE_DECLARATION(changedName); |
---|
| 607 | SUPER_INTRUSIVE_DECLARATION(changedGametype); |
---|
[6524] | 608 | SUPER_INTRUSIVE_DECLARATION(changedUsed); |
---|
| 609 | SUPER_INTRUSIVE_DECLARATION(clone); |
---|
| 610 | SUPER_INTRUSIVE_DECLARATION(changedCarrier); |
---|
| 611 | SUPER_INTRUSIVE_DECLARATION(changedPickedUp); |
---|
[1687] | 612 | // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
[1684] | 613 | |
---|
| 614 | |
---|
| 615 | #undef SUPER_INTRUSIVE_DECLARATION_INCLUDE |
---|
| 616 | #endif /* SUPER_INTRUSIVE_DECLARATION_INCLUDE */ |
---|
[1679] | 617 | #endif /* _Super_H__ */ |
---|