Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: functionality almost reached

File size: 7.9 KB
RevLine 
[4838]1/*!
[7716]2 * @file executor_functional.h
[7197]3 * Definition of an Executor
[5391]4 */
[1853]5
[7716]6/*
7   orxonox - the future of 3D-vertical-scrollers
[1853]8
[7716]9   Copyright (C) 2004 orx
[1853]10
[7716]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.
[5141]15
[7716]16### File Specific:
17   main-programmer: Benjamin Grauer
18   co-programmer: ...
19*/
[5652]20
[5328]21
[7716]22#ifndef __EXECUTOR_FUNCTIONAL_H_
23#define __EXECUTOR_FUNCTIONAL_H_
[5641]24
25
[5164]26
[7716]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; };
[5161]34
[7716]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); };
[5641]42
[7716]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(); };
[5161]50
[7716]51#endif /* __EXECUTOR_FUNCTIONAL_H_ */
[5161]52
[5328]53
[7716]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
[5161]58
[7716]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
[5161]66
[7716]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 */
[5135]71
[7716]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
[5636]78
[7716]79 #undef EXECUTOR_FUNCTIONAL_USE_STATIC
80#endif /* EXECUTOR_FUNCTIONAL_USE_STATIC */
[7714]81
[7716]82template<class T> class __EXECUTOR_FUNCTIONAL_NAME(0) : public Executor
83{
84private:
85  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST;
[5551]86
[7716]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;
[7717]93  };
94
[7716]95  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
96  {
97    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
98  };
[5142]99
[7717]100  virtual Executor* clone() const {
101    return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(this->functionPointer);
102  };
[7716]103};
[5135]104
105
[7716]106template<class T, typename type0> class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor
107{
108private:
109  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST;
[5141]110
[7716]111public:
112  __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST)
113      : Executor(ExecutorParamType<type0>())
114  {
115    this->functorType = Executor_Objective;
116    this->functionPointer = functionPointer;
[7717]117  };
118
[7716]119  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
120  {
[5153]121
[7716]122    /* // THE VERY COOL DEBUG
123      printf("SUB[0] : %s\n", sub[0].c_str());
124      printf("getDefault<type0>(this->defaultValue, 0):::: %d\n", getDefault<type0>(this->defaultValue, 0));
125      printf("VALUE: %d\n", fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)));
126    */
127    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
128      fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) );
129  };
[5153]130
[7717]131  virtual Executor* clone() const {
132    return  new __EXECUTOR_FUNCTIONAL_NAME(1)<T, type0>(this->functionPointer);
133  };
[7716]134};
[5145]135
[7716]136/// DOUBLE PENETRATION
137template<class T, typename type0, typename type1> class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor
138{
139private:
140  void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST;
[5145]141
[7714]142public:
[7716]143  __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST)
144      : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
[7714]145  {
[7716]146    this->functorType = Executor_Objective;
147    this->functionPointer = functionPointer;
[7717]148  };
149
[7714]150  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
151  {
[7716]152    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
153      fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),
154      fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)));
155  };
[7714]156
[7717]157  virtual Executor* clone() const {
158    return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, type0, type1>(this->functionPointer);
159  };
[5129]160};
[5113]161
[5632]162
[5326]163
[7716]164/// HACK !! THESE WILL BE RESET AGAIN !!
165
[7718]166
167#define EXECUTOR_FUNCTIONAL_CREATOR0() \
168template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST) \
169{ \
170  return new __EXECUTOR_FUNCTIONAL_NAME(0)<T>(functionPointer); \
[7716]171}
[7718]172
173#define EXECUTOR_FUNCTIONAL_CREATOR1(type0) \
174template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
175{ \
176  return new __EXECUTOR_FUNCTIONAL_NAME(1)<T, type0##_TYPE>(functionPointer); \
[7716]177}
[7718]178
179#define EXECUTOR_FUNCTIONAL_CREATOR2(type0, type1) \
180template<class T> Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \
181{ \
182  return new __EXECUTOR_FUNCTIONAL_NAME(2)<T, type0##_TYPE, type1##_TYPE>(functionPointer); \
[7716]183}
[5641]184
[7718]185#define EXECUTOR_FUNCTIONAL_CREATOR3(type0, type1, type2)
186#define EXECUTOR_FUNCTIONAL_CREATOR4(type0, type1, type2, type3)
187#define EXECUTOR_FUNCTIONAL_CREATOR5(type0, type1, type2, type3, type4)
[5326]188
[7718]189
190
191#define FUNCTOR_LIST(x) EXECUTOR_FUNCTIONAL_CREATOR ## x
192#include "functor_list.h"
193#undef FUNCTOR_LIST
194
195
196
[7716]197#undef __EXECUTOR_FUNCTIONAL_CONST
198#undef __EXECUTOR_FUNCTIONAL_NAME
199#undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC
200#undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER
Note: See TracBrowser for help on using the repository browser.