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((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((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 | #define SUPER(classname, functionname, ...) \ |
---|
209 | SUPER_##functionname(classname, functionname, __VA_ARGS__) |
---|
210 | |
---|
211 | // helper macro: for functions without arguments |
---|
212 | #define SUPER_NOARGS(classname, functionname) \ |
---|
213 | (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this) |
---|
214 | |
---|
215 | // helper macro: for functions with arguments |
---|
216 | #define SUPER_ARGS(classname, functionname, ...) \ |
---|
217 | (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this, __VA_ARGS__) |
---|
218 | |
---|
219 | |
---|
220 | //// Function-specific macros //// |
---|
221 | |
---|
222 | /* |
---|
223 | Add a macro for each super-function |
---|
224 | |
---|
225 | Example (no arguments): |
---|
226 | #define SUPER_myfunction(classname, functionname, ...) \ |
---|
227 | SUPER_NOARGS(classname, functionname) |
---|
228 | |
---|
229 | Example (with arguments): |
---|
230 | #define SUPER_myfunction(classname, functionname, ...) \ |
---|
231 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
232 | */ |
---|
233 | |
---|
234 | // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
235 | #define SUPER_XMLPort(classname, functionname, ...) \ |
---|
236 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
237 | |
---|
238 | #define SUPER_tick(classname, functionname, ...) \ |
---|
239 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
240 | |
---|
241 | #define SUPER_changedActivity(classname, functionname, ...) \ |
---|
242 | SUPER_NOARGS(classname, functionname) |
---|
243 | |
---|
244 | #define SUPER_changedVisibility(classname, functionname, ...) \ |
---|
245 | SUPER_NOARGS(classname, functionname) |
---|
246 | |
---|
247 | #define SUPER_processEvent(classname, functionname, ...) \ |
---|
248 | SUPER_ARGS(classname, functionname, __VA_ARGS__) |
---|
249 | |
---|
250 | #define SUPER_changedScale(classname, functionname, ...) \ |
---|
251 | SUPER_NOARGS(classname, functionname) |
---|
252 | |
---|
253 | #define SUPER_changedMainState(classname, functionname, ...) \ |
---|
254 | SUPER_NOARGS(classname, functionname) |
---|
255 | |
---|
256 | #define SUPER_changedOwner(classname, functionname, ...) \ |
---|
257 | SUPER_NOARGS(classname, functionname) |
---|
258 | |
---|
259 | #define SUPER_changedOverlayGroup(classname, functionname, ...) \ |
---|
260 | SUPER_NOARGS(classname, functionname) |
---|
261 | |
---|
262 | #define SUPER_changedName(classname, functionname, ...) \ |
---|
263 | SUPER_NOARGS(classname, functionname) |
---|
264 | |
---|
265 | #define SUPER_changedGametype(classname, functionname, ...) \ |
---|
266 | SUPER_NOARGS(classname, functionname) |
---|
267 | // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
268 | |
---|
269 | |
---|
270 | namespace orxonox |
---|
271 | { |
---|
272 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
273 | // This code gets included by Identifier.h and every other header file that needs a super-function // |
---|
274 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
275 | |
---|
276 | //// Common code //// |
---|
277 | |
---|
278 | // Base templates |
---|
279 | /** |
---|
280 | @brief Creates the SuperFunctionCaller if T is a child of the super-functions baseclass. |
---|
281 | */ |
---|
282 | template <int functionnumber, class T, int templatehack1, int templatehack2> |
---|
283 | struct SuperFunctionCondition |
---|
284 | { |
---|
285 | static void check() {} |
---|
286 | }; |
---|
287 | |
---|
288 | /** |
---|
289 | @brief Initializes the SuperFunctionCaller-pointer with zero. |
---|
290 | */ |
---|
291 | template <int functionnumber, class T> |
---|
292 | struct SuperFunctionInitialization |
---|
293 | { |
---|
294 | static void initialize(ClassIdentifier<T>* identifier) {} |
---|
295 | }; |
---|
296 | |
---|
297 | /** |
---|
298 | @brief Deletes the SuperFunctionCaller. |
---|
299 | */ |
---|
300 | template <int functionnumber, class T> |
---|
301 | struct SuperFunctionDestruction |
---|
302 | { |
---|
303 | static void destroy(ClassIdentifier<T>* identifier) {} |
---|
304 | }; |
---|
305 | |
---|
306 | |
---|
307 | //// Function-specific code //// |
---|
308 | |
---|
309 | /** |
---|
310 | @brief Creates the needed objects and templates to call a super-function. |
---|
311 | @param functionnumber Each super-function needs a unique number, starting with zero, increasing by one |
---|
312 | @param functionname The name of the super-function |
---|
313 | @param hasarguments "false" if the function doesn't take any arguments, "true" if it does (without "") |
---|
314 | @param ... Variadic: If the function takes arguments, add them here with type and name. Example: int myvalue, float myothervalue |
---|
315 | */ |
---|
316 | #define SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(functionnumber, functionname, hasarguments, ...) \ |
---|
317 | template <class T, int templatehack1, int templatehack2> \ |
---|
318 | struct SuperFunctionCondition<functionnumber, T, templatehack1, templatehack2> \ |
---|
319 | { \ |
---|
320 | static void check() \ |
---|
321 | { \ |
---|
322 | SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); \ |
---|
323 | } \ |
---|
324 | }; \ |
---|
325 | \ |
---|
326 | class _CoreExport SuperFunctionCaller_##functionname \ |
---|
327 | { \ |
---|
328 | public: \ |
---|
329 | virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \ |
---|
330 | virtual ~SuperFunctionCaller_##functionname () {} \ |
---|
331 | }; \ |
---|
332 | \ |
---|
333 | template <class T> \ |
---|
334 | class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname \ |
---|
335 | { \ |
---|
336 | public: \ |
---|
337 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \ |
---|
338 | { \ |
---|
339 | } \ |
---|
340 | }; \ |
---|
341 | \ |
---|
342 | template <class T> \ |
---|
343 | struct SuperFunctionInitialization<functionnumber, T> \ |
---|
344 | { \ |
---|
345 | static void initialize(ClassIdentifier<T>* identifier) \ |
---|
346 | { \ |
---|
347 | identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; \ |
---|
348 | identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; \ |
---|
349 | SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \ |
---|
350 | } \ |
---|
351 | }; \ |
---|
352 | \ |
---|
353 | template <class T> \ |
---|
354 | struct SuperFunctionDestruction<functionnumber, T> \ |
---|
355 | { \ |
---|
356 | static void destroy(ClassIdentifier<T>* identifier) \ |
---|
357 | { \ |
---|
358 | if (identifier->superFunctionCaller_##functionname##_) \ |
---|
359 | delete identifier->superFunctionCaller_##functionname##_; \ |
---|
360 | SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); \ |
---|
361 | } \ |
---|
362 | }; \ |
---|
363 | \ |
---|
364 | template <class T> \ |
---|
365 | class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \ |
---|
366 | { \ |
---|
367 | public: \ |
---|
368 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \ |
---|
369 | { \ |
---|
370 | (dynamic_cast<T*>(object))->T:: functionname |
---|
371 | |
---|
372 | /* |
---|
373 | JUST ADD THE FUNCTION ARGUMENTS BETWEEN BOTH MACROS, ENCLOSED BY BRACKETS |
---|
374 | EXAMPLE: |
---|
375 | |
---|
376 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, myfunction, true, int myvalue, float myothervalue) <-- !!! DONT ADD A SEMICOLON HERE !!! |
---|
377 | (myvalue, myothervalue) |
---|
378 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2 |
---|
379 | */ |
---|
380 | |
---|
381 | #define SUPER_FUNCTION_GLOBAL_DECLARATION_PART2 \ |
---|
382 | ; \ |
---|
383 | } \ |
---|
384 | }; |
---|
385 | |
---|
386 | #define SUPER_CALL_ARGUMENTSfalse(...) OrxonoxClass* object |
---|
387 | #define SUPER_CALL_ARGUMENTS0(...) OrxonoxClass* object |
---|
388 | #define SUPER_CALL_ARGUMENTStrue(...) OrxonoxClass* object, __VA_ARGS__ |
---|
389 | #define SUPER_CALL_ARGUMENTS1(...) OrxonoxClass* object, __VA_ARGS__ |
---|
390 | |
---|
391 | |
---|
392 | /* |
---|
393 | //// COMMENTS ABOUT THE MACRO //// |
---|
394 | |
---|
395 | // Partially specialized template (templatehack not yet specialized, this |
---|
396 | // will be done by the real condition in the header-file of the super-function) |
---|
397 | // Only used as fallback |
---|
398 | template <class T, int templatehack1, int templatehack2> |
---|
399 | struct SuperFunctionCondition<functionnumber, T, templatehack1, templatehack2> |
---|
400 | { |
---|
401 | // If this function gets called, the header-file of the super function is not |
---|
402 | // included, so this fallback template (templatehack not specialized) is used |
---|
403 | static void check() |
---|
404 | { |
---|
405 | // Calls the condition-check of the next super-function (functionnumber + 1) |
---|
406 | SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); |
---|
407 | } |
---|
408 | }; |
---|
409 | |
---|
410 | // Baseclass of the super-function caller. The real call will be done by a |
---|
411 | // templatized subclass through the virtual () operator. |
---|
412 | class _CoreExport SuperFunctionCaller_##functionname |
---|
413 | { |
---|
414 | public: |
---|
415 | virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; |
---|
416 | virtual ~SuperFunctionCaller_##functionname () {} |
---|
417 | }; |
---|
418 | |
---|
419 | // Fallback if the base is pure virtual |
---|
420 | template <class T> |
---|
421 | class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname |
---|
422 | { |
---|
423 | public: |
---|
424 | // Fallback does nothing |
---|
425 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) |
---|
426 | { |
---|
427 | } |
---|
428 | }; |
---|
429 | |
---|
430 | // Initializes the SuperFunctionCaller-pointer with a fallback caller in case the base function is pure virtual |
---|
431 | template <class T> |
---|
432 | struct SuperFunctionInitialization<functionnumber, T> |
---|
433 | { |
---|
434 | static void initialize(ClassIdentifier<T>* identifier) |
---|
435 | { |
---|
436 | identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; |
---|
437 | identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; |
---|
438 | |
---|
439 | // Calls the initialization of the next super-function (functionnumber + 1) |
---|
440 | SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); |
---|
441 | } |
---|
442 | }; |
---|
443 | |
---|
444 | // Deletes the SuperFunctionCaller. |
---|
445 | template <class T> |
---|
446 | struct SuperFunctionDestruction<functionnumber, T> |
---|
447 | { |
---|
448 | static void destroy(ClassIdentifier<T>* identifier) |
---|
449 | { |
---|
450 | if (identifier->superFunctionCaller_##functionname##_) |
---|
451 | delete identifier->superFunctionCaller_##functionname##_; |
---|
452 | |
---|
453 | // Calls the destruction of the next super-function (functionnumber + 1) |
---|
454 | SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); |
---|
455 | } |
---|
456 | }; |
---|
457 | |
---|
458 | // The real super-function caller: Calls T::functionname() |
---|
459 | // T should be the parent, but this will be done by the spezialized condition template |
---|
460 | template <class T> |
---|
461 | class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname |
---|
462 | { |
---|
463 | public: |
---|
464 | // @brief Calls the function. |
---|
465 | // @param object The object to call the function on |
---|
466 | // @param ... The arguments of the function |
---|
467 | inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) |
---|
468 | { |
---|
469 | (dynamic_cast<T*>(object))->T:: functionname ( Call the function with it's arguments ); |
---|
470 | } |
---|
471 | } |
---|
472 | */ |
---|
473 | |
---|
474 | |
---|
475 | //// Execute the code for each super-function //// |
---|
476 | |
---|
477 | // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
478 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, XMLPort, true, Element& xmlelement, XMLPort::Mode mode) |
---|
479 | (xmlelement, mode) |
---|
480 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
481 | |
---|
482 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(1, tick, true, float dt) |
---|
483 | (dt) |
---|
484 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
485 | |
---|
486 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(2, changedActivity, false) |
---|
487 | () |
---|
488 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
489 | |
---|
490 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(3, changedVisibility, false) |
---|
491 | () |
---|
492 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
493 | |
---|
494 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, processEvent, true, Event& event) |
---|
495 | (event) |
---|
496 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
497 | |
---|
498 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(5, changedScale, false) |
---|
499 | () |
---|
500 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
501 | |
---|
502 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false) |
---|
503 | () |
---|
504 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
505 | |
---|
506 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOwner, false) |
---|
507 | () |
---|
508 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
509 | |
---|
510 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedOverlayGroup, false) |
---|
511 | () |
---|
512 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
513 | |
---|
514 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false) |
---|
515 | () |
---|
516 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
517 | |
---|
518 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false) |
---|
519 | () |
---|
520 | SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; |
---|
521 | // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
522 | |
---|
523 | } |
---|
524 | |
---|
525 | #else /* _Super_H__ */ |
---|
526 | #ifdef SUPER_INTRUSIVE_DECLARATION_INCLUDE |
---|
527 | |
---|
528 | ////////////////////////////////////////////////////////////////////////// |
---|
529 | // This code gets included within the declaration of ClassIdentifier<T> // |
---|
530 | ////////////////////////////////////////////////////////////////////////// |
---|
531 | |
---|
532 | //// Common code //// |
---|
533 | |
---|
534 | private: |
---|
535 | |
---|
536 | template <int functionnumber, class TT, int templatehack1, int templatehack2> |
---|
537 | friend struct SuperFunctionCondition; |
---|
538 | |
---|
539 | // Creates the super-function-callers by calling the first SuperFunctionCondition check |
---|
540 | // This get's called within the initialization of an Identifier |
---|
541 | virtual void createSuperFunctionCaller() const |
---|
542 | { |
---|
543 | SuperFunctionCondition<0, T, 0, 0>::check(); |
---|
544 | } |
---|
545 | |
---|
546 | |
---|
547 | //// Function-specific code //// |
---|
548 | |
---|
549 | public: |
---|
550 | /** |
---|
551 | @brief Adds a pointer to the SuperFunctionCaller as a member of ClassIdentifier. |
---|
552 | @param functionname The name of the super-function |
---|
553 | */ |
---|
554 | #ifndef SUPER_INTRUSIVE_DECLARATION |
---|
555 | #define SUPER_INTRUSIVE_DECLARATION(functionname) \ |
---|
556 | SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_; \ |
---|
557 | bool bSuperFunctionCaller_##functionname##_isFallback_ |
---|
558 | #endif |
---|
559 | |
---|
560 | |
---|
561 | //// Execute the code for each super-function //// |
---|
562 | |
---|
563 | // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
564 | SUPER_INTRUSIVE_DECLARATION(XMLPort); |
---|
565 | SUPER_INTRUSIVE_DECLARATION(tick); |
---|
566 | SUPER_INTRUSIVE_DECLARATION(changedActivity); |
---|
567 | SUPER_INTRUSIVE_DECLARATION(changedVisibility); |
---|
568 | SUPER_INTRUSIVE_DECLARATION(processEvent); |
---|
569 | SUPER_INTRUSIVE_DECLARATION(changedScale); |
---|
570 | SUPER_INTRUSIVE_DECLARATION(changedMainState); |
---|
571 | SUPER_INTRUSIVE_DECLARATION(changedOwner); |
---|
572 | SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup); |
---|
573 | SUPER_INTRUSIVE_DECLARATION(changedName); |
---|
574 | SUPER_INTRUSIVE_DECLARATION(changedGametype); |
---|
575 | // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- |
---|
576 | |
---|
577 | |
---|
578 | #undef SUPER_INTRUSIVE_DECLARATION_INCLUDE |
---|
579 | #endif /* SUPER_INTRUSIVE_DECLARATION_INCLUDE */ |
---|
580 | #endif /* _Super_H__ */ |
---|