Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/executor/executor_functional.h @ 7716

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

trunk: static and const calls all work

File size: 7.3 KB
Line 
1/*!
2 * @file executor_functional.h
3 * Definition of an 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#ifndef __EXECUTOR_FUNCTIONAL_H_
23#define __EXECUTOR_FUNCTIONAL_H_
24
25
26
27template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; };
28template<> MT_Type ExecutorParamType<bool>() { return MT_EXT1; };
29template<> MT_Type ExecutorParamType<int>() { return MT_INT; };
30template<> MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; };
31template<> MT_Type ExecutorParamType<float>() { return MT_FLOAT; };
32template<> MT_Type ExecutorParamType<char>() { return MT_CHAR; };
33template<> MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; };
34
35template<typename type> type fromString(const std::string& input, type defaultValue) {return defaultValue; };
36template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); };
37template<> int fromString<int>(const std::string& input, int defaultValue) { return isInt(input, defaultValue); };
38template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); };
39template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); };
40template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); };
41template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return isString(input, defaultValue); };
42
43template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };
44template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); };
45template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); };
46template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); };
47template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); };
48template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); };
49template<> std::string getDefault<std::string>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getString(); };
50
51#endif /* __EXECUTOR_FUNCTIONAL_H_ */
52
53
54#define __EXECUTOR_FUNCTIONAL_CONST
55#define __EXECUTOR_FUNCTIONAL_NAME(ParamCount)   Executor##ParamCount##Params
56#define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC      dynamic_cast<T*>(object)->*(functionPointer)
57#define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER   T::*functionPointer
58
59#ifdef EXECUTOR_FUNCTIONAL_USE_CONST
60 #undef __EXECUTOR_FUNCTIONAL_CONST
61 #define __EXECUTOR_FUNCTIONAL_CONST const
62 #undef __EXECUTOR_FUNCTIONAL_NAME
63 #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_const
64 #undef EXECUTOR_FUNCTIONAL_USE_CONST
65#endif
66
67#ifdef EXECUTOR_FUNCTIONAL_USE_STATIC
68 #ifdef EXECUTOR_FUNCTIONAL_USE_CONST
69  #error you obviously do not know what you are doing !! ask the bensch
70 #endif /* EXECUTOR_FUNCTIONAL_USE_CONST */
71
72 #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC
73 #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC       functionPointer
74 #undef __EXECUTOR_FUNCTIONAL_NAME
75 #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount)    Executor##ParamCount##Params_static
76 #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER
77 #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER    *functionPointer
78
79 #undef EXECUTOR_FUNCTIONAL_USE_STATIC
80#endif /* EXECUTOR_FUNCTIONAL_USE_STATIC */
81
82template<class T> class __EXECUTOR_FUNCTIONAL_NAME(0) : public Executor
83{
84private:
85  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST;
86
87public:
88  __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST )
89      : Executor()
90  {
91    this->functorType = Executor_Objective;
92    this->functionPointer = functionPointer;
93  }
94  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
95  {
96    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
97  };
98
99  Executor* clone() const { };
100};
101
102
103template<class T, typename type0> class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor
104{
105private:
106  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;
107
108public:
109  __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
110      : Executor(ExecutorParamType<type0>())
111  {
112    this->functorType = Executor_Objective;
113    this->functionPointer = functionPointer;
114  }
115  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
116  {
117
118    /* // THE VERY COOL DEBUG
119      printf("SUB[0] : %s\n", sub[0].c_str());
120      printf("getDefault<type0>(this->defaultValue, 0):::: %d\n", getDefault<type0>(this->defaultValue, 0));
121      printf("VALUE: %d\n", fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)));
122    */
123    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
124      fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) );
125  };
126
127  virtual Executor* clone() const {};
128};
129
130/// DOUBLE PENETRATION
131template<class T, typename type0, typename type1> class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor
132{
133private:
134  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;
135
136public:
137  __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
138      : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
139  {
140    this->functorType = Executor_Objective;
141    this->functionPointer = functionPointer;
142  }
143  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
144  {
145    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
146      fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),
147      fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)));
148  };
149
150  virtual Executor* clone() const {};
151};
152
153
154
155/// HACK !! THESE WILL BE RESET AGAIN !!
156
157template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST)
158{
159  return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(functionPointer);
160}
161template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(bool) __EXECUTOR_FUNCTIONAL_CONST)
162{
163  return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, bool>(functionPointer);
164}
165template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(int) __EXECUTOR_FUNCTIONAL_CONST)
166{
167  return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, int>(functionPointer);
168}
169template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(bool, int) __EXECUTOR_FUNCTIONAL_CONST)
170{
171  return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, bool, int>(functionPointer);
172}
173
174
175#undef __EXECUTOR_FUNCTIONAL_CONST
176#undef __EXECUTOR_FUNCTIONAL_NAME
177#undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC
178#undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER
Note: See TracBrowser for help on using the repository browser.