Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/executor/executor.h @ 9734

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

new_class_id: better constructs for the Executor.

File size: 6.7 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
19template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; };
20template<> MT_Type ExecutorParamType<bool>();
21template<> MT_Type ExecutorParamType<int>();
22template<> MT_Type ExecutorParamType<unsigned int>();
23template<> MT_Type ExecutorParamType<float>();
24template<> MT_Type ExecutorParamType<char>();
25template<> MT_Type ExecutorParamType<const std::string&>();
26
27////////////////
28// BASE CLASS //
29////////////////
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
38 *  Functions with up to 5 parameters (more seems overhead, split up the function)
39 *  Functions with many types (@see functor_list.h)
40 */
41template <typename CallType> class Executor
42{
43public:
44  //! an enumerator for the definition of the Type.
45  typedef enum {
46    FunctionDefault,
47    FunctionStatic,
48    FunctionConst,
49  } FunctionType;
50
51public:
52  virtual ~Executor() {};
53
54  // RETRIEVE INFORMATION
55  /** @param i the i'th defaultValue, @returns reference to the MultiType */
56  inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
57  /** @returns the default Values as a List */
58  inline const MultiType* const getDefaultValues() { return defaultValue; };
59
60  /** @returns the Type of this Function (either static or objective) */
61  inline FunctionType getType() const { return this->functionType; };
62
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; };
67
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  {
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    }
102    return this;
103  }
104
105  virtual Executor<CallType>* clone () const = 0;
106
107
108protected:
109  //! Now follows a List of Executor Constructors, to be fast in creating.
110  Executor(bool hasRetVal, FunctionType functionType = FunctionDefault)
111  : bRetVal(hasRetVal), paramCount(0), functionType(functionType)
112  { };
113
114  Executor(bool hasRetVal, const MultiType& param0,
115           FunctionType functionType = FunctionDefault)
116  : bRetVal(hasRetVal), paramCount(1), functionType(functionType)
117  {
118    this->defaultValue[0] = param0;
119  };
120
121  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
122           FunctionType functionType = FunctionDefault)
123  : bRetVal(hasRetVal), paramCount(2), functionType(functionType)
124  {
125    this->defaultValue[0] = param0;
126    this->defaultValue[1] = param1;
127  };
128
129  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
130           const MultiType& param2,
131           FunctionType functionType = FunctionDefault)
132  : bRetVal(hasRetVal), paramCount(3), functionType(functionType)
133  {
134    this->defaultValue[0] = param0;
135    this->defaultValue[1] = param1;
136    this->defaultValue[2] = param2;
137  };
138
139  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
140           const MultiType& param2, const MultiType& param3,
141           FunctionType functionType = FunctionDefault)
142  : bRetVal(hasRetVal), paramCount(4), functionType(functionType)
143  {
144    this->defaultValue[0] = param0;
145    this->defaultValue[1] = param1;
146    this->defaultValue[2] = param2;
147    this->defaultValue[3] = param3;
148  };
149
150  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
151           const MultiType& param2, const MultiType& param3,
152           const MultiType& param4,
153           FunctionType functionType = FunctionDefault)
154  : bRetVal(hasRetVal), paramCount(5), functionType(functionType)
155  {
156    this->defaultValue[0] = param0;
157    this->defaultValue[1] = param1;
158    this->defaultValue[2] = param2;
159    this->defaultValue[3] = param3;
160    this->defaultValue[4] = param4;
161  };
162
163  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
164           const MultiType& param2, const MultiType& param3,
165           const MultiType& param4, const MultiType& param5,
166           FunctionType functionType = FunctionDefault)
167  : bRetVal(hasRetVal), paramCount(6), functionType(functionType)
168  {
169    this->defaultValue[0] = param0;
170    this->defaultValue[1] = param1;
171    this->defaultValue[2] = param2;
172    this->defaultValue[3] = param3;
173    this->defaultValue[4] = param4;
174    this->defaultValue[5] = param5;
175  };
176
177  Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1,
178           const MultiType& param2, const MultiType& param3,
179           const MultiType& param4, const MultiType& param5,
180           const MultiType& param6,
181           FunctionType functionType = FunctionDefault)
182  : bRetVal(hasRetVal), paramCount(7), functionType(functionType)
183  {
184    this->defaultValue[0] = param0;
185    this->defaultValue[1] = param1;
186    this->defaultValue[2] = param2;
187    this->defaultValue[3] = param3;
188    this->defaultValue[4] = param4;
189    this->defaultValue[5] = param5;
190    this->defaultValue[6] = param6;
191  };
192
193protected:
194  const bool                  bRetVal;          //!< True if the Executor has a return Value.
195  unsigned int                paramCount;       //!< the count of parameters.
196  MultiType                   defaultValue[7];  //!< Default Values.
197
198  const FunctionType          functionType;     //!< What Type of Function it is.
199};
200
201#endif /* _EXECUTOR_H */
Note: See TracBrowser for help on using the repository browser.