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