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 | #ifndef _Super_H__ |
---|
30 | #define _Super_H__ |
---|
31 | |
---|
32 | #include <iostream> |
---|
33 | |
---|
34 | ////////////////// |
---|
35 | // Common macro // |
---|
36 | ////////////////// |
---|
37 | #define SUPER(classname, functionname, ...) \ |
---|
38 | SUPER_##functionname(classname, functionname, __VA_ARGS__) |
---|
39 | |
---|
40 | ///////////////////////////// |
---|
41 | // Function-specific macro // |
---|
42 | ///////////////////////////// |
---|
43 | #define SUPER_testfunction(classname, functionname, ...) \ |
---|
44 | (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this) |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | ///////////////// |
---|
49 | // Common code // |
---|
50 | ///////////////// |
---|
51 | class SuperDummy {}; |
---|
52 | |
---|
53 | // Base template |
---|
54 | template <int functionnumber, int templatehack, class T> |
---|
55 | struct SuperFunctionCondition |
---|
56 | { |
---|
57 | static void check() {} |
---|
58 | }; |
---|
59 | |
---|
60 | //////////////////////////// |
---|
61 | // Function-specific code // |
---|
62 | //////////////////////////// |
---|
63 | // Partially specialized template (templatehack not yet specialized, this will be done by the real condition in the header file of the super-function) |
---|
64 | template <int templatehack, class T> |
---|
65 | struct SuperFunctionCondition<0, templatehack, T> |
---|
66 | { |
---|
67 | // Calls the condition of the next super-function |
---|
68 | static void check() |
---|
69 | { |
---|
70 | std::cout << "ignore superfunction \"testfunction\" in " << ClassIdentifier<T>::getIdentifier()->getName() << std::endl; |
---|
71 | SuperFunctionCondition<0 + 1, templatehack, T>::check(); |
---|
72 | } |
---|
73 | }; |
---|
74 | |
---|
75 | class SuperFunctionCaller_testfunction |
---|
76 | { |
---|
77 | public: |
---|
78 | virtual void operator()(void* object) = 0; |
---|
79 | virtual ~SuperFunctionCaller_testfunction() {} |
---|
80 | }; |
---|
81 | |
---|
82 | template <class T> |
---|
83 | class SuperFunctionClassCaller_testfunction : public SuperFunctionCaller_testfunction |
---|
84 | { |
---|
85 | public: |
---|
86 | inline void operator()(void* object) |
---|
87 | { |
---|
88 | ((T*)object)->T::testfunction(); |
---|
89 | } |
---|
90 | }; |
---|
91 | } |
---|
92 | |
---|
93 | #else /* _Super_H__ */ |
---|
94 | #ifdef SUPER_INTRUSIVE_DECLARATION |
---|
95 | |
---|
96 | ///////////////// |
---|
97 | // Common code // |
---|
98 | ///////////////// |
---|
99 | private: |
---|
100 | template <int functionnumber, int templatehack, class TT> |
---|
101 | friend struct SuperFunctionCondition; |
---|
102 | |
---|
103 | // Creates the function pointers by calling the first SuperFunctionCondition check |
---|
104 | virtual void createSuperFunctionCaller() const |
---|
105 | { |
---|
106 | SuperFunctionCondition<0, 0, T>::check(); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | //////////////////////////// |
---|
111 | // Function-specific code // |
---|
112 | //////////////////////////// |
---|
113 | public: |
---|
114 | // The function caller |
---|
115 | SuperFunctionCaller_testfunction* superFunctionCaller_testfunction_; |
---|
116 | |
---|
117 | #undef SUPER_INTRUSIVE_DECLARATION |
---|
118 | #endif /* SUPER_INTRUSIVE_DECLARATION */ |
---|
119 | |
---|
120 | #ifdef SUPER_INTRUSIVE_CONSTRUCTOR |
---|
121 | |
---|
122 | //////////////////////////// |
---|
123 | // Function-specific code // |
---|
124 | //////////////////////////// |
---|
125 | this->superFunctionCaller_testfunction_ = 0; |
---|
126 | |
---|
127 | #undef SUPER_INTRUSIVE_CONSTRUCTOR |
---|
128 | #endif /* SUPER_INTRUSIVE_CONSTRUCTOR */ |
---|
129 | |
---|
130 | #ifdef SUPER_INTRUSIVE_DESTRUCTOR |
---|
131 | |
---|
132 | //////////////////////////// |
---|
133 | // Function-specific code // |
---|
134 | //////////////////////////// |
---|
135 | |
---|
136 | if (this->superFunctionCaller_testfunction_) |
---|
137 | delete this->superFunctionCaller_testfunction_; |
---|
138 | |
---|
139 | #undef SUPER_INTRUSIVE_DESTRUCTOR |
---|
140 | #endif /* SUPER_INTRUSIVE_DESTRUCTOR */ |
---|
141 | #endif /* _Super_H__ */ |
---|