Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: does not run anymore with scripts, but i think, it is on track

lua_State is now handled over the Global Executor

File size: 16.8 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), functionPointer(functionPointer)
77  {};
78
79  /**
80   * @brief executes the Functional
81   * @param object the Object the action should be executed on.
82   * @param eval the CallType to get the Parameters from.
83   */
84  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
85  {
86    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
87  };
88
89  /**
90   * @brief copies the Executor
91   * @returns a new Executor that's a copy of this one.
92   */
93  virtual Executor<CallType, BaseClass>* clone() const
94  {
95    return new __EXECUTOR_FUNCTIONAL_NAME(0,)<T, CallType>(this->functionPointer);
96  };
97};
98
99
100
101///////////
102//// 1 ////
103///////////
104//! @brief ExecutorClass, that can execute Functions with one parameter.
105template<class T, typename CallType, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
106class __EXECUTOR_FUNCTIONAL_NAME(1,) : public Executor<CallType, BaseClass>
107{
108private:
109  /** @brief the FunctioPointer. */
110  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;
111
112public:
113  /**
114   * @brief constructs the Executor.
115   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
116   */
117  __EXECUTOR_FUNCTIONAL_NAME(1,) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
118      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
119  {};
120
121  /**
122   * @brief executes the Functional
123   * @param object the Object the action should be executed on.
124   * @param eval the CallType to get the Parameters from.
125   */
126  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
127  {
128    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
129      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue));
130  };
131
132  /**
133   * @brief copies the Executor
134   * @returns a new Executor that's a copy of this one.
135   */
136  virtual Executor<CallType, BaseClass>* clone() const
137  {
138    return  new __EXECUTOR_FUNCTIONAL_NAME(1,)<T, CallType, type0>(this->functionPointer);
139  };
140};
141
142
143
144///////////
145//// 2 ////
146///////////
147//! @brief ExecutorClass, that can execute Functions with two parameters.
148template<class T, typename CallType, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
149class __EXECUTOR_FUNCTIONAL_NAME(2,) : public Executor<CallType, BaseClass>
150{
151private:
152  /** @brief the FunctioPointer. */
153  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;
154
155public:
156  /**
157   * @brief constructs the Executor.
158   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
159   */
160  __EXECUTOR_FUNCTIONAL_NAME(2,) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
161      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
162  {};
163
164  /**
165   * @brief executes the Functional
166   * @param object the Object the action should be executed on.
167   * @param eval the CallType to get the Parameters from.
168   */
169  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
170  {
171    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
172      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
173      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue));
174  };
175
176  /**
177   * @brief copies the Executor
178   * @returns a new Executor that's a copy of this one.
179   */
180  virtual Executor<CallType, BaseClass>* clone() const
181  {
182    return new __EXECUTOR_FUNCTIONAL_NAME(2,)<T, CallType, type0, type1>(this->functionPointer);
183  };
184};
185
186
187
188///////////
189//// 3 ////
190///////////
191//! @brief ExecutorClass, that can execute Functions with three parameters.
192template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
193class __EXECUTOR_FUNCTIONAL_NAME(3,) : public Executor<CallType, BaseClass>
194{
195private:
196  /** @brief the FunctioPointer. */
197  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST;
198
199public:
200  /**
201   * @brief constructs the Executor.
202   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
203   */
204  __EXECUTOR_FUNCTIONAL_NAME(3,) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST)
205      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
206  {};
207
208  /**
209   * @brief executes the Functional
210   * @param object the Object the action should be executed on.
211   * @param eval the CallType to get the Parameters from.
212   */
213  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
214  {
215    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
216      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
217      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
218      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue));
219  };
220
221  /**
222   * @brief copies the Executor
223   * @returns a new Executor that's a copy of this one.
224   */
225  virtual Executor<CallType, BaseClass>* clone() const
226  {
227    return new __EXECUTOR_FUNCTIONAL_NAME(3,)<T, CallType, type0, type1, type2>(this->functionPointer);
228  };
229};
230
231
232
233///////////
234//// 4 ////
235///////////
236//! @brief ExecutorClass, that can execute Functions with four parameters.
237template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
238class __EXECUTOR_FUNCTIONAL_NAME(4,) : public Executor<CallType, BaseClass>
239{
240private:
241  /** @brief the FunctioPointer. */
242  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST;
243
244public:
245  /**
246   * @brief constructs the Executor.
247   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
248   */
249  __EXECUTOR_FUNCTIONAL_NAME(4,) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST)
250      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
251  {};
252
253  /**
254  * @brief executes the Functional
255  * @param object the Object the action should be executed on.
256  * @param eval the CallType to get the Parameters from.
257   */
258  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
259  {
260    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
261      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
262      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
263      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue),
264      Evaluater<CallType>().template operator()<type3, 3>(eval, this->defaultValue));
265  };
266
267  /**
268   * @brief copies the Executor
269   * @returns a new Executor that's a copy of this one.
270   */
271  virtual Executor<CallType, BaseClass>* clone() const
272  {
273    return new __EXECUTOR_FUNCTIONAL_NAME(4,)<T, CallType, type0, type1, type2, type3>(this->functionPointer);
274  };
275};
276
277
278
279///////////
280//// 5 ////
281///////////
282//! @brief ExecutorClass, that can execute Functions with five parameters.
283template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
284class __EXECUTOR_FUNCTIONAL_NAME(5,) : public Executor<CallType, BaseClass>
285{
286private:
287  /** @brief the FunctioPointer. */
288  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST;
289
290public:
291  /**
292   * @brief constructs the Executor.
293   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
294   */
295  __EXECUTOR_FUNCTIONAL_NAME(5,) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST)
296      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
297  {};
298
299  /**
300  * @brief executes the Functional
301  * @param object the Object the action should be executed on.
302  * @param eval the CallType to get the Parameters from.
303   */
304  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
305  {
306    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
307      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
308      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
309      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue),
310      Evaluater<CallType>().template operator()<type3, 3>(eval, this->defaultValue),
311      Evaluater<CallType>().template operator()<type4, 4>(eval, this->defaultValue));
312  };
313
314  /**
315   * @brief copies the Executor
316   * @returns a new Executor that's a copy of this one.
317   */
318  virtual Executor<CallType, BaseClass>* clone() const
319  {
320    return new __EXECUTOR_FUNCTIONAL_NAME(5,)<T, CallType, type0, type1, type2, type3, type4>(this->functionPointer);
321  };
322};
323
324
325////////////////////
326//// 0 & RETURN ////
327////////////////////
328//! @brief ExecutorClass, that can execute Functions with one parameter.
329template<class T, typename CallType, typename ret, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
330class __EXECUTOR_FUNCTIONAL_NAME(0,ret) : public Executor<CallType, BaseClass>
331{
332private:
333  /** @brief the FunctioPointer. */
334  ret (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST;
335
336public:
337  /**
338   * @brief constructs the Executor.
339   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
340   */
341  __EXECUTOR_FUNCTIONAL_NAME(0,ret) (ret (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST)
342      : Executor<CallType, BaseClass>(true, __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
343  {};
344
345  /**
346     * @brief executes the Functional
347     * @param object the Object the action should be executed on.
348     * @param eval the CallType to get the Parameters from.
349   */
350  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
351  {
352    Evaluater<CallType>().template storeRet<ret>(eval, (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)());
353  };
354
355  /**
356     * @brief copies the Executor
357     * @returns a new Executor that's a copy of this one.
358   */
359  virtual Executor<CallType, BaseClass>* clone() const
360  {
361    return  new __EXECUTOR_FUNCTIONAL_NAME(0,ret)<T, CallType, ret>(this->functionPointer);
362  };
363};
364
365////////////////////
366//// 1 & RETURN ////
367////////////////////
368//! @brief ExecutorClass, that can execute Functions with one parameter.
369template<class T, typename CallType, typename ret, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
370class __EXECUTOR_FUNCTIONAL_NAME(1,ret) : public Executor<CallType, BaseClass>
371{
372private:
373  /** @brief the FunctioPointer. */
374  ret (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;
375
376public:
377  /**
378   * @brief constructs the Executor.
379   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
380   */
381  __EXECUTOR_FUNCTIONAL_NAME(1,ret) (ret (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
382      : Executor<CallType, BaseClass>(true, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
383  {};
384
385  /**
386     * @brief executes the Functional
387     * @param object the Object the action should be executed on.
388     * @param eval the CallType to get the Parameters from.
389   */
390  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
391  {
392    Evaluater<CallType>().template storeRet<ret>(eval, (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
393          Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue)));
394  };
395
396  /**
397     * @brief copies the Executor
398     * @returns a new Executor that's a copy of this one.
399   */
400  virtual Executor<CallType, BaseClass>* clone() const
401  {
402    return  new __EXECUTOR_FUNCTIONAL_NAME(1,ret)<T, CallType, ret, type0>(this->functionPointer);
403  };
404};
405
406
407////////////////////
408//// 1 & RETURN ////
409////////////////////
410//! @brief ExecutorClass, that can execute Functions with one parameter.
411template<class T, typename CallType, typename ret, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
412class __EXECUTOR_FUNCTIONAL_NAME(2,ret) : public Executor<CallType, BaseClass>
413{
414private:
415  /** @brief the FunctioPointer. */
416  ret (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;
417
418public:
419  /**
420   * @brief constructs the Executor.
421   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
422   */
423  __EXECUTOR_FUNCTIONAL_NAME(2,ret) (ret (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
424      : Executor<CallType, BaseClass>(true, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE), functionPointer(functionPointer)
425  {};
426
427  /**
428     * @brief executes the Functional
429     * @param object the Object the action should be executed on.
430     * @param eval the CallType to get the Parameters from.
431   */
432  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
433  {
434    Evaluater<CallType>().template storeRet<ret>(eval, (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
435          Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
436          Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue)));
437  };
438
439  /**
440     * @brief copies the Executor
441     * @returns a new Executor that's a copy of this one.
442   */
443  virtual Executor<CallType, BaseClass>* clone() const
444  {
445    return  new __EXECUTOR_FUNCTIONAL_NAME(2,ret)<T, CallType, ret, type0, type1>(this->functionPointer);
446  };
447};
448
449#endif /* __EXECUTOR_FUNCTIONAL_NAME */
Note: See TracBrowser for help on using the repository browser.