Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/executor/executor_generic.h @ 10009

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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