Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6417 was 6417, checked in by rgrieder, 14 years ago

Merged presentation2 branch back to trunk.
Major new features:

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