[4838] | 1 | /*! |
---|
[7716] | 2 | * @file executor_functional.h |
---|
[7197] | 3 | * Definition of an Executor |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[7716] | 6 | /* |
---|
| 7 | orxonox - the future of 3D-vertical-scrollers |
---|
[1853] | 8 | |
---|
[7716] | 9 | Copyright (C) 2004 orx |
---|
[1853] | 10 | |
---|
[7716] | 11 | This program is free software; you can redistribute it and/or modify |
---|
| 12 | it under the terms of the GNU General Public License as published by |
---|
| 13 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 14 | any later version. |
---|
[5141] | 15 | |
---|
[7716] | 16 | ### File Specific: |
---|
| 17 | main-programmer: Benjamin Grauer |
---|
| 18 | co-programmer: ... |
---|
| 19 | */ |
---|
[5652] | 20 | |
---|
[5328] | 21 | |
---|
[7716] | 22 | #ifndef __EXECUTOR_FUNCTIONAL_H_ |
---|
| 23 | #define __EXECUTOR_FUNCTIONAL_H_ |
---|
[5641] | 24 | |
---|
[7721] | 25 | #include "executor.h" |
---|
[5641] | 26 | |
---|
[7716] | 27 | template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; }; |
---|
[7721] | 28 | template<> MT_Type ExecutorParamType<bool>(); |
---|
| 29 | template<> MT_Type ExecutorParamType<int>(); |
---|
| 30 | template<> MT_Type ExecutorParamType<unsigned int>(); |
---|
| 31 | template<> MT_Type ExecutorParamType<float>(); |
---|
| 32 | template<> MT_Type ExecutorParamType<char>(); |
---|
| 33 | template<> MT_Type ExecutorParamType<const std::string&>(); |
---|
[5161] | 34 | |
---|
[7716] | 35 | template<typename type> type fromString(const std::string& input, type defaultValue) {return defaultValue; }; |
---|
[7721] | 36 | template<> bool fromString<bool>(const std::string& input, bool defaultValue); |
---|
| 37 | template<> int fromString<int>(const std::string& input, int defaultValue); |
---|
| 38 | template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue); |
---|
| 39 | template<> float fromString<float>(const std::string& input, float defaultValue); |
---|
| 40 | template<> char fromString<char>(const std::string& input, char defaultValue); |
---|
| 41 | template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue); |
---|
[5641] | 42 | |
---|
[7716] | 43 | template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; |
---|
[7721] | 44 | template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i); |
---|
| 45 | template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i); |
---|
| 46 | template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i); |
---|
| 47 | template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i); |
---|
| 48 | template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i); |
---|
| 49 | template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i); |
---|
[5161] | 50 | |
---|
[7716] | 51 | #endif /* __EXECUTOR_FUNCTIONAL_H_ */ |
---|
[5161] | 52 | |
---|
[5328] | 53 | |
---|
[7716] | 54 | #define __EXECUTOR_FUNCTIONAL_CONST |
---|
| 55 | #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params |
---|
| 56 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC dynamic_cast<T*>(object)->*(functionPointer) |
---|
| 57 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER T::*functionPointer |
---|
[5161] | 58 | |
---|
[7716] | 59 | #ifdef EXECUTOR_FUNCTIONAL_USE_CONST |
---|
| 60 | #undef __EXECUTOR_FUNCTIONAL_CONST |
---|
| 61 | #define __EXECUTOR_FUNCTIONAL_CONST const |
---|
| 62 | #undef __EXECUTOR_FUNCTIONAL_NAME |
---|
| 63 | #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_const |
---|
| 64 | #undef EXECUTOR_FUNCTIONAL_USE_CONST |
---|
| 65 | #endif |
---|
[5161] | 66 | |
---|
[7716] | 67 | #ifdef EXECUTOR_FUNCTIONAL_USE_STATIC |
---|
| 68 | #ifdef EXECUTOR_FUNCTIONAL_USE_CONST |
---|
| 69 | #error you obviously do not know what you are doing !! ask the bensch |
---|
| 70 | #endif /* EXECUTOR_FUNCTIONAL_USE_CONST */ |
---|
[5135] | 71 | |
---|
[7719] | 72 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC |
---|
[7716] | 73 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC functionPointer |
---|
| 74 | #undef __EXECUTOR_FUNCTIONAL_NAME |
---|
| 75 | #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_static |
---|
| 76 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER |
---|
| 77 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER *functionPointer |
---|
[5636] | 78 | |
---|
[7719] | 79 | #undef EXECUTOR_FUNCTIONAL_USE_STATIC |
---|
[7716] | 80 | #endif /* EXECUTOR_FUNCTIONAL_USE_STATIC */ |
---|
[7714] | 81 | |
---|
[7716] | 82 | template<class T> class __EXECUTOR_FUNCTIONAL_NAME(0) : public Executor |
---|
| 83 | { |
---|
| 84 | private: |
---|
| 85 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5551] | 86 | |
---|
[7716] | 87 | public: |
---|
| 88 | __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST ) |
---|
| 89 | : Executor() |
---|
| 90 | { |
---|
| 91 | this->functorType = Executor_Objective; |
---|
| 92 | this->functionPointer = functionPointer; |
---|
[7717] | 93 | }; |
---|
| 94 | |
---|
[7716] | 95 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
| 96 | { |
---|
| 97 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(); |
---|
| 98 | }; |
---|
[5142] | 99 | |
---|
[7719] | 100 | virtual Executor* clone() const |
---|
| 101 | { |
---|
[7717] | 102 | return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(this->functionPointer); |
---|
| 103 | }; |
---|
[7716] | 104 | }; |
---|
[5135] | 105 | |
---|
[7719] | 106 | //! SINGLE VALUE |
---|
[7716] | 107 | template<class T, typename type0> class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor |
---|
| 108 | { |
---|
| 109 | private: |
---|
| 110 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5141] | 111 | |
---|
[7716] | 112 | public: |
---|
| 113 | __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST) |
---|
| 114 | : Executor(ExecutorParamType<type0>()) |
---|
| 115 | { |
---|
| 116 | this->functorType = Executor_Objective; |
---|
| 117 | this->functionPointer = functionPointer; |
---|
[7717] | 118 | }; |
---|
| 119 | |
---|
[7716] | 120 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
| 121 | { |
---|
[5153] | 122 | |
---|
[7716] | 123 | /* // THE VERY COOL DEBUG |
---|
| 124 | printf("SUB[0] : %s\n", sub[0].c_str()); |
---|
| 125 | printf("getDefault<type0>(this->defaultValue, 0):::: %d\n", getDefault<type0>(this->defaultValue, 0)); |
---|
| 126 | printf("VALUE: %d\n", fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0))); |
---|
| 127 | */ |
---|
| 128 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
| 129 | fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) ); |
---|
| 130 | }; |
---|
[5153] | 131 | |
---|
[7719] | 132 | virtual Executor* clone() const |
---|
| 133 | { |
---|
[7717] | 134 | return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, type0>(this->functionPointer); |
---|
| 135 | }; |
---|
[7716] | 136 | }; |
---|
[5145] | 137 | |
---|
[7719] | 138 | //! DOUBLE VALUE |
---|
[7716] | 139 | template<class T, typename type0, typename type1> class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor |
---|
| 140 | { |
---|
| 141 | private: |
---|
| 142 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5145] | 143 | |
---|
[7714] | 144 | public: |
---|
[7716] | 145 | __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST) |
---|
| 146 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
---|
[7714] | 147 | { |
---|
[7716] | 148 | this->functorType = Executor_Objective; |
---|
| 149 | this->functionPointer = functionPointer; |
---|
[7717] | 150 | }; |
---|
| 151 | |
---|
[7714] | 152 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
| 153 | { |
---|
[7716] | 154 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
| 155 | fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)), |
---|
| 156 | fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1))); |
---|
| 157 | }; |
---|
[7714] | 158 | |
---|
[7719] | 159 | virtual Executor* clone() const |
---|
| 160 | { |
---|
[7717] | 161 | return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, type0, type1>(this->functionPointer); |
---|
| 162 | }; |
---|
[5129] | 163 | }; |
---|
[5113] | 164 | |
---|
[5632] | 165 | |
---|
[7719] | 166 | //! TRIPPLE VALUE |
---|
| 167 | template<class T, typename type0, typename type1, typename type2> class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor |
---|
| 168 | { |
---|
| 169 | private: |
---|
| 170 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5326] | 171 | |
---|
[7719] | 172 | public: |
---|
| 173 | __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST) |
---|
| 174 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>()) |
---|
| 175 | { |
---|
| 176 | this->functorType = Executor_Objective; |
---|
| 177 | this->functionPointer = functionPointer; |
---|
| 178 | }; |
---|
[7716] | 179 | |
---|
[7719] | 180 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
| 181 | { |
---|
| 182 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
| 183 | fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)), |
---|
| 184 | fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)), |
---|
| 185 | fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2))); |
---|
| 186 | }; |
---|
[7718] | 187 | |
---|
[7719] | 188 | virtual Executor* clone() const |
---|
| 189 | { |
---|
| 190 | return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, type0, type1, type2>(this->functionPointer); |
---|
| 191 | }; |
---|
| 192 | }; |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | //! QUADRUPPEL VALUE |
---|
| 197 | template<class T, typename type0, typename type1, typename type2, typename type3> class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor |
---|
| 198 | { |
---|
| 199 | private: |
---|
| 200 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST; |
---|
| 201 | |
---|
| 202 | public: |
---|
| 203 | __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST) |
---|
| 204 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>()) |
---|
| 205 | { |
---|
| 206 | this->functorType = Executor_Objective; |
---|
| 207 | this->functionPointer = functionPointer; |
---|
| 208 | }; |
---|
| 209 | |
---|
| 210 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
| 211 | { |
---|
| 212 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
| 213 | fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)), |
---|
| 214 | fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)), |
---|
| 215 | fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)), |
---|
| 216 | fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3))); |
---|
| 217 | }; |
---|
| 218 | |
---|
| 219 | virtual Executor* clone() const |
---|
| 220 | { |
---|
| 221 | return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, type0, type1, type2, type3>(this->functionPointer); |
---|
| 222 | }; |
---|
| 223 | }; |
---|
| 224 | |
---|
| 225 | //! CHINQUE VALUE |
---|
| 226 | template<class T, typename type0, typename type1, typename type2, typename type3, typename type4> class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor |
---|
| 227 | { |
---|
| 228 | private: |
---|
| 229 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST; |
---|
| 230 | |
---|
| 231 | public: |
---|
| 232 | __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST) |
---|
| 233 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>()) |
---|
| 234 | { |
---|
| 235 | this->functorType = Executor_Objective; |
---|
| 236 | this->functionPointer = functionPointer; |
---|
| 237 | }; |
---|
| 238 | |
---|
| 239 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
| 240 | { |
---|
| 241 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
| 242 | fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)), |
---|
| 243 | fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)), |
---|
| 244 | fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)), |
---|
| 245 | fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)), |
---|
| 246 | fromString<type4>(sub[4], getDefault<type4>(this->defaultValue, 4))); |
---|
| 247 | }; |
---|
| 248 | |
---|
| 249 | virtual Executor* clone() const |
---|
| 250 | { |
---|
| 251 | return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, type0, type1, type2, type3, type4>(this->functionPointer); |
---|
| 252 | }; |
---|
| 253 | }; |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | |
---|
[7718] | 257 | #define EXECUTOR_FUNCTIONAL_CREATOR0() \ |
---|
| 258 | template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
| 259 | { \ |
---|
| 260 | return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(functionPointer); \ |
---|
[7716] | 261 | } |
---|
[7718] | 262 | |
---|
| 263 | #define EXECUTOR_FUNCTIONAL_CREATOR1(type0) \ |
---|
| 264 | template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
| 265 | { \ |
---|
| 266 | return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, type0##_TYPE>(functionPointer); \ |
---|
[7716] | 267 | } |
---|
[7718] | 268 | |
---|
| 269 | #define EXECUTOR_FUNCTIONAL_CREATOR2(type0, type1) \ |
---|
| 270 | template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
| 271 | { \ |
---|
| 272 | return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, type0##_TYPE, type1##_TYPE>(functionPointer); \ |
---|
[7716] | 273 | } |
---|
[5641] | 274 | |
---|
[7719] | 275 | #define EXECUTOR_FUNCTIONAL_CREATOR3(type0, type1, type2) \ |
---|
| 276 | template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
| 277 | { \ |
---|
| 278 | return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, type0##_TYPE, type1##_TYPE, type2##_TYPE>(functionPointer); \ |
---|
| 279 | } |
---|
[5326] | 280 | |
---|
[7719] | 281 | #define EXECUTOR_FUNCTIONAL_CREATOR4(type0, type1, type2, type3) \ |
---|
| 282 | template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
| 283 | { \ |
---|
| 284 | return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE>(functionPointer); \ |
---|
| 285 | } |
---|
[7718] | 286 | |
---|
[7719] | 287 | #define EXECUTOR_FUNCTIONAL_CREATOR5(type0, type1, type2, type3, type4) \ |
---|
| 288 | template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
| 289 | { \ |
---|
| 290 | return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE>(functionPointer); \ |
---|
| 291 | } |
---|
[7718] | 292 | |
---|
[7719] | 293 | |
---|
| 294 | |
---|
[7718] | 295 | #define FUNCTOR_LIST(x) EXECUTOR_FUNCTIONAL_CREATOR ## x |
---|
| 296 | #include "functor_list.h" |
---|
| 297 | #undef FUNCTOR_LIST |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | |
---|
[7716] | 301 | #undef __EXECUTOR_FUNCTIONAL_CONST |
---|
| 302 | #undef __EXECUTOR_FUNCTIONAL_NAME |
---|
| 303 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC |
---|
| 304 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER |
---|