Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/lib/util/executor/executor.h @ 10673

Last change on this file since 10673 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 8.2 KB
Line 
1/*!
2 * @file executor.h
3 * Definition of an Executor
4 */
5
6#ifndef _EXECUTOR_H
7#define _EXECUTOR_H
8
9#include "base_object.h"
10
11#include "multi_type.h"
12
13//! The maximum Count of Arguments of the Executor
14/** This is Hardcoded, for each Executor. */
15#define EXECUTOR_MAX_ARGUMENTS                7
16
17
18/** @returns the Type of an Argument taken by the Executor */
19template<typename type> inline MT_Type ExecutorParamType() { return MT_EXT1; };
20/** @returns the Type of an Argument taken by the Executor in this case MT_BOOL */
21template<> inline MT_Type ExecutorParamType<bool>() { return MT_BOOL; };
22/** @returns the Type of an Argument taken by the Executor in this case MT_INT*/
23template<> inline MT_Type ExecutorParamType<int>() { return MT_INT; };
24/** @returns the Type of an Argument taken by the Executor in this case MT_UINT*/
25template<> inline MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; };
26/** @returns the Type of an Argument taken by the Executor in this case MT_FLOAT*/
27template<> inline MT_Type ExecutorParamType<float>() { return MT_FLOAT; };
28/** @returns the Type of an Argument taken by the Executor in this case MT_CHAR*/
29template<> inline MT_Type ExecutorParamType<char>() { return MT_CHAR; };
30/** @returns the Type of an Argument taken by the Executor in this case MT_STRING*/
31template<> inline MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; };
32
33////////////////
34// BASE CLASS //
35////////////////
36//! a BaseClass for all possible Executors
37/**
38 * An Executor is an Object, that is able to call Objects of Any type (class)
39 * and execute a function with given parameters on it.
40 *
41 * The Executor is able to handle:
42 *  Objects of any Class (Templated)
43 *  Default Values
44 *  Functions with up to 5 parameters (more seems overhead, split up the function)
45 *  Functions with many types (@see functor_list.h)
46 */
47template <typename CallType, class BaseClass = BaseObject> class Executor
48{
49public:
50  //! an enumerator for the definition of the Type.
51  typedef enum {
52    FunctionMember,      //!< The function is neither Static nor Constant
53    FunctionStatic,      //!< The Function is Static and pointing to either a Static Member or a C-style function.
54    FunctionConstMember, //!< The Function is Constant and pointing to a Member that does not change the Object.
55  } FunctionType;
56
57public:
58  virtual ~Executor() {};
59
60  // RETRIEVE INFORMATION
61  /** @param i the i'th defaultValue, @returns reference to the MultiType */
62  inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
63  /** @returns the default Values as a List */
64  inline const MultiType* const getDefaultValues() { return defaultValue; };
65
66  /** @returns the Type of this Function (either static or objective) */
67  inline FunctionType getType() const { return this->functionType; };
68
69  /** @returns the Count of Parameters this Executor takes */
70  inline unsigned int getParamCount() const { return this->paramCount; };
71  /** @returns true if the Executor has a return Value. */
72  inline bool hasRetVal() const { return bRetVal; };
73
74  /** executes a Command. @param object the Object, @param values The Value of type CallType to pass to the Executor. */
75  virtual void operator()(BaseClass* object, CallType& values) const = 0;
76
77  /**
78   * @brief set the default values of the executor
79   * @param value0 the first default value
80   * @param value1 the second default value
81   * @param value2 the third default value
82   * @param value3 the fourth default value
83   * @param value4 the fifth default value
84   * @param value5 the sixth default value
85   * @param value6 the seventh default value
86   * @returns itself
87   * @note: THIS FUNCTION WILL BE REPLACED BY A CONFIGURATOR (most probably).
88  */
89  Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
90                          const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
91                          const MultiType& value4 = MT_NULL, const MultiType& value5 = MT_NULL,
92                          const MultiType& value6 = MT_NULL)
93  {
94    const MultiType* value[5];
95    value[0] = &value0;
96    value[1] = &value1;
97    value[2] = &value2;
98    value[3] = &value3;
99    value[4] = &value4;
100    value[5] = &value5;
101    value[6] = &value6;
102    for (unsigned int i = 0; i < this->paramCount; i++)
103    {
104      if (*value[i] != MT_NULL)
105      {
106        this->defaultValue[i].setValueOf(*value[i]);
107        this->defaultValue[i].storeString();
108      }
109    }
110    return this;
111  }
112
113  /** @returns the Clone as a new Copy of the Executor. */
114  virtual Executor<CallType, BaseClass>* clone () const = 0;
115
116
117protected:
118  //! Now follows a List of Executor Constructors, to be fast in creating.
119  //! Creates an Executor with no Argument.
120  Executor(bool hasRetVal, FunctionType functionType = FunctionMember)
121  : bRetVal(hasRetVal), paramCount(0), functionType(functionType)
122  { };
123
124  //! Creates an Executor with 1 Argument.
125  Executor(bool hasRetVal, const MultiType& param0,
126           FunctionType functionType = FunctionMember)
127  : bRetVal(hasRetVal), paramCount(1), functionType(functionType)
128  {
129    this->defaultValue[0] = param0;
130  };
131
132  //! Creates an Executor with 2 Arguments.
133  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
134           FunctionType functionType = FunctionMember)
135  : bRetVal(hasRetVal), paramCount(2), functionType(functionType)
136  {
137    this->defaultValue[0] = param0;
138    this->defaultValue[1] = param1;
139  };
140
141  //! Creates an Executor with 3 Arguments.
142  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
143           const MultiType& param2,
144           FunctionType functionType = FunctionMember)
145  : bRetVal(hasRetVal), paramCount(3), functionType(functionType)
146  {
147    this->defaultValue[0] = param0;
148    this->defaultValue[1] = param1;
149    this->defaultValue[2] = param2;
150  };
151
152  //! Creates an Executor with 4 Arguments.
153  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
154           const MultiType& param2, const MultiType& param3,
155           FunctionType functionType = FunctionMember)
156  : bRetVal(hasRetVal), paramCount(4), functionType(functionType)
157  {
158    this->defaultValue[0] = param0;
159    this->defaultValue[1] = param1;
160    this->defaultValue[2] = param2;
161    this->defaultValue[3] = param3;
162  };
163
164  //! Creates an Executor with 5 Arguments.
165  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
166           const MultiType& param2, const MultiType& param3,
167           const MultiType& param4,
168           FunctionType functionType = FunctionMember)
169  : bRetVal(hasRetVal), paramCount(5), functionType(functionType)
170  {
171    this->defaultValue[0] = param0;
172    this->defaultValue[1] = param1;
173    this->defaultValue[2] = param2;
174    this->defaultValue[3] = param3;
175    this->defaultValue[4] = param4;
176  };
177
178  //! Creates an Executor with 6 Arguments.
179  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
180           const MultiType& param2, const MultiType& param3,
181           const MultiType& param4, const MultiType& param5,
182           FunctionType functionType = FunctionMember)
183  : bRetVal(hasRetVal), paramCount(6), 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;
191  };
192
193  //! Creates an Executor with 7 Arguments.
194  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
195           const MultiType& param2, const MultiType& param3,
196           const MultiType& param4, const MultiType& param5,
197           const MultiType& param6,
198           FunctionType functionType = FunctionMember)
199  : bRetVal(hasRetVal), paramCount(7), functionType(functionType)
200  {
201    this->defaultValue[0] = param0;
202    this->defaultValue[1] = param1;
203    this->defaultValue[2] = param2;
204    this->defaultValue[3] = param3;
205    this->defaultValue[4] = param4;
206    this->defaultValue[5] = param5;
207    this->defaultValue[6] = param6;
208  };
209
210protected:
211  const bool                  bRetVal;          //!< True if the Executor has a return Value.
212  const unsigned int          paramCount;       //!< the count of parameters.
213  MultiType                   defaultValue[7];  //!< Default Values.
214
215  const FunctionType          functionType;     //!< What Type of Function it is.
216};
217
218#endif /* _EXECUTOR_H */
Note: See TracBrowser for help on using the repository browser.