Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: new Executor construct, that is much more typesafe, faster, and easier to extend…

Also changed the LoadParam process, and adapted ScriptEngine calls

Then at the end, some missing headers appeared, and appended them to all the cc-files again.

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