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 | * Inspiration: Functor by Benjamin Grauer |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef _Functor_H__ |
---|
31 | #define _Functor_H__ |
---|
32 | |
---|
33 | #include "CorePrereqs.h" |
---|
34 | |
---|
35 | #include "util/MultiTypeMath.h" |
---|
36 | #include "Debug.h" |
---|
37 | |
---|
38 | #define MAX_FUNCTOR_ARGUMENTS 5 |
---|
39 | |
---|
40 | namespace orxonox |
---|
41 | { |
---|
42 | enum FunctionType |
---|
43 | { |
---|
44 | FT_MEMBER, |
---|
45 | FT_CONSTMEMBER, |
---|
46 | FT_STATIC |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | template <class T> |
---|
51 | inline std::string typeToString() { return "unknown"; } |
---|
52 | |
---|
53 | #define CreateTypeToStringTemplate(type) \ |
---|
54 | template <> \ |
---|
55 | inline std::string typeToString<type>() { return #type; } \ |
---|
56 | template <> \ |
---|
57 | inline std::string typeToString<type&>() { return #type; } \ |
---|
58 | template <> \ |
---|
59 | inline std::string typeToString<const type>() { return #type; } \ |
---|
60 | template <> \ |
---|
61 | inline std::string typeToString<const type&>() { return #type; } |
---|
62 | |
---|
63 | CreateTypeToStringTemplate(int); |
---|
64 | CreateTypeToStringTemplate(unsigned int); |
---|
65 | CreateTypeToStringTemplate(char); |
---|
66 | CreateTypeToStringTemplate(unsigned char); |
---|
67 | CreateTypeToStringTemplate(short); |
---|
68 | CreateTypeToStringTemplate(unsigned short); |
---|
69 | CreateTypeToStringTemplate(long); |
---|
70 | CreateTypeToStringTemplate(unsigned long); |
---|
71 | CreateTypeToStringTemplate(float); |
---|
72 | CreateTypeToStringTemplate(double); |
---|
73 | CreateTypeToStringTemplate(long double); |
---|
74 | CreateTypeToStringTemplate(bool); |
---|
75 | CreateTypeToStringTemplate(Vector2); |
---|
76 | CreateTypeToStringTemplate(Vector3); |
---|
77 | CreateTypeToStringTemplate(Quaternion); |
---|
78 | CreateTypeToStringTemplate(ColourValue); |
---|
79 | CreateTypeToStringTemplate(Radian); |
---|
80 | CreateTypeToStringTemplate(Degree); |
---|
81 | |
---|
82 | template <> \ |
---|
83 | inline std::string typeToString<std::string>() { return "string"; } \ |
---|
84 | template <> \ |
---|
85 | inline std::string typeToString<std::string&>() { return "string"; } \ |
---|
86 | template <> \ |
---|
87 | inline std::string typeToString<const std::string>() { return "string"; } \ |
---|
88 | template <> \ |
---|
89 | inline std::string typeToString<const std::string&>() { return "string"; } |
---|
90 | |
---|
91 | class _CoreExport Functor |
---|
92 | { |
---|
93 | public: |
---|
94 | Functor() {} |
---|
95 | virtual ~Functor() {} |
---|
96 | |
---|
97 | virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; |
---|
98 | |
---|
99 | inline unsigned int getParamCount() const { return this->numParams_; } |
---|
100 | inline bool hasReturnvalue() const { return this->hasReturnValue_; } |
---|
101 | inline FunctionType getType() const { return this->type_; } |
---|
102 | inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } |
---|
103 | |
---|
104 | std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; } |
---|
105 | std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } |
---|
106 | |
---|
107 | virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0; |
---|
108 | |
---|
109 | protected: |
---|
110 | unsigned int numParams_; |
---|
111 | bool hasReturnValue_; |
---|
112 | FunctionType type_; |
---|
113 | MultiTypeMath returnedValue_; |
---|
114 | |
---|
115 | std::string typeReturnvalue_; |
---|
116 | std::string typeParam_[MAX_FUNCTOR_ARGUMENTS]; |
---|
117 | }; |
---|
118 | |
---|
119 | class _CoreExport FunctorStatic : public Functor |
---|
120 | { |
---|
121 | public: |
---|
122 | virtual ~FunctorStatic() {} |
---|
123 | virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; |
---|
124 | }; |
---|
125 | |
---|
126 | template <class T> |
---|
127 | class FunctorMember : public Functor |
---|
128 | { |
---|
129 | public: |
---|
130 | FunctorMember() |
---|
131 | { |
---|
132 | constObject_ = 0; |
---|
133 | object_ = 0; |
---|
134 | bConstObject_ = false; |
---|
135 | } |
---|
136 | virtual ~FunctorMember() {} |
---|
137 | |
---|
138 | virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; |
---|
139 | virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; |
---|
140 | |
---|
141 | virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) |
---|
142 | { |
---|
143 | if (this->bConstObject_) |
---|
144 | { |
---|
145 | if (this->constObject_) |
---|
146 | (*this)(this->constObject_, param1, param2, param3, param4, param5); |
---|
147 | else |
---|
148 | { |
---|
149 | COUT(1) << "An error occurred in Functor.h:" << std::endl; |
---|
150 | COUT(1) << "Error: No const object set." << std::endl; |
---|
151 | } |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | if (this->object_) |
---|
156 | (*this)(this->object_, param1, param2, param3, param4, param5); |
---|
157 | else |
---|
158 | { |
---|
159 | COUT(1) << "An error occurred in Functor.h:" << std::endl; |
---|
160 | COUT(1) << "Error: No object set." << std::endl; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | void setObject(T* object) |
---|
166 | { |
---|
167 | this->bConstObject_ = false; |
---|
168 | this->object_ = object; |
---|
169 | } |
---|
170 | |
---|
171 | void setObject(const T* object) |
---|
172 | { |
---|
173 | this->bConstObject_ = true; |
---|
174 | this->constObject_ = object; |
---|
175 | } |
---|
176 | |
---|
177 | private: |
---|
178 | const T* constObject_; |
---|
179 | T* object_; |
---|
180 | bool bConstObject_; |
---|
181 | }; |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | #define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams |
---|
186 | #define FUNCTOR_TEMPLATE000 |
---|
187 | #define FUNCTOR_TEMPLATE001 template <class P1> |
---|
188 | #define FUNCTOR_TEMPLATE002 template <class P1, class P2> |
---|
189 | #define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3> |
---|
190 | #define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4> |
---|
191 | #define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5> |
---|
192 | #define FUNCTOR_TEMPLATE010 template <class R> |
---|
193 | #define FUNCTOR_TEMPLATE011 template <class R, class P1> |
---|
194 | #define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2> |
---|
195 | #define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3> |
---|
196 | #define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4> |
---|
197 | #define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5> |
---|
198 | #define FUNCTOR_TEMPLATE100 template <class T> |
---|
199 | #define FUNCTOR_TEMPLATE101 template <class T, class P1> |
---|
200 | #define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2> |
---|
201 | #define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3> |
---|
202 | #define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4> |
---|
203 | #define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5> |
---|
204 | #define FUNCTOR_TEMPLATE110 template <class T, class R> |
---|
205 | #define FUNCTOR_TEMPLATE111 template <class T, class R, class P1> |
---|
206 | #define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2> |
---|
207 | #define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3> |
---|
208 | #define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4> |
---|
209 | #define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5> |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | #define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams |
---|
214 | #define FUNCTOR_TEMPLATE_CLASSES000 |
---|
215 | #define FUNCTOR_TEMPLATE_CLASSES001 <P1> |
---|
216 | #define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2> |
---|
217 | #define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3> |
---|
218 | #define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4> |
---|
219 | #define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5> |
---|
220 | #define FUNCTOR_TEMPLATE_CLASSES010 <R> |
---|
221 | #define FUNCTOR_TEMPLATE_CLASSES011 <R, P1> |
---|
222 | #define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2> |
---|
223 | #define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3> |
---|
224 | #define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4> |
---|
225 | #define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5> |
---|
226 | #define FUNCTOR_TEMPLATE_CLASSES100 <T> |
---|
227 | #define FUNCTOR_TEMPLATE_CLASSES101 <T, P1> |
---|
228 | #define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2> |
---|
229 | #define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3> |
---|
230 | #define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4> |
---|
231 | #define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5> |
---|
232 | #define FUNCTOR_TEMPLATE_CLASSES110 <T, R> |
---|
233 | #define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1> |
---|
234 | #define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2> |
---|
235 | #define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3> |
---|
236 | #define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4> |
---|
237 | #define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5> |
---|
238 | |
---|
239 | |
---|
240 | |
---|
241 | #define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams |
---|
242 | #define FUNCTOR_TYPENAME_PARAMS0 |
---|
243 | #define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>(); |
---|
244 | #define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); |
---|
245 | #define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); |
---|
246 | #define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); |
---|
247 | #define FUNCTOR_TYPENAME_PARAMS5 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); this->typeParam_[4] = typeToString<P5>(); |
---|
248 | |
---|
249 | #define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue |
---|
250 | #define FUNCTOR_TYPENAME_RETURN0 |
---|
251 | #define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>(); |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | #define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams |
---|
256 | #define FUNCTOR_FUNCTION_PARAMS0 |
---|
257 | #define FUNCTOR_FUNCTION_PARAMS1 P1 param1 |
---|
258 | #define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2 |
---|
259 | #define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3 |
---|
260 | #define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4 |
---|
261 | #define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5 |
---|
262 | |
---|
263 | #define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue |
---|
264 | #define FUNCTOR_FUNCTION_RETURNVALUE0 void |
---|
265 | #define FUNCTOR_FUNCTION_RETURNVALUE1 R |
---|
266 | |
---|
267 | |
---|
268 | |
---|
269 | #define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams |
---|
270 | #define FUNCTOR_FUNCTION_CALL0 |
---|
271 | #define FUNCTOR_FUNCTION_CALL1 param1 |
---|
272 | #define FUNCTOR_FUNCTION_CALL2 param1, param2 |
---|
273 | #define FUNCTOR_FUNCTION_CALL3 param1, param2, param3 |
---|
274 | #define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4 |
---|
275 | #define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5 |
---|
276 | |
---|
277 | #define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall) |
---|
278 | #define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall |
---|
279 | #define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall |
---|
280 | |
---|
281 | |
---|
282 | |
---|
283 | #define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams |
---|
284 | #define FUNCTOR_EVALUATE_PARAM0 |
---|
285 | #define FUNCTOR_EVALUATE_PARAM1 \ |
---|
286 | if (index == 0) { P1 temp = param; param = temp; } |
---|
287 | #define FUNCTOR_EVALUATE_PARAM2 \ |
---|
288 | if (index == 0) { P1 temp = param; param = temp; } \ |
---|
289 | else if (index == 1) { P2 temp = param; param = temp; } |
---|
290 | #define FUNCTOR_EVALUATE_PARAM3 \ |
---|
291 | if (index == 0) { P1 temp = param; param = temp; } \ |
---|
292 | else if (index == 1) { P2 temp = param; param = temp; } \ |
---|
293 | else if (index == 2) { P3 temp = param; param = temp; } |
---|
294 | #define FUNCTOR_EVALUATE_PARAM4 \ |
---|
295 | if (index == 0) { P1 temp = param; param = temp; } \ |
---|
296 | else if (index == 1) { P2 temp = param; param = temp; } \ |
---|
297 | else if (index == 2) { P3 temp = param; param = temp; } \ |
---|
298 | else if (index == 3) { P4 temp = param; param = temp; } |
---|
299 | #define FUNCTOR_EVALUATE_PARAM5 \ |
---|
300 | if (index == 0) { P1 temp = param; param = temp; } \ |
---|
301 | else if (index == 1) { P2 temp = param; param = temp; } \ |
---|
302 | else if (index == 2) { P3 temp = param; param = temp; } \ |
---|
303 | else if (index == 3) { P4 temp = param; param = temp; } \ |
---|
304 | else if (index == 4) { P5 temp = param; param = temp; } |
---|
305 | |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | |
---|
310 | #define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \ |
---|
311 | FUNCTOR_TEMPLATE(0, returnvalue, numparams) \ |
---|
312 | class FunctorStatic##returnvalue##numparams : public FunctorStatic \ |
---|
313 | { \ |
---|
314 | public: \ |
---|
315 | FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ |
---|
316 | { \ |
---|
317 | this->numParams_ = numparams; \ |
---|
318 | this->hasReturnValue_ = returnvalue; \ |
---|
319 | this->type_ = FT_STATIC; \ |
---|
320 | this->functionPointer_ = functionPointer; \ |
---|
321 | \ |
---|
322 | FUNCTOR_TYPENAME_PARAMS(numparams); \ |
---|
323 | FUNCTOR_TYPENAME_RETURN(returnvalue); \ |
---|
324 | } \ |
---|
325 | \ |
---|
326 | void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ |
---|
327 | { \ |
---|
328 | FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ |
---|
329 | } \ |
---|
330 | \ |
---|
331 | virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ |
---|
332 | { \ |
---|
333 | FUNCTOR_EVALUATE_PARAM(numparams); \ |
---|
334 | } \ |
---|
335 | \ |
---|
336 | private: \ |
---|
337 | FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ |
---|
338 | }; \ |
---|
339 | \ |
---|
340 | \ |
---|
341 | FUNCTOR_TEMPLATE(0, returnvalue, numparams) \ |
---|
342 | inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ |
---|
343 | { \ |
---|
344 | return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \ |
---|
345 | } |
---|
346 | |
---|
347 | |
---|
348 | |
---|
349 | |
---|
350 | |
---|
351 | #define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \ |
---|
352 | FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ |
---|
353 | class FunctorMember##returnvalue##numparams : public FunctorMember<T> \ |
---|
354 | { \ |
---|
355 | public: \ |
---|
356 | FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ |
---|
357 | { \ |
---|
358 | this->numParams_ = numparams; \ |
---|
359 | this->hasReturnValue_ = returnvalue; \ |
---|
360 | this->type_ = FT_MEMBER; \ |
---|
361 | this->functionPointer_ = functionPointer; \ |
---|
362 | } \ |
---|
363 | \ |
---|
364 | void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ |
---|
365 | { \ |
---|
366 | FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ |
---|
367 | } \ |
---|
368 | \ |
---|
369 | void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ |
---|
370 | { \ |
---|
371 | COUT(1) << "An error occurred in Functor.h:" << std::endl; \ |
---|
372 | COUT(1) << "Error: Function is not const." << std::endl; \ |
---|
373 | } \ |
---|
374 | \ |
---|
375 | virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ |
---|
376 | { \ |
---|
377 | FUNCTOR_EVALUATE_PARAM(numparams); \ |
---|
378 | } \ |
---|
379 | \ |
---|
380 | private: \ |
---|
381 | FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ |
---|
382 | }; \ |
---|
383 | \ |
---|
384 | \ |
---|
385 | FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ |
---|
386 | class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \ |
---|
387 | { \ |
---|
388 | public: \ |
---|
389 | FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ |
---|
390 | { \ |
---|
391 | this->numParams_ = numparams; \ |
---|
392 | this->hasReturnValue_ = returnvalue; \ |
---|
393 | this->type_ = FT_CONSTMEMBER; \ |
---|
394 | this->functionPointer_ = functionPointer; \ |
---|
395 | } \ |
---|
396 | \ |
---|
397 | void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ |
---|
398 | { \ |
---|
399 | FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ |
---|
400 | } \ |
---|
401 | \ |
---|
402 | void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ |
---|
403 | { \ |
---|
404 | FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ |
---|
405 | } \ |
---|
406 | \ |
---|
407 | virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ |
---|
408 | { \ |
---|
409 | FUNCTOR_EVALUATE_PARAM(numparams); \ |
---|
410 | } \ |
---|
411 | \ |
---|
412 | private: \ |
---|
413 | FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \ |
---|
414 | }; \ |
---|
415 | \ |
---|
416 | \ |
---|
417 | FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ |
---|
418 | inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ |
---|
419 | { \ |
---|
420 | return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ |
---|
421 | } \ |
---|
422 | \ |
---|
423 | \ |
---|
424 | FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ |
---|
425 | inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ |
---|
426 | { \ |
---|
427 | return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ |
---|
428 | } |
---|
429 | |
---|
430 | |
---|
431 | // disable annoying warning about forcing value to boolean |
---|
432 | #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC |
---|
433 | #pragma warning(push) |
---|
434 | #pragma warning(disable:4100 4800) |
---|
435 | #endif |
---|
436 | |
---|
437 | #define CREATE_ALL_STATIC_FUNCTORS() \ |
---|
438 | CREATE_STATIC_FUNCTOR(0, 0); \ |
---|
439 | CREATE_STATIC_FUNCTOR(0, 1); \ |
---|
440 | CREATE_STATIC_FUNCTOR(0, 2); \ |
---|
441 | CREATE_STATIC_FUNCTOR(0, 3); \ |
---|
442 | CREATE_STATIC_FUNCTOR(0, 4); \ |
---|
443 | CREATE_STATIC_FUNCTOR(0, 5); \ |
---|
444 | CREATE_STATIC_FUNCTOR(1, 0); \ |
---|
445 | CREATE_STATIC_FUNCTOR(1, 1); \ |
---|
446 | CREATE_STATIC_FUNCTOR(1, 2); \ |
---|
447 | CREATE_STATIC_FUNCTOR(1, 3); \ |
---|
448 | CREATE_STATIC_FUNCTOR(1, 4); \ |
---|
449 | CREATE_STATIC_FUNCTOR(1, 5) |
---|
450 | |
---|
451 | |
---|
452 | #define CREATE_ALL_MEMBER_FUNCTORS() \ |
---|
453 | CREATE_MEMBER_FUNCTOR(0, 0); \ |
---|
454 | CREATE_MEMBER_FUNCTOR(0, 1); \ |
---|
455 | CREATE_MEMBER_FUNCTOR(0, 2); \ |
---|
456 | CREATE_MEMBER_FUNCTOR(0, 3); \ |
---|
457 | CREATE_MEMBER_FUNCTOR(0, 4); \ |
---|
458 | CREATE_MEMBER_FUNCTOR(0, 5); \ |
---|
459 | CREATE_MEMBER_FUNCTOR(1, 0); \ |
---|
460 | CREATE_MEMBER_FUNCTOR(1, 1); \ |
---|
461 | CREATE_MEMBER_FUNCTOR(1, 2); \ |
---|
462 | CREATE_MEMBER_FUNCTOR(1, 3); \ |
---|
463 | CREATE_MEMBER_FUNCTOR(1, 4); \ |
---|
464 | CREATE_MEMBER_FUNCTOR(1, 5) |
---|
465 | |
---|
466 | |
---|
467 | CREATE_ALL_STATIC_FUNCTORS(); |
---|
468 | CREATE_ALL_MEMBER_FUNCTORS(); |
---|
469 | } |
---|
470 | |
---|
471 | #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC |
---|
472 | #pragma warning(pop) |
---|
473 | #endif |
---|
474 | |
---|
475 | #endif /* _Functor_H__ */ |
---|