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