[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 | */ |
---|
[9735] | 41 | template <typename CallType, class BaseClass = BaseObject> class Executor |
---|
[5170] | 42 | { |
---|
[9727] | 43 | public: |
---|
[9733] | 44 | //! an enumerator for the definition of the Type. |
---|
| 45 | typedef enum { |
---|
[9737] | 46 | FunctionMember, //!< The function is neither Static nor Constant |
---|
[9735] | 47 | FunctionStatic, //!< The Function is Static and pointing to either a Static Member or a C-style function. |
---|
[9737] | 48 | FunctionConstMember, //!< The Function is Constant and pointing to a Member that does not change the Object. |
---|
[9733] | 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 */ |
---|
[9735] | 69 | virtual void operator()(BaseClass* object, CallType& values) const = 0; |
---|
[9727] | 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 | |
---|
[9735] | 105 | /** @returns the Clone as a new Copy of the Executor. */ |
---|
[9733] | 106 | virtual Executor<CallType>* clone () const = 0; |
---|
| 107 | |
---|
[9734] | 108 | |
---|
[9727] | 109 | protected: |
---|
[9734] | 110 | //! Now follows a List of Executor Constructors, to be fast in creating. |
---|
[9737] | 111 | Executor(bool hasRetVal, FunctionType functionType = FunctionMember) |
---|
[9734] | 112 | : bRetVal(hasRetVal), paramCount(0), functionType(functionType) |
---|
| 113 | { }; |
---|
| 114 | |
---|
| 115 | Executor(bool hasRetVal, const MultiType& param0, |
---|
[9737] | 116 | FunctionType functionType = FunctionMember) |
---|
[9734] | 117 | : bRetVal(hasRetVal), paramCount(1), functionType(functionType) |
---|
[9733] | 118 | { |
---|
| 119 | this->defaultValue[0] = param0; |
---|
[9734] | 120 | }; |
---|
| 121 | |
---|
| 122 | Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, |
---|
[9737] | 123 | FunctionType functionType = FunctionMember) |
---|
[9734] | 124 | : bRetVal(hasRetVal), paramCount(2), functionType(functionType) |
---|
| 125 | { |
---|
| 126 | this->defaultValue[0] = param0; |
---|
[9733] | 127 | this->defaultValue[1] = param1; |
---|
[9734] | 128 | }; |
---|
| 129 | |
---|
| 130 | Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, |
---|
| 131 | const MultiType& param2, |
---|
[9737] | 132 | FunctionType functionType = FunctionMember) |
---|
[9734] | 133 | : bRetVal(hasRetVal), paramCount(3), functionType(functionType) |
---|
| 134 | { |
---|
| 135 | this->defaultValue[0] = param0; |
---|
| 136 | this->defaultValue[1] = param1; |
---|
[9733] | 137 | this->defaultValue[2] = param2; |
---|
[9734] | 138 | }; |
---|
| 139 | |
---|
| 140 | Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, |
---|
| 141 | const MultiType& param2, const MultiType& param3, |
---|
[9737] | 142 | FunctionType functionType = FunctionMember) |
---|
[9734] | 143 | : bRetVal(hasRetVal), paramCount(4), functionType(functionType) |
---|
| 144 | { |
---|
| 145 | this->defaultValue[0] = param0; |
---|
| 146 | this->defaultValue[1] = param1; |
---|
| 147 | this->defaultValue[2] = param2; |
---|
[9733] | 148 | this->defaultValue[3] = param3; |
---|
[9734] | 149 | }; |
---|
| 150 | |
---|
| 151 | Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, |
---|
| 152 | const MultiType& param2, const MultiType& param3, |
---|
| 153 | const MultiType& param4, |
---|
[9737] | 154 | FunctionType functionType = FunctionMember) |
---|
[9734] | 155 | : bRetVal(hasRetVal), paramCount(5), functionType(functionType) |
---|
| 156 | { |
---|
| 157 | this->defaultValue[0] = param0; |
---|
| 158 | this->defaultValue[1] = param1; |
---|
| 159 | this->defaultValue[2] = param2; |
---|
| 160 | this->defaultValue[3] = param3; |
---|
[9733] | 161 | this->defaultValue[4] = param4; |
---|
[9734] | 162 | }; |
---|
| 163 | |
---|
| 164 | Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, |
---|
| 165 | const MultiType& param2, const MultiType& param3, |
---|
| 166 | const MultiType& param4, const MultiType& param5, |
---|
[9737] | 167 | FunctionType functionType = FunctionMember) |
---|
[9734] | 168 | : bRetVal(hasRetVal), paramCount(6), functionType(functionType) |
---|
| 169 | { |
---|
| 170 | this->defaultValue[0] = param0; |
---|
| 171 | this->defaultValue[1] = param1; |
---|
| 172 | this->defaultValue[2] = param2; |
---|
| 173 | this->defaultValue[3] = param3; |
---|
| 174 | this->defaultValue[4] = param4; |
---|
[9733] | 175 | this->defaultValue[5] = param5; |
---|
[9734] | 176 | }; |
---|
| 177 | |
---|
| 178 | Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, |
---|
| 179 | const MultiType& param2, const MultiType& param3, |
---|
| 180 | const MultiType& param4, const MultiType& param5, |
---|
| 181 | const MultiType& param6, |
---|
[9737] | 182 | FunctionType functionType = FunctionMember) |
---|
[9734] | 183 | : bRetVal(hasRetVal), paramCount(7), functionType(functionType) |
---|
| 184 | { |
---|
| 185 | this->defaultValue[0] = param0; |
---|
| 186 | this->defaultValue[1] = param1; |
---|
| 187 | this->defaultValue[2] = param2; |
---|
| 188 | this->defaultValue[3] = param3; |
---|
| 189 | this->defaultValue[4] = param4; |
---|
| 190 | this->defaultValue[5] = param5; |
---|
[9733] | 191 | this->defaultValue[6] = param6; |
---|
[9734] | 192 | }; |
---|
[9727] | 193 | |
---|
[9733] | 194 | protected: |
---|
[9734] | 195 | const bool bRetVal; //!< True if the Executor has a return Value. |
---|
[9735] | 196 | const unsigned int paramCount; //!< the count of parameters. |
---|
[9733] | 197 | MultiType defaultValue[7]; //!< Default Values. |
---|
| 198 | |
---|
[9734] | 199 | const FunctionType functionType; //!< What Type of Function it is. |
---|
[9733] | 200 | }; |
---|
| 201 | |
---|
[5632] | 202 | #endif /* _EXECUTOR_H */ |
---|