[4838] | 1 | /*! |
---|
[5632] | 2 | * @file executor.h |
---|
[7197] | 3 | * Definition of an Executor |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[5632] | 6 | #ifndef _EXECUTOR_H |
---|
| 7 | #define _EXECUTOR_H |
---|
[1853] | 8 | |
---|
[5129] | 9 | #include "base_object.h" |
---|
[1853] | 10 | |
---|
[5552] | 11 | #include "multi_type.h" |
---|
[5141] | 12 | |
---|
[9732] | 13 | //! The maximum Count of Arguments of the Executor |
---|
| 14 | /** This is Hardcoded, for each Executor. */ |
---|
| 15 | #define EXECUTOR_MAX_ARGUMENTS 7 |
---|
[9728] | 16 | |
---|
| 17 | |
---|
[9732] | 18 | |
---|
[9728] | 19 | template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; }; |
---|
| 20 | template<> MT_Type ExecutorParamType<bool>(); |
---|
| 21 | template<> MT_Type ExecutorParamType<int>(); |
---|
| 22 | template<> MT_Type ExecutorParamType<unsigned int>(); |
---|
| 23 | template<> MT_Type ExecutorParamType<float>(); |
---|
| 24 | template<> MT_Type ExecutorParamType<char>(); |
---|
| 25 | template<> MT_Type ExecutorParamType<const std::string&>(); |
---|
| 26 | |
---|
[5161] | 27 | //////////////// |
---|
| 28 | // BASE CLASS // |
---|
| 29 | //////////////// |
---|
[7197] | 30 | //! a BaseClass for all possible Executors |
---|
| 31 | /** |
---|
| 32 | * An Executor is an Object, that is able to call Objects of Any type (class) |
---|
| 33 | * and execute a function with given parameters on it. |
---|
| 34 | * |
---|
| 35 | * The Executor is able to handle: |
---|
| 36 | * Objects of any Class (Templated) |
---|
| 37 | * Default Values |
---|
[8408] | 38 | * Functions with up to 5 parameters (more seems overhead, split up the function) |
---|
[7331] | 39 | * Functions with many types (@see functor_list.h) |
---|
[7197] | 40 | */ |
---|
[9733] | 41 | template <typename CallType> class Executor |
---|
[5170] | 42 | { |
---|
[9727] | 43 | public: |
---|
[9733] | 44 | //! an enumerator for the definition of the Type. |
---|
| 45 | typedef enum { |
---|
| 46 | FunctionDefault, |
---|
| 47 | FunctionStatic, |
---|
| 48 | FunctionConst, |
---|
| 49 | } FunctionType; |
---|
| 50 | |
---|
| 51 | public: |
---|
| 52 | virtual ~Executor() {}; |
---|
| 53 | |
---|
| 54 | // RETRIEVE INFORMATION |
---|
[9727] | 55 | /** @param i the i'th defaultValue, @returns reference to the MultiType */ |
---|
| 56 | inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; }; |
---|
[9733] | 57 | /** @returns the default Values as a List */ |
---|
| 58 | inline const MultiType* const getDefaultValues() { return defaultValue; }; |
---|
[5641] | 59 | |
---|
[9727] | 60 | /** @returns the Type of this Function (either static or objective) */ |
---|
[9733] | 61 | inline FunctionType getType() const { return this->functionType; }; |
---|
[9730] | 62 | |
---|
[9727] | 63 | /** @returns the Count of Parameters this Executor takes */ |
---|
| 64 | inline unsigned int getParamCount() const { return this->paramCount; }; |
---|
| 65 | /** @returns true if the Executor has a return Value. */ |
---|
| 66 | inline bool hasRetVal() const { return bRetVal; }; |
---|
[5161] | 67 | |
---|
[9727] | 68 | /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */ |
---|
| 69 | virtual void operator()(BaseObject* object, CallType& values) const = 0; |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * @brief set the default values of the executor |
---|
| 73 | * @param value0 the first default value |
---|
| 74 | * @param value1 the second default value |
---|
| 75 | * @param value2 the third default value |
---|
| 76 | * @param value3 the fourth default value |
---|
| 77 | * @param value4 the fifth default value |
---|
| 78 | * @returns itself |
---|
| 79 | * @note: THIS FUNCTION WILL BE REPLACED BY A CONFIGURATOR (most probably). |
---|
| 80 | */ |
---|
| 81 | Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, |
---|
| 82 | const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, |
---|
| 83 | const MultiType& value4 = MT_NULL, const MultiType& value5 = MT_NULL, |
---|
| 84 | const MultiType& value6 = MT_NULL) |
---|
| 85 | { |
---|
[9733] | 86 | const MultiType* value[5]; |
---|
| 87 | value[0] = &value0; |
---|
| 88 | value[1] = &value1; |
---|
| 89 | value[2] = &value2; |
---|
| 90 | value[3] = &value3; |
---|
| 91 | value[4] = &value4; |
---|
| 92 | value[5] = &value5; |
---|
| 93 | value[6] = &value6; |
---|
| 94 | for (unsigned int i = 0; i < this->paramCount; i++) |
---|
| 95 | { |
---|
| 96 | if (*value[i] != MT_NULL) |
---|
| 97 | { |
---|
| 98 | this->defaultValue[i].setValueOf(*value[i]); |
---|
| 99 | this->defaultValue[i].storeString(); |
---|
| 100 | } |
---|
| 101 | } |
---|
[9727] | 102 | return this; |
---|
| 103 | } |
---|
| 104 | |
---|
[9733] | 105 | virtual Executor<CallType>* clone () const = 0; |
---|
| 106 | |
---|
[9727] | 107 | protected: |
---|
| 108 | Executor(bool hasRetVal, |
---|
[9728] | 109 | const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL, |
---|
[9727] | 110 | const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL, |
---|
| 111 | const MultiType& param4 = MT_NULL, const MultiType& param5 = MT_NULL, |
---|
| 112 | const MultiType& param6 = MT_NULL) |
---|
[9733] | 113 | : bRetVal(hasRetVal) |
---|
| 114 | { |
---|
| 115 | // What Parameters have we got |
---|
| 116 | this->defaultValue[0] = param0; |
---|
| 117 | this->defaultValue[1] = param1; |
---|
| 118 | this->defaultValue[2] = param2; |
---|
| 119 | this->defaultValue[3] = param3; |
---|
| 120 | this->defaultValue[4] = param4; |
---|
| 121 | this->defaultValue[5] = param5; |
---|
| 122 | this->defaultValue[6] = param6; |
---|
[9727] | 123 | |
---|
[9733] | 124 | this->paramCount = 0; |
---|
| 125 | for (unsigned int i = 0; i <= EXECUTOR_MAX_ARGUMENTS; i++) |
---|
| 126 | { |
---|
| 127 | if (this->defaultValue[i] == MT_NULL || i == EXECUTOR_MAX_ARGUMENTS) |
---|
| 128 | { |
---|
| 129 | this->paramCount = i; |
---|
| 130 | break; |
---|
| 131 | } |
---|
| 132 | else |
---|
| 133 | this->defaultValue[i].storeString(); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | protected: |
---|
| 140 | unsigned int paramCount; //!< the count of parameters. |
---|
| 141 | MultiType defaultValue[7]; //!< Default Values. |
---|
| 142 | |
---|
| 143 | FunctionType functionType; //!< What Type of Function it is. |
---|
| 144 | private: |
---|
| 145 | const bool bRetVal; //!< True if the Executor has a return Value. |
---|
| 146 | }; |
---|
| 147 | |
---|
[5632] | 148 | #endif /* _EXECUTOR_H */ |
---|