Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/core/Functor.h @ 1001

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

ok, be aware, here comes a big one. people with weak nerves should probably better look away or take some serious drugs.
this update includes partial and explicit class template specialization, partial and explicit specialized template function overloading, template meta programming and a simple typecast.
yeah right, a typecast. but let me explain the whole story from the beginning.

it all started with a simple problem: i had a double in a MultiType and wanted a float, but i always got 0. what was the problem? the conversion 'MultiType to anyting' was handled by the Converter class in util/Convert.h and the Converter was specialized for strings, multitypes, vectors and so on, but not for int, float, bool, …
so i've first wanted to implement a typecast as default, but this was a bad idea because it doesn't work for almost every generic type.
implementing an explicit specialization for every possible pair of primitives (did you ever happened to use an unsigned short? or a long double? no? ignorants :D) would have been a simple but ugly solution.
but there were other problems: if there's a rule to convert a string into anything and another rule to convert anything into an int - what happens if you want to convert a string into an int? compiler error! …ambiguous partial template specialization.
so i've spent days and nights to find a solution. this is my 5th try or so and i'm still really unsure if it works, but it's the first version i want to commit to have at least a backup.
if you're interested in looking at the code you better wait until i've cleaned up the whole thing, it's a real mess. and i want to do further tests, but now i'm tired. good night ;)

