Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added a Substring handler

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#ifdef __EXECUTOR_FUNCTIONAL_NAME
58
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
105///////////
106//// 1 ////
107///////////
108//! @brief ExecutorClass, that can execute Functions with one parameter.
109template<class T, typename CallType, typename type0, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
110class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor<CallType, BaseClass>
111{
112private:
113  /** @brief the FunctioPointer. */
114  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;
115
116public:
117  /**
118   * @brief constructs the Executor.
119   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
120   */
121  __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
122      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
123  {
124    this->functionPointer = functionPointer;
125  };
126
127  /**
128   * @brief executes the Functional
129   * @param object the Object the action should be executed on.
130   * @param eval the CallType to get the Parameters from.
131   */
132  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
133  {
134    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
135      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue));
136  };
137
138  /**
139   * @brief copies the Executor
140   * @returns a new Executor that's a copy of this one.
141   */
142  virtual Executor<CallType, BaseClass>* clone() const
143  {
144    return  new __EXECUTOR_FUNCTIONAL_NAME(1)<T, CallType, type0>(this->functionPointer);
145  };
146};
147
148
149
150
151
152///////////
153//// 2 ////
154///////////
155//! @brief ExecutorClass, that can execute Functions with two parameters.
156template<class T, typename CallType, typename type0, typename type1, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
157class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor<CallType, BaseClass>
158{
159private:
160  /** @brief the FunctioPointer. */
161  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;
162
163public:
164  /**
165   * @brief constructs the Executor.
166   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
167   */
168  __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
169      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
170  {
171    this->functionPointer = functionPointer;
172  };
173
174  /**
175   * @brief executes the Functional
176   * @param object the Object the action should be executed on.
177   * @param eval the CallType to get the Parameters from.
178   */
179  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
180  {
181    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
182      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
183      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue));
184  };
185
186  /**
187   * @brief copies the Executor
188   * @returns a new Executor that's a copy of this one.
189   */
190  virtual Executor<CallType, BaseClass>* clone() const
191  {
192    return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, CallType, type0, type1>(this->functionPointer);
193  };
194};
195
196
197
198
199
200///////////
201//// 3 ////
202///////////
203//! @brief ExecutorClass, that can execute Functions with three parameters.
204template<class T, typename CallType, typename type0, typename type1, typename type2, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
205class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor<CallType, BaseClass>
206{
207private:
208  /** @brief the FunctioPointer. */
209  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST;
210
211public:
212  /**
213   * @brief constructs the Executor.
214   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
215   */
216  __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST)
217      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
218  {
219    this->functionPointer = functionPointer;
220  };
221
222  /**
223   * @brief executes the Functional
224   * @param object the Object the action should be executed on.
225   * @param eval the CallType to get the Parameters from.
226   */
227  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
228  {
229    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
230      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
231      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
232      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue));
233  };
234
235  /**
236   * @brief copies the Executor
237   * @returns a new Executor that's a copy of this one.
238   */
239  virtual Executor<CallType, BaseClass>* clone() const
240  {
241    return new __EXECUTOR_FUNCTIONAL_NAME(3)<T, CallType, type0, type1, type2>(this->functionPointer);
242  };
243};
244
245
246
247
248
249///////////
250//// 4 ////
251///////////
252//! @brief ExecutorClass, that can execute Functions with four parameters.
253template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
254class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor<CallType, BaseClass>
255{
256private:
257  /** @brief the FunctioPointer. */
258  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST;
259
260public:
261  /**
262   * @brief constructs the Executor.
263   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
264   */
265  __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST)
266      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
267  {
268    this->functionPointer = functionPointer;
269  };
270
271  /**
272  * @brief executes the Functional
273  * @param object the Object the action should be executed on.
274  * @param eval the CallType to get the Parameters from.
275   */
276  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
277  {
278    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
279      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
280      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
281      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue),
282      Evaluater<CallType>().template operator()<type3, 3>(eval, this->defaultValue));
283  };
284
285  /**
286   * @brief copies the Executor
287   * @returns a new Executor that's a copy of this one.
288   */
289  virtual Executor<CallType, BaseClass>* clone() const
290  {
291    return new __EXECUTOR_FUNCTIONAL_NAME(4)<T, CallType, type0, type1, type2, type3>(this->functionPointer);
292  };
293};
294
295
296
297
298
299
300///////////
301//// 5 ////
302///////////
303//! @brief ExecutorClass, that can execute Functions with five parameters.
304template<class T, typename CallType, typename type0, typename type1, typename type2, typename type3, typename type4, template<typename> class Evaluater = ExecutorEvaluater, class BaseClass = BaseObject>
305class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor<CallType, BaseClass>
306{
307private:
308  /** @brief the FunctioPointer. */
309  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST;
310
311public:
312  /**
313   * @brief constructs the Executor.
314   * @param __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER the FunctionPointer to the Calling Function.
315   */
316  __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST)
317      : Executor<CallType, BaseClass>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>(), __EXECUTOR_FUNCTIONAL_FUNCTIONTYPE)
318  {
319    this->functionPointer = functionPointer;
320  };
321
322  /**
323  * @brief executes the Functional
324  * @param object the Object the action should be executed on.
325  * @param eval the CallType to get the Parameters from.
326   */
327  virtual void operator()(BaseObject* object, CallType& eval = Evaluater<CallType>::defaultValue()) const
328  {
329    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
330      Evaluater<CallType>().template operator()<type0, 0>(eval, this->defaultValue),
331      Evaluater<CallType>().template operator()<type1, 1>(eval, this->defaultValue),
332      Evaluater<CallType>().template operator()<type2, 2>(eval, this->defaultValue),
333      Evaluater<CallType>().template operator()<type3, 3>(eval, this->defaultValue),
334      Evaluater<CallType>().template operator()<type4, 4>(eval, this->defaultValue));
335  };
336
337  /**
338   * @brief copies the Executor
339   * @returns a new Executor that's a copy of this one.
340   */
341  virtual Executor<CallType, BaseClass>* clone() const
342  {
343    return new __EXECUTOR_FUNCTIONAL_NAME(5)<T, CallType, type0, type1, type2, type3, type4>(this->functionPointer);
344  };
345};
346
347#endif /* __EXECUTOR_FUNCTIONAL_NAME */
Note: See TracBrowser for help on using the repository browser.