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