File size: 20.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 *   Inspiration: Functor by Benjamin Grauer
27 */
28
29#ifndef _Functor_H__
30#define _Functor_H__
31
32#include "util/MultiTypeMath.h"
33#include "Debug.h"
34
35#include "CorePrereqs.h"
36
37#define MAX_FUNCTOR_ARGUMENTS 5
38
39namespace orxonox
40{
41    enum FunctionType
42    {
43        FT_MEMBER,
44        FT_CONSTMEMBER,
45        FT_STATIC
46    };
47
48
49    template <class T>
50    inline std::string typeToString() { return "unknown"; }
51
52#define CreateTypeToStringTemplate(type) \
53    template <> \
54    inline std::string typeToString<type>() { return #type; } \
55    template <> \
56    inline std::string typeToString<type&>() { return #type; } \
57    template <> \
58    inline std::string typeToString<const type>() { return #type; } \
59    template <> \
60    inline std::string typeToString<const type&>() { return #type; }
61
62    CreateTypeToStringTemplate(int);
63    CreateTypeToStringTemplate(unsigned int);
64    CreateTypeToStringTemplate(char);
65    CreateTypeToStringTemplate(unsigned char);
66    CreateTypeToStringTemplate(short);
67    CreateTypeToStringTemplate(unsigned short);
68    CreateTypeToStringTemplate(long);
69    CreateTypeToStringTemplate(unsigned long);
70    CreateTypeToStringTemplate(float);
71    CreateTypeToStringTemplate(double);
72    CreateTypeToStringTemplate(long double);
73    CreateTypeToStringTemplate(bool);
74    CreateTypeToStringTemplate(Vector2);
75    CreateTypeToStringTemplate(Vector3);
76    CreateTypeToStringTemplate(Quaternion);
77    CreateTypeToStringTemplate(ColourValue);
78    CreateTypeToStringTemplate(Radian);
79    CreateTypeToStringTemplate(Degree);
80
81    template <> \
82    inline std::string typeToString<std::string>() { return "string"; } \
83    template <> \
84    inline std::string typeToString<std::string&>() { return "string"; } \
85    template <> \
86    inline std::string typeToString<const std::string>() { return "string"; } \
87    template <> \
88    inline std::string typeToString<const std::string&>() { return "string"; }
89
90    class _CoreExport Functor
91    {
92        public:
93            Functor() {}
94            virtual ~Functor() {}
95
96            virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
97
98            inline unsigned int getParamCount() const { return this->numParams_; }
99            inline bool hasReturnvalue() const { return this->hasReturnValue_; }
100            inline FunctionType getType() const { return this->type_; }
101            inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; }
102
103            std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; }
104            std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; }
105
106            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0;
107
108        protected:
109            unsigned int numParams_;
110            bool hasReturnValue_;
111            FunctionType type_;
112            MultiTypeMath returnedValue_;
113
114            std::string typeReturnvalue_;
115            std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];
116    };
117
118    class _CoreExport FunctorStatic : public Functor
119    {
120        public:
121            virtual ~FunctorStatic() {}
122            virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
123    };
124
125    template <class T>
126    class FunctorMember : public Functor
127    {
128        public:
129            FunctorMember()
130            {
131                constObject_ = 0;
132                object_ = 0;
133                bConstObject_ = false;
134            }
135            virtual ~FunctorMember() {}
136
137            virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
138            virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
139
140            virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
141            {
142                if (this->bConstObject_)
143                {
144                    if (this->constObject_)
145                        (*this)(this->constObject_, param1, param2, param3, param4, param5);
146                    else
147                    {
148                        COUT(1) << "An error occurred in Functor.h:" << std::endl;
149                        COUT(1) << "Error: No const object set." << std::endl;
150                    }
151                }
152                else
153                {
154                    if (this->object_)
155                        (*this)(this->object_, param1, param2, param3, param4, param5);
156                    else
157                    {
158                        COUT(1) << "An error occurred in Functor.h:" << std::endl;
159                        COUT(1) << "Error: No object set." << std::endl;
160                    }
161                }
162            }
163
164            void setObject(T* object)
165            {
166                this->bConstObject_ = false;
167                this->object_ = object;
168            }
169
170            void setObject(const T* object)
171            {
172                this->bConstObject_ = true;
173                this->constObject_ = object;
174            }
175
176        private:
177            const T* constObject_;
178            T* object_;
179            bool bConstObject_;
180    };
181
182
183
184#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams
185#define FUNCTOR_TEMPLATE000
186#define FUNCTOR_TEMPLATE001 template <class P1>
187#define FUNCTOR_TEMPLATE002 template <class P1, class P2>
188#define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>
189#define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>
190#define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>
191#define FUNCTOR_TEMPLATE010 template <class R>
192#define FUNCTOR_TEMPLATE011 template <class R, class P1>
193#define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>
194#define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>
195#define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>
196#define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>
197#define FUNCTOR_TEMPLATE100 template <class T>
198#define FUNCTOR_TEMPLATE101 template <class T, class P1>
199#define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>
200#define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>
201#define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>
202#define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>
203#define FUNCTOR_TEMPLATE110 template <class T, class R>
204#define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>
205#define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>
206#define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>
207#define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>
208#define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
209
210
211
212#define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams
213#define FUNCTOR_TEMPLATE_CLASSES000
214#define FUNCTOR_TEMPLATE_CLASSES001 <P1>
215#define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2>
216#define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3>
217#define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4>
218#define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5>
219#define FUNCTOR_TEMPLATE_CLASSES010 <R>
220#define FUNCTOR_TEMPLATE_CLASSES011 <R, P1>
221#define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2>
222#define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3>
223#define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4>
224#define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5>
225#define FUNCTOR_TEMPLATE_CLASSES100 <T>
226#define FUNCTOR_TEMPLATE_CLASSES101 <T, P1>
227#define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2>
228#define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3>
229#define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4>
230#define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5>
231#define FUNCTOR_TEMPLATE_CLASSES110 <T, R>
232#define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1>
233#define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2>
234#define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3>
235#define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4>
236#define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5>
237
238
239
240#define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams
241#define FUNCTOR_TYPENAME_PARAMS0
242#define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>();
243#define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>();
244#define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>();
245#define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>();
246#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>();
247
248#define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue
249#define FUNCTOR_TYPENAME_RETURN0
250#define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();
251
252
253
254#define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams
255#define FUNCTOR_FUNCTION_PARAMS0
256#define FUNCTOR_FUNCTION_PARAMS1 P1 param1
257#define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2
258#define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3
259#define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4
260#define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5
261
262#define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue
263#define FUNCTOR_FUNCTION_RETURNVALUE0 void
264#define FUNCTOR_FUNCTION_RETURNVALUE1 R
265
266
267
268#define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams
269#define FUNCTOR_FUNCTION_CALL0
270#define FUNCTOR_FUNCTION_CALL1 param1
271#define FUNCTOR_FUNCTION_CALL2 param1, param2
272#define FUNCTOR_FUNCTION_CALL3 param1, param2, param3
273#define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4
274#define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5
275
276#define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall)
277#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall
278#define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall
279
280
281
282#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
283#define FUNCTOR_EVALUATE_PARAM0
284#define FUNCTOR_EVALUATE_PARAM1 \
285    if (index == 0) param = (P1)param
286#define FUNCTOR_EVALUATE_PARAM2 \
287    if (index == 0) param = (P1)param; \
288    else if (index == 1) param = (P2)param
289#define FUNCTOR_EVALUATE_PARAM3 \
290    if (index == 0) param = (P1)param; \
291    else if (index == 1) param = (P2)param; \
292    else if (index == 2) param = (P3)param
293#define FUNCTOR_EVALUATE_PARAM4 \
294    if (index == 0) param = (P1)param; \
295    else if (index == 1) param = (P2)param; \
296    else if (index == 2) param = (P3)param; \
297    else if (index == 3) param = (P4)param
298#define FUNCTOR_EVALUATE_PARAM5 \
299    if (index == 0) param = (P1)param; \
300    else if (index == 1) param = (P2)param; \
301    else if (index == 2) param = (P3)param; \
302    else if (index == 3) param = (P4)param; \
303    else if (index == 4) param = (P5)param
304
305
306
307
308
309#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \
310    FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
311    class FunctorStatic##returnvalue##numparams : public FunctorStatic \
312    { \
313        public: \
314            FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
315            { \
316                this->numParams_ = numparams; \
317                this->hasReturnValue_ = returnvalue; \
318                this->type_ = FT_STATIC; \
319                this->functionPointer_ = functionPointer; \
320                \
321                FUNCTOR_TYPENAME_PARAMS(numparams); \
322                FUNCTOR_TYPENAME_RETURN(returnvalue); \
323            } \
324    \
325            void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
326            { \
327                std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" << std::endl; \
328                std::cout << param1 << std::endl; \
329                std::cout << this->getTypenameParam(0) << std::endl; \
330                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
331                std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" << std::endl; \
332            } \
333    \
334            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
335            { \
336                FUNCTOR_EVALUATE_PARAM(numparams); \
337            } \
338    \
339        private: \
340            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
341    }; \
342    \
343    \
344    FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
345    inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
346    { \
347        return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \
348    }
349
350
351
352
353
354#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \
355    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
356    class FunctorMember##returnvalue##numparams : public FunctorMember<T> \
357    { \
358        public: \
359            FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
360            { \
361                this->numParams_ = numparams; \
362                this->hasReturnValue_ = returnvalue; \
363                this->type_ = FT_MEMBER; \
364                this->functionPointer_ = functionPointer; \
365            } \
366    \
367            void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
368            { \
369                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
370            } \
371    \
372            void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
373            { \
374                COUT(1) << "An error occurred in Functor.h:" << std::endl; \
375                COUT(1) << "Error: Function is not const." << std::endl; \
376            } \
377    \
378            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
379            { \
380                FUNCTOR_EVALUATE_PARAM(numparams); \
381            } \
382    \
383        private: \
384            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
385    }; \
386    \
387    \
388    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
389    class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \
390    { \
391        public: \
392            FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
393            { \
394                this->numParams_ = numparams; \
395                this->hasReturnValue_ = returnvalue; \
396                this->type_ = FT_CONSTMEMBER; \
397                this->functionPointer_ = functionPointer; \
398            } \
399    \
400            void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
401            { \
402                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
403            } \
404    \
405            void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
406            { \
407                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
408            } \
409    \
410            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
411            { \
412                FUNCTOR_EVALUATE_PARAM(numparams); \
413            } \
414    \
415        private: \
416            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \
417    }; \
418    \
419    \
420    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
421    inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
422    { \
423        return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
424    } \
425    \
426    \
427    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
428    inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
429    { \
430        return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
431    }
432
433
434
435
436#define CREATE_ALL_STATIC_FUNCTORS() \
437    CREATE_STATIC_FUNCTOR(0, 0); \
438    CREATE_STATIC_FUNCTOR(0, 1); \
439    CREATE_STATIC_FUNCTOR(0, 2); \
440    CREATE_STATIC_FUNCTOR(0, 3); \
441    CREATE_STATIC_FUNCTOR(0, 4); \
442    CREATE_STATIC_FUNCTOR(0, 5); \
443    CREATE_STATIC_FUNCTOR(1, 0); \
444    CREATE_STATIC_FUNCTOR(1, 1); \
445    CREATE_STATIC_FUNCTOR(1, 2); \
446    CREATE_STATIC_FUNCTOR(1, 3); \
447    CREATE_STATIC_FUNCTOR(1, 4); \
448    CREATE_STATIC_FUNCTOR(1, 5)
449
450
451#define CREATE_ALL_MEMBER_FUNCTORS() \
452    CREATE_MEMBER_FUNCTOR(0, 0); \
453    CREATE_MEMBER_FUNCTOR(0, 1); \
454    CREATE_MEMBER_FUNCTOR(0, 2); \
455    CREATE_MEMBER_FUNCTOR(0, 3); \
456    CREATE_MEMBER_FUNCTOR(0, 4); \
457    CREATE_MEMBER_FUNCTOR(0, 5); \
458    CREATE_MEMBER_FUNCTOR(1, 0); \
459    CREATE_MEMBER_FUNCTOR(1, 1); \
460    CREATE_MEMBER_FUNCTOR(1, 2); \
461    CREATE_MEMBER_FUNCTOR(1, 3); \
462    CREATE_MEMBER_FUNCTOR(1, 4); \
463    CREATE_MEMBER_FUNCTOR(1, 5)
464
465
466    CREATE_ALL_STATIC_FUNCTORS();
467    CREATE_ALL_MEMBER_FUNCTORS();
468}
469
470#endif /* _Functor_H__ */
Note: See TracBrowser for help on using the repository browser.