Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/Functor.h @ 5972

Last change on this file since 5972 was 5929, checked in by rgrieder, 15 years ago

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

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