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