Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands3/src/libraries/core/Functor.h @ 7185

Last change on this file since 7185 was 7185, checked in by landauf, 14 years ago

continued working on the new console command interface and implementation

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