Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/core/Functor.h @ 1716

Last change on this file since 1716 was 1716, checked in by landauf, 16 years ago

Added new 'MultiType', replacing MultiTypePrimitive, MultiTypeString and MultiTypeMath. MultiType can hold all types MultiTypeMath was able to hold, namely all primitives, pointers, string and several math objects (vector2, 3 and 4, quaternion, colourvalue, radian, degree).

The new MultiType has a completely changed behaviour, I'll explain this on a wiki page somewhen.
But to say the most important things in a few words:
The MultiType has a fixed type. This type is determined by the first assigned value (by using setValue(value), operator=(value) or MultiType(value)). Every other value getting assigned later, will be converted to the first type. But you can change the type (setType<T>()), convert the value (convert<T>()) or force the type of a newly assigned value manually (setValue<T>(value)) by using template functions.

In contrast, the old MultiTypeMath changed it's internal type whenever a new type was assigned. So be aware of this important change.

At the moment I can't see any issues, but there might very well be several problems yet to discover, so further tests will be done.

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