Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: lua_State executor definition

File size: 12.0 KB
Line 
1/*!
2 * @file executor_generic.h
3 * Definition of a Generic Executor
4 */
5
6/*
7   orxonox - the future of 3D-vertical-scrollers
8
9   Copyright (C) 2004 orx
10
11   This program is free software; you can redistribute it and/or modify
12   it under the terms of the GNU General Public License as published by
13   the Free Software Foundation; either version 2, or (at your option)
14   any later version.
15
16### File Specific:
17   main-programmer: Benjamin Grauer
18   co-programmer: ...
19*/
20
21
22
23#ifndef __EXECUTOR_GENERIC_H_
24#define __EXECUTOR_GENERIC_H_
25
26
27#include "executor.h"
28/**
29 * @brief this is a Template Class used as an evaluater.
30 *
31 * Trait to determine a default Value for any Type,
32 * and to define the Convertible, and how it is transformed into the
33 * corresponding SubTypes over the operator().
34 *
35 * This Class must be reimplemented for each Convertible and all of its
36 *  conversion-members.
37 *
38 * e.g: Convertible SubSting, that splits up into many Stings
39 *      conversion-members: (int) can be transformed from a String.
40 */
41template<typename FromType> class ExecutorEvaluater
42{
43public:
44  /** @brief Executes the Evaluater
45   * @param CallValue the Value that should be converted
46   * @param defaults the default Values.
47   */
48  template <typename ToType, int index>
49  ToType operator()(FromType& CallValue, const MultiType* const defaults)
50  {
51    return defaultValue;
52  }
53  static FromType& defaultValue() { static FromType defaultValue; return defaultValue; };
54};
55#endif /* __EXECUTOR_GENERIC_H_ */
56
57
58#ifdef __EXECUTOR_FUNCTIONAL_NAME
59///////////
60//// 0 ////
61///////////
62//! @brief ExecutorClass, that can execute Functions without any parameters.
63template<class T, typename CallType, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
64class __EXECUTOR_FUNCTIONAL_NAME(0) :public Executor<CallType, BaseClass>
65{
66private:
67  /** @brief the FunctioPointer. */
68  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST;
69
70public:
71  /**
72   * @brief constructs the Executor.
73   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
74   */
75  __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST )
76      : Executor<CallType, BaseClass>(false, __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
77  {
78    this->functionPointer = functionPointer;
79  };
80
81  /**
82   * @brief executes the Functional
83   * @param object the Object the action should be executed on.
84   * @param eval the CallType to get the Parameters from.
85   */
86  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
87  {
88    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
89  };
90
91  /**
92   * @brief copies the Executor
93   * @returns a new Executor that's a copy of this one.
94   */
95  virtual Executor<CallType, BaseClass>* clone() const
96  {
97    return new __EXECUTOR_FUNCTIONAL_NAME(0)<T, CallType>(this->functionPointer);
98  };
99};
100
101
102
103///////////
104//// 1 ////
105///////////
106//! @brief ExecutorClass, that can execute Functions with one parameter.
107template<class T, typename CallType, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
108class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<CallType, BaseClass>
109{
110private:
111  /** @brief the FunctioPointer. */
112  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;
113
114public:
115  /**
116   * @brief constructs the Executor.
117   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
118   */
119  __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
120      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
121  {
122    this->functionPointer = functionPointer;
123  };
124
125  /**
126   * @brief executes the Functional
127   * @param object the Object the action should be executed on.
128   * @param eval the CallType to get the Parameters from.
129   */
130  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
131  {
132    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
133      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue));
134  };
135
136  /**
137   * @brief copies the Executor
138   * @returns a new Executor that's a copy of this one.
139   */
140  virtual Executor<CallType, BaseClass>* clone() const
141  {
142    return  new __EXECUTOR_FUNCTIONAL_NAME(1)<T, CallType, type0>(this->functionPointer);
143  };
144};
145
146
147
148///////////
149//// 2 ////
150///////////
151//! @brief ExecutorClass, that can execute Functions with two parameters.
152template<class T, typename CallType, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
153class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<CallType, BaseClass>
154{
155private:
156  /** @brief the FunctioPointer. */
157  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;
158
159public:
160  /**
161   * @brief constructs the Executor.
162   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
163   */
164  __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
165      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
166  {
167    this->functionPointer = functionPointer;
168  };
169
170  /**
171   * @brief executes the Functional
172   * @param object the Object the action should be executed on.
173   * @param eval the CallType to get the Parameters from.
174   */
175  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
176  {
177    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
178      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
179      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue));
180  };
181
182  /**
183   * @brief copies the Executor
184   * @returns a new Executor that's a copy of this one.
185   */
186  virtual Executor<CallType, BaseClass>* clone() const
187  {
188    return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, CallType, type0, type1>(this->functionPointer);
189  };
190};
191
192
193
194///////////
195//// 3 ////
196///////////
197//! @brief ExecutorClass, that can execute Functions with three parameters.
198template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
199class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<CallType, BaseClass>
200{
201private:
202  /** @brief the FunctioPointer. */
203  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST;
204
205public:
206  /**
207   * @brief constructs the Executor.
208   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
209   */
210  __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST)
211      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
212  {
213    this->functionPointer = functionPointer;
214  };
215
216  /**
217   * @brief executes the Functional
218   * @param object the Object the action should be executed on.
219   * @param eval the CallType to get the Parameters from.
220   */
221  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
222  {
223    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
224      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
225      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
226      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue));
227  };
228
229  /**
230   * @brief copies the Executor
231   * @returns a new Executor that's a copy of this one.
232   */
233  virtual Executor<CallType, BaseClass>* clone() const
234  {
235    return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, CallType, type0, type1, type2>(this->functionPointer);
236  };
237};
238
239
240
241///////////
242//// 4 ////
243///////////
244//! @brief ExecutorClass, that can execute Functions with four parameters.
245template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
246class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<CallType, BaseClass>
247{
248private:
249  /** @brief the FunctioPointer. */
250  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST;
251
252public:
253  /**
254   * @brief constructs the Executor.
255   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
256   */
257  __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST)
258      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
259  {
260    this->functionPointer = functionPointer;
261  };
262
263  /**
264  * @brief executes the Functional
265  * @param object the Object the action should be executed on.
266  * @param eval the CallType to get the Parameters from.
267   */
268  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
269  {
270    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
271      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
272      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
273      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue),
274      Evaluater<CallType>().template operator()<type3, 3>(eval, this->defaultValue));
275  };
276
277  /**
278   * @brief copies the Executor
279   * @returns a new Executor that's a copy of this one.
280   */
281  virtual Executor<CallType, BaseClass>* clone() const
282  {
283    return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, CallType, type0, type1, type2, type3>(this->functionPointer);
284  };
285};
286
287
288
289///////////
290//// 5 ////
291///////////
292//! @brief ExecutorClass, that can execute Functions with five parameters.
293template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
294class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<CallType, BaseClass>
295{
296private:
297  /** @brief the FunctioPointer. */
298  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST;
299
300public:
301  /**
302   * @brief constructs the Executor.
303   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
304   */
305  __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST)
306      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
307  {
308    this->functionPointer = functionPointer;
309  };
310
311  /**
312  * @brief executes the Functional
313  * @param object the Object the action should be executed on.
314  * @param eval the CallType to get the Parameters from.
315   */
316  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
317  {
318    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
319      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
320      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
321      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue),
322      Evaluater<CallType>().template operator()<type3, 3>(eval, this->defaultValue),
323      Evaluater<CallType>().template operator()<type4, 4>(eval, this->defaultValue));
324  };
325
326  /**
327   * @brief copies the Executor
328   * @returns a new Executor that's a copy of this one.
329   */
330  virtual Executor<CallType, BaseClass>* clone() const
331  {
332    return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, CallType, type0, type1, type2, type3, type4>(this->functionPointer);
333  };
334};
335
336#endif /* __EXECUTOR_FUNCTIONAL_NAME */
Note: See TracBrowser for help on using the repository browser.