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