Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

cleaned out useless non-portable stuff

File size: 4.8 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 "helper_functions.h"
12#include "multi_type.h"
13#include "functor_list.h" //< MUST BE INCLUDED HERE AT LEAST ONCE.
14
15//! an enumerator for the definition of the Type.
16typedef enum {
17  Executor_Objective,
18  Executor_Static,
19} Executor_Type;
20
21//! The maximum Count of Arguments of the Executor
22/** This is Hardcoded, for each Executor. */
23#define EXECUTOR_MAX_ARGUMENTS                7
24
25
26
27template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; };
28template<> MT_Type ExecutorParamType<bool>();
29template<> MT_Type ExecutorParamType<int>();
30template<> MT_Type ExecutorParamType<unsigned int>();
31template<> MT_Type ExecutorParamType<float>();
32template<> MT_Type ExecutorParamType<char>();
33template<> MT_Type ExecutorParamType<const std::string&>();
34
35////////////////
36// BASE CLASS //
37////////////////
38//! a BaseClass for all possible Executors
39/**
40 * An Executor is an Object, that is able to call Objects of Any type (class)
41 * and execute a function with given parameters on it.
42 *
43 * The Executor is able to handle:
44 *  Objects of any Class (Templated)
45 *  Default Values
46 *  Functions with up to 5 parameters (more seems overhead, split up the function)
47 *  Functions with many types (@see functor_list.h)
48 */
49class ExecutorBase
50{
51public:
52  /** @param i the i'th defaultValue, @returns reference to the MultiType */
53  inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
54
55  // RETRIEVE INFORMATION
56  /** @returns the Type of this Function (either static or objective) */
57  inline Executor_Type getType() const { return this->functorType; };
58
59  /** @returns the Count of Parameters this Executor takes */
60  inline unsigned int getParamCount() const { return this->paramCount; };
61  /** @returns true if the Executor has a return Value. */
62  inline bool hasRetVal() const { return bRetVal; };
63
64  static void debug();
65
66protected:
67  virtual ~ExecutorBase() {};
68  ExecutorBase(bool hasRetVal = false,
69               const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL,
70               const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL,
71               const MultiType& param4 = MT_NULL, const MultiType& param5 = MT_NULL,
72               const MultiType& param6 = MT_NULL);
73
74  // SETTING up the EXECUTOR
75  void defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
76                     const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
77                     const MultiType& value4 = MT_NULL, const MultiType& param5 = MT_NULL,
78                     const MultiType& param6 = MT_NULL);
79
80  void cloning(ExecutorBase* executor) const;
81
82protected:
83  Executor_Type               functorType;      //!< The type of Function we've got (either static or objective).
84  unsigned int                paramCount;       //!< the count of parameters.
85  MultiType                   defaultValue[7];  //!< Default Values.
86
87private:
88  const bool                  bRetVal;          //!< True if the Executor has a return Value.
89  const bool                  bStaticFunction;  //!< A Executor to a Static Function
90  const bool                  bConstFunction;   //!< A Executor to a Constant Function
91};
92
93template <typename CallType> class Executor : public ExecutorBase
94{
95public:
96  virtual Executor<CallType>* clone () const = 0;
97
98  /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
99  virtual void operator()(BaseObject* object, CallType& values) const = 0;
100
101  /**
102   * @brief set the default values of the executor
103   * @param value0 the first default value
104   * @param value1 the second default value
105   * @param value2 the third default value
106   * @param value3 the fourth default value
107   * @param value4 the fifth default value
108   * @returns itself
109   * @note: THIS FUNCTION WILL BE REPLACED BY A CONFIGURATOR (most probably).
110  */
111  Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
112                          const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
113                          const MultiType& value4 = MT_NULL, const MultiType& value5 = MT_NULL,
114                          const MultiType& value6 = MT_NULL)
115  {
116    this->ExecutorBase::defaultValues(value0, value1, value2, value3, value4, value5, value6);
117    return this;
118  }
119
120protected:
121  Executor(bool hasRetVal,
122           const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL,
123           const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL,
124           const MultiType& param4 = MT_NULL, const MultiType& param5 = MT_NULL,
125           const MultiType& param6 = MT_NULL)
126      : ExecutorBase(hasRetVal, param0, param1, param2, param3, param4, param5, param6)
127{}}
128;
129
130#endif /* _EXECUTOR_H */
Note: See TracBrowser for help on using the repository browser.