[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" |
---|
[9728] | 26 | #include "substring.h" |
---|
[5641] | 27 | |
---|
[5161] | 28 | |
---|
[8035] | 29 | template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; }; |
---|
[7721] | 30 | template<> bool fromString<bool>(const std::string& input, bool defaultValue); |
---|
| 31 | template<> int fromString<int>(const std::string& input, int defaultValue); |
---|
| 32 | template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue); |
---|
| 33 | template<> float fromString<float>(const std::string& input, float defaultValue); |
---|
| 34 | template<> char fromString<char>(const std::string& input, char defaultValue); |
---|
| 35 | template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue); |
---|
[5641] | 36 | |
---|
[8035] | 37 | template<typename type> type fromMulti(const MultiType& multi) { /* return defaultValue; */ }; |
---|
| 38 | template<> bool fromMulti<bool>(const MultiType& multi); |
---|
| 39 | template<> int fromMulti<int>(const MultiType& multi); |
---|
| 40 | template<> unsigned int fromMulti<unsigned int>(const MultiType& multi); |
---|
| 41 | template<> float fromMulti<float>(const MultiType& multi); |
---|
| 42 | template<> char fromMulti<char>(const MultiType& multi); |
---|
| 43 | template<> const std::string& fromMulti<const std::string&>(const MultiType& multi); |
---|
| 44 | |
---|
| 45 | |
---|
[7716] | 46 | template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; |
---|
[7721] | 47 | template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i); |
---|
| 48 | template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i); |
---|
| 49 | template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i); |
---|
| 50 | template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i); |
---|
| 51 | template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i); |
---|
| 52 | template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i); |
---|
[5161] | 53 | |
---|
[9730] | 54 | |
---|
| 55 | /** |
---|
[9736] | 56 | * @brief this is a Template Class used as an evaluater. |
---|
| 57 | * |
---|
| 58 | * Trait to determine a default Value for any Type, |
---|
| 59 | * and to define the Convertible, and how it is transformed into the |
---|
| 60 | * corresponding SubTypes over the operator(). |
---|
| 61 | * |
---|
| 62 | * This Class must be reimplemented for each Convertible and all of its |
---|
| 63 | * conversion-members. |
---|
| 64 | * |
---|
| 65 | * e.g: Convertible SubSting, that splits up into many Stings |
---|
| 66 | * conversion-members: (int) can be transformed from a String. |
---|
| 67 | */ |
---|
| 68 | template<typename FromType> class ExecutorEvaluater |
---|
| 69 | { |
---|
| 70 | public: |
---|
| 71 | /** @brief Executes the Evaluater |
---|
| 72 | * @param CallValue the Value that should be converted |
---|
| 73 | * @param defaults the default Values. |
---|
| 74 | */ |
---|
| 75 | template <typename ToType, int index> |
---|
| 76 | ToType operator()(FromType& CallValue, const MultiType* const defaults) |
---|
| 77 | { |
---|
| 78 | return defaultValue; /*(CallValue.size() > index) ? |
---|
| 79 | fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) : |
---|
| 80 | fromMulti<ToType>(defaults[index]); */ |
---|
| 81 | } |
---|
| 82 | static FromType& defaultValue() { return FromType(); }; |
---|
| 83 | }; |
---|
| 84 | |
---|
| 85 | /** |
---|
[9730] | 86 | * @brief to remove writing errors, this function is Used. |
---|
| 87 | * @param sub The SubString to use |
---|
| 88 | * @param default The default Values. |
---|
| 89 | */ |
---|
[9736] | 90 | template<> class ExecutorEvaluater <const SubString> |
---|
[9730] | 91 | { |
---|
[9731] | 92 | public: |
---|
[9736] | 93 | /** @brief Executes the Evaluater |
---|
[9735] | 94 | * @param CallValue the Value that should be converted |
---|
| 95 | * @param defaults the default Values. |
---|
| 96 | */ |
---|
[9736] | 97 | template <typename ToType, int index> |
---|
| 98 | ToType operator()(const SubString& CallValue, const MultiType* const defaults) |
---|
[9731] | 99 | { |
---|
[9732] | 100 | return (CallValue.size() > index) ? |
---|
| 101 | fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) : |
---|
[9731] | 102 | fromMulti<ToType>(defaults[index]); |
---|
| 103 | } |
---|
[9736] | 104 | static const SubString& defaultValue() { return SubString::NullSubString; }; |
---|
[9730] | 105 | }; |
---|
| 106 | |
---|
[9736] | 107 | |
---|
| 108 | |
---|
| 109 | |
---|
[7716] | 110 | #endif /* __EXECUTOR_FUNCTIONAL_H_ */ |
---|
[5161] | 111 | |
---|
[7724] | 112 | //! if Functional is constant calling |
---|
[7716] | 113 | #define __EXECUTOR_FUNCTIONAL_CONST |
---|
[7724] | 114 | //! The Name to be attached to the functional (for normal, static, and const modes) |
---|
[7716] | 115 | #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params |
---|
[7724] | 116 | //! The Execution-mode (either static or objective) |
---|
[7716] | 117 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC dynamic_cast<T*>(object)->*(functionPointer) |
---|
[7724] | 118 | //! The Function-Pointer, and how to save it internally. |
---|
[7716] | 119 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER T::*functionPointer |
---|
[9735] | 120 | #define __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE Executor<CallType, BaseClass>::FunctionDefault |
---|
[5161] | 121 | |
---|
[9731] | 122 | #ifdef EXECUTOR_FUNCTIONAL_USE_CONST //! USING CONST FUNCTIONALS |
---|
| 123 | #ifdef __EXECUTOR_FUNCTIONAL_CONST_INCLUDED //!< CHECK IF ALREADY INCLUED CONST FUNCTIONALS |
---|
[9728] | 124 | #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS |
---|
| 125 | #else |
---|
| 126 | #define __EXECUTOR_FUNCTIONAL_CONST_INCLUDED |
---|
| 127 | #endif |
---|
[7716] | 128 | #undef __EXECUTOR_FUNCTIONAL_CONST |
---|
| 129 | #define __EXECUTOR_FUNCTIONAL_CONST const |
---|
[9735] | 130 | #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE |
---|
| 131 | #define __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE Executor<CallType, BaseClass>::FunctionConst |
---|
[7716] | 132 | #undef __EXECUTOR_FUNCTIONAL_NAME |
---|
| 133 | #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_const |
---|
[9728] | 134 | //#endif /* EXECUTOR_FUNCTIONAL_USE_CONST */ |
---|
[5161] | 135 | |
---|
[9728] | 136 | #elif defined EXECUTOR_FUNCTIONAL_USE_STATIC |
---|
[7716] | 137 | #ifdef EXECUTOR_FUNCTIONAL_USE_CONST |
---|
| 138 | #error you obviously do not know what you are doing !! ask the bensch |
---|
[9728] | 139 | #endif |
---|
[5135] | 140 | |
---|
[9730] | 141 | #ifdef __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED |
---|
[9728] | 142 | #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS |
---|
| 143 | #else |
---|
| 144 | #define __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED |
---|
| 145 | #endif |
---|
| 146 | |
---|
[7719] | 147 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC |
---|
[7716] | 148 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC functionPointer |
---|
| 149 | #undef __EXECUTOR_FUNCTIONAL_NAME |
---|
| 150 | #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_static |
---|
| 151 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER |
---|
| 152 | #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER *functionPointer |
---|
[9735] | 153 | #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE |
---|
| 154 | #define __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE Executor<CallType, BaseClass>::FunctionStatic |
---|
[5636] | 155 | |
---|
[9728] | 156 | //#endif /* EXECUTOR_FUNCTIONAL_USE_STATIC */ |
---|
| 157 | #else |
---|
| 158 | #ifdef __EXECUTOR_FUNCTIONAL_PLAIN_INCLUDED |
---|
| 159 | #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS |
---|
| 160 | #else |
---|
| 161 | #define __EXECUTOR_FUNCTIONAL_PLAIN_INCLUDED |
---|
| 162 | #endif |
---|
| 163 | #endif |
---|
[7714] | 164 | |
---|
[9728] | 165 | #ifndef __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS |
---|
[9730] | 166 | |
---|
[9735] | 167 | |
---|
| 168 | |
---|
| 169 | |
---|
[8035] | 170 | /////////// |
---|
| 171 | //// 0 //// |
---|
| 172 | /////////// |
---|
[7724] | 173 | //! @brief ExecutorClass, that can execute Functions without any parameters. |
---|
[9736] | 174 | template<class T, typename CallType, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject> |
---|
[9735] | 175 | class __EXECUTOR_FUNCTIONAL_NAME(0) :public Executor<CallType, BaseClass> |
---|
[7716] | 176 | { |
---|
| 177 | private: |
---|
[7724] | 178 | /** @brief the FunctioPointer. */ |
---|
[7716] | 179 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5551] | 180 | |
---|
[7716] | 181 | public: |
---|
[7724] | 182 | /** |
---|
| 183 | * @brief constructs the Executor. |
---|
| 184 | * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function. |
---|
| 185 | */ |
---|
[7716] | 186 | __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST ) |
---|
[9735] | 187 | : Executor<CallType, BaseClass>(false, __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE) |
---|
[7716] | 188 | { |
---|
| 189 | this->functionPointer = functionPointer; |
---|
[7717] | 190 | }; |
---|
| 191 | |
---|
[7724] | 192 | /** |
---|
| 193 | * @brief executes the Functional |
---|
| 194 | * @param object the Object the action should be executed on. |
---|
| 195 | * @param sub the SubString to get the Parameters from. |
---|
| 196 | */ |
---|
[9736] | 197 | virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const |
---|
[7716] | 198 | { |
---|
| 199 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(); |
---|
| 200 | }; |
---|
[5142] | 201 | |
---|
[7724] | 202 | /** |
---|
| 203 | * @brief copies the Executor |
---|
| 204 | * @returns a new Executor that's a copy of this one. |
---|
| 205 | */ |
---|
[9735] | 206 | virtual Executor<CallType, BaseClass>* clone() const |
---|
[7719] | 207 | { |
---|
[9731] | 208 | return new __EXECUTOR_FUNCTIONAL_NAME(0)<T, CallType>(this->functionPointer); |
---|
[7717] | 209 | }; |
---|
[7716] | 210 | }; |
---|
[5135] | 211 | |
---|
[8035] | 212 | |
---|
| 213 | |
---|
[9735] | 214 | |
---|
| 215 | |
---|
[8035] | 216 | /////////// |
---|
| 217 | //// 1 //// |
---|
| 218 | /////////// |
---|
[7724] | 219 | //! @brief ExecutorClass, that can execute Functions with one parameter. |
---|
[9736] | 220 | template<class T, typename CallType, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject> |
---|
[9735] | 221 | class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<CallType, BaseClass> |
---|
[7716] | 222 | { |
---|
| 223 | private: |
---|
[7724] | 224 | /** @brief the FunctioPointer. */ |
---|
[7716] | 225 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5141] | 226 | |
---|
[7716] | 227 | public: |
---|
[7724] | 228 | /** |
---|
| 229 | * @brief constructs the Executor. |
---|
| 230 | * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function. |
---|
| 231 | */ |
---|
[7716] | 232 | __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST) |
---|
[9735] | 233 | : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE) |
---|
[7716] | 234 | { |
---|
| 235 | this->functionPointer = functionPointer; |
---|
[7717] | 236 | }; |
---|
| 237 | |
---|
[7724] | 238 | /** |
---|
| 239 | * @brief executes the Functional |
---|
| 240 | * @param object the Object the action should be executed on. |
---|
| 241 | * @param sub the SubString to get the Parameters from. |
---|
| 242 | */ |
---|
[9736] | 243 | virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const |
---|
[7716] | 244 | { |
---|
| 245 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
[9736] | 246 | Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue)); |
---|
[7716] | 247 | }; |
---|
[5153] | 248 | |
---|
[7724] | 249 | /** |
---|
| 250 | * @brief copies the Executor |
---|
| 251 | * @returns a new Executor that's a copy of this one. |
---|
| 252 | */ |
---|
[9735] | 253 | virtual Executor<CallType, BaseClass>* clone() const |
---|
[7719] | 254 | { |
---|
[9731] | 255 | return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, CallType, type0>(this->functionPointer); |
---|
[7717] | 256 | }; |
---|
[7716] | 257 | }; |
---|
[5145] | 258 | |
---|
[9735] | 259 | |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | |
---|
[8035] | 263 | /////////// |
---|
| 264 | //// 2 //// |
---|
| 265 | /////////// |
---|
[7724] | 266 | //! @brief ExecutorClass, that can execute Functions with two parameters. |
---|
[9736] | 267 | template<class T, typename CallType, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject> |
---|
[9735] | 268 | class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<CallType, BaseClass> |
---|
[7716] | 269 | { |
---|
| 270 | private: |
---|
[7724] | 271 | /** @brief the FunctioPointer. */ |
---|
[7716] | 272 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5145] | 273 | |
---|
[7714] | 274 | public: |
---|
[7724] | 275 | /** |
---|
| 276 | * @brief constructs the Executor. |
---|
| 277 | * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function. |
---|
| 278 | */ |
---|
[7716] | 279 | __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST) |
---|
[9736] | 280 | : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE) |
---|
[7714] | 281 | { |
---|
[7716] | 282 | this->functionPointer = functionPointer; |
---|
[7717] | 283 | }; |
---|
| 284 | |
---|
[7724] | 285 | /** |
---|
| 286 | * @brief executes the Functional |
---|
| 287 | * @param object the Object the action should be executed on. |
---|
| 288 | * @param sub the SubString to get the Parameters from. |
---|
| 289 | */ |
---|
[9736] | 290 | virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const |
---|
[7714] | 291 | { |
---|
[7716] | 292 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
[9736] | 293 | Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue), |
---|
| 294 | Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue)); |
---|
[7716] | 295 | }; |
---|
[7714] | 296 | |
---|
[7724] | 297 | /** |
---|
| 298 | * @brief copies the Executor |
---|
| 299 | * @returns a new Executor that's a copy of this one. |
---|
| 300 | */ |
---|
[9735] | 301 | virtual Executor<CallType, BaseClass>* clone() const |
---|
[7719] | 302 | { |
---|
[9731] | 303 | return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, CallType, type0, type1>(this->functionPointer); |
---|
[7717] | 304 | }; |
---|
[5129] | 305 | }; |
---|
[5113] | 306 | |
---|
[5632] | 307 | |
---|
[9735] | 308 | |
---|
| 309 | |
---|
| 310 | |
---|
[8035] | 311 | /////////// |
---|
| 312 | //// 3 //// |
---|
| 313 | /////////// |
---|
[7724] | 314 | //! @brief ExecutorClass, that can execute Functions with three parameters. |
---|
[9736] | 315 | template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject> |
---|
[9735] | 316 | class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<CallType, BaseClass> |
---|
[7719] | 317 | { |
---|
| 318 | private: |
---|
[7724] | 319 | /** @brief the FunctioPointer. */ |
---|
[7719] | 320 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[5326] | 321 | |
---|
[7719] | 322 | public: |
---|
[7724] | 323 | /** |
---|
| 324 | * @brief constructs the Executor. |
---|
| 325 | * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function. |
---|
| 326 | */ |
---|
[7719] | 327 | __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST) |
---|
[9736] | 328 | : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE) |
---|
[7719] | 329 | { |
---|
| 330 | this->functionPointer = functionPointer; |
---|
| 331 | }; |
---|
[7716] | 332 | |
---|
[7724] | 333 | /** |
---|
| 334 | * @brief executes the Functional |
---|
| 335 | * @param object the Object the action should be executed on. |
---|
| 336 | * @param sub the SubString to get the Parameters from. |
---|
| 337 | */ |
---|
[9736] | 338 | virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const |
---|
[7719] | 339 | { |
---|
| 340 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
[9736] | 341 | Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue), |
---|
| 342 | Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue), |
---|
| 343 | Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue)); |
---|
[7719] | 344 | }; |
---|
[7718] | 345 | |
---|
[7724] | 346 | /** |
---|
| 347 | * @brief copies the Executor |
---|
| 348 | * @returns a new Executor that's a copy of this one. |
---|
| 349 | */ |
---|
[9735] | 350 | virtual Executor<CallType, BaseClass>* clone() const |
---|
[7719] | 351 | { |
---|
[9731] | 352 | return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, CallType, type0, type1, type2>(this->functionPointer); |
---|
[7719] | 353 | }; |
---|
| 354 | }; |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | |
---|
[9735] | 358 | |
---|
| 359 | |
---|
[8035] | 360 | /////////// |
---|
| 361 | //// 4 //// |
---|
| 362 | /////////// |
---|
[7724] | 363 | //! @brief ExecutorClass, that can execute Functions with four parameters. |
---|
[9736] | 364 | template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject> |
---|
[9735] | 365 | class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<CallType, BaseClass> |
---|
[7719] | 366 | { |
---|
| 367 | private: |
---|
[7724] | 368 | /** @brief the FunctioPointer. */ |
---|
[7719] | 369 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST; |
---|
| 370 | |
---|
| 371 | public: |
---|
[7724] | 372 | /** |
---|
| 373 | * @brief constructs the Executor. |
---|
| 374 | * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function. |
---|
| 375 | */ |
---|
[7719] | 376 | __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST) |
---|
[9736] | 377 | : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE) |
---|
[7719] | 378 | { |
---|
| 379 | this->functionPointer = functionPointer; |
---|
| 380 | }; |
---|
| 381 | |
---|
[7724] | 382 | /** |
---|
| 383 | * @brief executes the Functional |
---|
| 384 | * @param object the Object the action should be executed on. |
---|
| 385 | * @param sub the SubString to get the Parameters from. |
---|
| 386 | */ |
---|
[9736] | 387 | virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const |
---|
[7719] | 388 | { |
---|
| 389 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
[9736] | 390 | Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue), |
---|
| 391 | Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue), |
---|
| 392 | Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue), |
---|
| 393 | Evaluater<CallType>().template operator()<type3, 3>(sub, this->defaultValue)); |
---|
[7719] | 394 | }; |
---|
| 395 | |
---|
[7724] | 396 | /** |
---|
| 397 | * @brief copies the Executor |
---|
| 398 | * @returns a new Executor that's a copy of this one. |
---|
| 399 | */ |
---|
[9735] | 400 | virtual Executor<CallType, BaseClass>* clone() const |
---|
[7719] | 401 | { |
---|
[9731] | 402 | return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, CallType, type0, type1, type2, type3>(this->functionPointer); |
---|
[7719] | 403 | }; |
---|
| 404 | }; |
---|
| 405 | |
---|
[8035] | 406 | |
---|
| 407 | |
---|
[9735] | 408 | |
---|
| 409 | |
---|
| 410 | |
---|
[8035] | 411 | /////////// |
---|
| 412 | //// 5 //// |
---|
| 413 | /////////// |
---|
[7724] | 414 | //! @brief ExecutorClass, that can execute Functions with five parameters. |
---|
[9736] | 415 | template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject> |
---|
[9735] | 416 | class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<CallType, BaseClass> |
---|
[7719] | 417 | { |
---|
[7724] | 418 | private: |
---|
| 419 | /** @brief the FunctioPointer. */ |
---|
| 420 | void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST; |
---|
[7719] | 421 | |
---|
[7724] | 422 | public: |
---|
| 423 | /** |
---|
| 424 | * @brief constructs the Executor. |
---|
| 425 | * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function. |
---|
| 426 | */ |
---|
| 427 | __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST) |
---|
[9736] | 428 | : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE) |
---|
[7724] | 429 | { |
---|
| 430 | this->functionPointer = functionPointer; |
---|
| 431 | }; |
---|
[7719] | 432 | |
---|
[7724] | 433 | /** |
---|
| 434 | * @brief executes the Functional |
---|
| 435 | * @param object the Object the action should be executed on. |
---|
| 436 | * @param sub the SubString to get the Parameters from. |
---|
| 437 | */ |
---|
[9736] | 438 | virtual void operator()(BaseObject* object, CallType& sub = Evaluater<CallType>::defaultValue()) const |
---|
[7724] | 439 | { |
---|
| 440 | (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( |
---|
[9736] | 441 | Evaluater<CallType>().template operator()<type0, 0>(sub, this->defaultValue), |
---|
| 442 | Evaluater<CallType>().template operator()<type1, 1>(sub, this->defaultValue), |
---|
| 443 | Evaluater<CallType>().template operator()<type2, 2>(sub, this->defaultValue), |
---|
| 444 | Evaluater<CallType>().template operator()<type3, 3>(sub, this->defaultValue), |
---|
| 445 | Evaluater<CallType>().template operator()<type4, 4>(sub, this->defaultValue)); |
---|
[7724] | 446 | }; |
---|
[7719] | 447 | |
---|
[7724] | 448 | /** |
---|
| 449 | * @brief copies the Executor |
---|
| 450 | * @returns a new Executor that's a copy of this one. |
---|
| 451 | */ |
---|
[9735] | 452 | virtual Executor<CallType, BaseClass>* clone() const |
---|
[7724] | 453 | { |
---|
[9731] | 454 | return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, CallType, type0, type1, type2, type3, type4>(this->functionPointer); |
---|
[7724] | 455 | }; |
---|
[7719] | 456 | }; |
---|
| 457 | |
---|
| 458 | |
---|
| 459 | |
---|
[9731] | 460 | |
---|
| 461 | |
---|
| 462 | |
---|
| 463 | |
---|
| 464 | |
---|
| 465 | |
---|
| 466 | // // // // // // // // // // // // // |
---|
| 467 | //// EXTENSION TO HIDE CONSTRUCT ///// |
---|
| 468 | // // // // // // // // // // // // // |
---|
[7724] | 469 | /** |
---|
| 470 | * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all) |
---|
| 471 | */ |
---|
[8048] | 472 | #define EXECUTOR_FUNCTIONAL_CREATOR0() \ |
---|
[9727] | 473 | template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
[7718] | 474 | { \ |
---|
[9731] | 475 | return new __EXECUTOR_FUNCTIONAL_NAME(0)<T, const SubString>(functionPointer); \ |
---|
[7716] | 476 | } |
---|
[7718] | 477 | |
---|
[7724] | 478 | /** |
---|
| 479 | * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all) |
---|
| 480 | * @param type0 for internal usage: the first Argument |
---|
| 481 | */ |
---|
[8048] | 482 | #define EXECUTOR_FUNCTIONAL_CREATOR1(type0) \ |
---|
[9732] | 483 | template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
[7718] | 484 | { \ |
---|
[9732] | 485 | return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, const SubString, type0>(functionPointer); \ |
---|
[7716] | 486 | } |
---|
[7718] | 487 | |
---|
[7724] | 488 | /** |
---|
| 489 | * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all) |
---|
| 490 | * @param type0 for internal usage: the first Argument |
---|
| 491 | * @param type1 for internal usage: the second Argument |
---|
| 492 | */ |
---|
[8048] | 493 | #define EXECUTOR_FUNCTIONAL_CREATOR2(type0, type1) \ |
---|
[9732] | 494 | template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
[7718] | 495 | { \ |
---|
[9732] | 496 | return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, const SubString, type0, type1>(functionPointer); \ |
---|
[7716] | 497 | } |
---|
[5641] | 498 | |
---|
[7724] | 499 | /** |
---|
| 500 | * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all) |
---|
| 501 | * @param type0 for internal usage: the first Argument |
---|
| 502 | * @param type1 for internal usage: the second Argument |
---|
| 503 | * @param type2 for internal usage: the third Argument |
---|
| 504 | */ |
---|
[8048] | 505 | #define EXECUTOR_FUNCTIONAL_CREATOR3(type0, type1, type2) \ |
---|
[9732] | 506 | template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
[7719] | 507 | { \ |
---|
[9732] | 508 | return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, const SubString, type0, type1, type2>(functionPointer); \ |
---|
[7719] | 509 | } |
---|
[5326] | 510 | |
---|
[7724] | 511 | /** |
---|
| 512 | * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all) |
---|
| 513 | * @param type0 for internal usage: the first Argument |
---|
| 514 | * @param type1 for internal usage: the second Argument |
---|
| 515 | * @param type2 for internal usage: the third Argument |
---|
| 516 | * @param type3 for internal usage: the fourth Argument |
---|
| 517 | */ |
---|
[8048] | 518 | #define EXECUTOR_FUNCTIONAL_CREATOR4(type0, type1, type2, type3) \ |
---|
[9732] | 519 | template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
[7719] | 520 | { \ |
---|
[9732] | 521 | return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, const SubString, type0, type1, type2, type3>(functionPointer); \ |
---|
[7719] | 522 | } |
---|
[7718] | 523 | |
---|
[7724] | 524 | /** |
---|
| 525 | * @brief enables us to easily retrieve an Executor of Class T with modular Argument-count, (without thinking about args at all) |
---|
| 526 | * @param type0 for internal usage: the first Argument |
---|
| 527 | * @param type1 for internal usage: the second Argument |
---|
| 528 | * @param type2 for internal usage: the third Argument |
---|
| 529 | * @param type3 for internal usage: the fourth Argument |
---|
| 530 | * @param type4 for internal usage: the fifth Argument |
---|
| 531 | */ |
---|
[8048] | 532 | #define EXECUTOR_FUNCTIONAL_CREATOR5(type0, type1, type2, type3, type4) \ |
---|
[9732] | 533 | template<class T> Executor<const SubString>* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST) \ |
---|
[7719] | 534 | { \ |
---|
[9732] | 535 | return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, const SubString, type0, type1, type2, type3, type4>(functionPointer); \ |
---|
[7719] | 536 | } |
---|
[7718] | 537 | |
---|
[7719] | 538 | |
---|
[7724] | 539 | /** |
---|
| 540 | * Creates the FunctionCallers |
---|
| 541 | */ |
---|
[7718] | 542 | #define FUNCTOR_LIST(x) EXECUTOR_FUNCTIONAL_CREATOR ## x |
---|
| 543 | #include "functor_list.h" |
---|
| 544 | #undef FUNCTOR_LIST |
---|
| 545 | |
---|
| 546 | |
---|
| 547 | |
---|
[7716] | 548 | #undef __EXECUTOR_FUNCTIONAL_CONST |
---|
| 549 | #undef __EXECUTOR_FUNCTIONAL_NAME |
---|
| 550 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC |
---|
| 551 | #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER |
---|
[9735] | 552 | #undef __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE |
---|
[7725] | 553 | |
---|
| 554 | #ifdef EXECUTOR_FUNCTIONAL_USE_CONST |
---|
| 555 | #undef EXECUTOR_FUNCTIONAL_USE_CONST |
---|
| 556 | #endif |
---|
| 557 | #ifdef EXECUTOR_FUNCTIONAL_USE_STATIC |
---|
| 558 | #undef EXECUTOR_FUNCTIONAL_USE_STATIC |
---|
| 559 | #endif |
---|
[9728] | 560 | |
---|
| 561 | |
---|
| 562 | #endif /* __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS */ |
---|
| 563 | #undef __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS |
---|