Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Changed implementation of SharedPtr, it's now non-intrusive and uses an allocated counter instead. Hence it's possible to create an instance of SharedPtr<T> even if T is only known from a forward declaration. Also changed some parts of the code to reflect the inheritance of the underlying object pointers without using inheritance in the SharedPtr itself.

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