/*! * @file executor_functional.h * Definition of an Executor */ /* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ #ifndef __EXECUTOR_FUNCTIONAL_H_ #define __EXECUTOR_FUNCTIONAL_H_ template MT_Type ExecutorParamType() { return MT_EXT1; }; template<> MT_Type ExecutorParamType() { return MT_EXT1; }; template<> MT_Type ExecutorParamType() { return MT_INT; }; template<> MT_Type ExecutorParamType() { return MT_UINT; }; template<> MT_Type ExecutorParamType() { return MT_FLOAT; }; template<> MT_Type ExecutorParamType() { return MT_CHAR; }; template<> MT_Type ExecutorParamType() { return MT_STRING; }; template type fromString(const std::string& input, type defaultValue) {return defaultValue; }; template<> bool fromString(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); }; template<> int fromString(const std::string& input, int defaultValue) { return isInt(input, defaultValue); }; template<> unsigned int fromString(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); }; template<> float fromString(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); }; template<> char fromString(const std::string& input, char defaultValue) { return isInt(input, defaultValue); }; template<> const std::string& fromString(const std::string& input, const std::string& defaultValue) { static std::string retVal = isString(input, defaultValue); return retVal; }; template type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; template<> bool getDefault(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); }; template<> int getDefault(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; template<> unsigned int getDefault(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; template<> float getDefault(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); }; template<> char getDefault(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); }; template<> const std::string& getDefault(const MultiType* const defaultValues, unsigned int i) { static std::string retVal = defaultValues[i].getString(); return retVal; }; #endif /* __EXECUTOR_FUNCTIONAL_H_ */ #define __EXECUTOR_FUNCTIONAL_CONST #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC dynamic_cast(object)->*(functionPointer) #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER T::*functionPointer #ifdef EXECUTOR_FUNCTIONAL_USE_CONST #undef __EXECUTOR_FUNCTIONAL_CONST #define __EXECUTOR_FUNCTIONAL_CONST const #undef __EXECUTOR_FUNCTIONAL_NAME #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_const #undef EXECUTOR_FUNCTIONAL_USE_CONST #endif #ifdef EXECUTOR_FUNCTIONAL_USE_STATIC #ifdef EXECUTOR_FUNCTIONAL_USE_CONST #error you obviously do not know what you are doing !! ask the bensch #endif /* EXECUTOR_FUNCTIONAL_USE_CONST */ #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC #define __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC functionPointer #undef __EXECUTOR_FUNCTIONAL_NAME #define __EXECUTOR_FUNCTIONAL_NAME(ParamCount) Executor##ParamCount##Params_static #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER #define __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER *functionPointer #undef EXECUTOR_FUNCTIONAL_USE_STATIC #endif /* EXECUTOR_FUNCTIONAL_USE_STATIC */ template class __EXECUTOR_FUNCTIONAL_NAME(0) : public Executor { private: void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST; public: __EXECUTOR_FUNCTIONAL_NAME(0) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST ) : Executor() { this->functorType = Executor_Objective; this->functionPointer = functionPointer; }; virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const { (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(); }; virtual Executor* clone() const { return new __EXECUTOR_FUNCTIONAL_NAME(0)(this->functionPointer); }; }; //! SINGLE VALUE template class __EXECUTOR_FUNCTIONAL_NAME(1) : public Executor { private: void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST; public: __EXECUTOR_FUNCTIONAL_NAME(1) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0) __EXECUTOR_FUNCTIONAL_CONST) : Executor(ExecutorParamType()) { this->functorType = Executor_Objective; this->functionPointer = functionPointer; }; virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const { /* // THE VERY COOL DEBUG printf("SUB[0] : %s\n", sub[0].c_str()); printf("getDefault(this->defaultValue, 0):::: %d\n", getDefault(this->defaultValue, 0)); printf("VALUE: %d\n", fromString(sub[0], getDefault(this->defaultValue, 0))); */ (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( fromString(sub[0], getDefault(this->defaultValue, 0)) ); }; virtual Executor* clone() const { return new __EXECUTOR_FUNCTIONAL_NAME(1)(this->functionPointer); }; }; //! DOUBLE VALUE template class __EXECUTOR_FUNCTIONAL_NAME(2) : public Executor { private: void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST; public: __EXECUTOR_FUNCTIONAL_NAME(2) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1) __EXECUTOR_FUNCTIONAL_CONST) : Executor(ExecutorParamType(), ExecutorParamType()) { this->functorType = Executor_Objective; this->functionPointer = functionPointer; }; virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const { (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( fromString(sub[0], getDefault(this->defaultValue, 0)), fromString(sub[1], getDefault(this->defaultValue, 1))); }; virtual Executor* clone() const { return new __EXECUTOR_FUNCTIONAL_NAME(2)(this->functionPointer); }; }; //! TRIPPLE VALUE template class __EXECUTOR_FUNCTIONAL_NAME(3) : public Executor { private: void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST; public: __EXECUTOR_FUNCTIONAL_NAME(3) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2) __EXECUTOR_FUNCTIONAL_CONST) : Executor(ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functorType = Executor_Objective; this->functionPointer = functionPointer; }; virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const { (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( fromString(sub[0], getDefault(this->defaultValue, 0)), fromString(sub[1], getDefault(this->defaultValue, 1)), fromString(sub[2], getDefault(this->defaultValue, 2))); }; virtual Executor* clone() const { return new __EXECUTOR_FUNCTIONAL_NAME(3)(this->functionPointer); }; }; //! QUADRUPPEL VALUE template class __EXECUTOR_FUNCTIONAL_NAME(4) : public Executor { private: void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST; public: __EXECUTOR_FUNCTIONAL_NAME(4) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3) __EXECUTOR_FUNCTIONAL_CONST) : Executor(ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functorType = Executor_Objective; this->functionPointer = functionPointer; }; virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const { (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( fromString(sub[0], getDefault(this->defaultValue, 0)), fromString(sub[1], getDefault(this->defaultValue, 1)), fromString(sub[2], getDefault(this->defaultValue, 2)), fromString(sub[3], getDefault(this->defaultValue, 3))); }; virtual Executor* clone() const { return new __EXECUTOR_FUNCTIONAL_NAME(4)(this->functionPointer); }; }; //! CHINQUE VALUE template class __EXECUTOR_FUNCTIONAL_NAME(5) : public Executor { private: void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST; public: __EXECUTOR_FUNCTIONAL_NAME(5) (void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0, type1, type2, type3, type4) __EXECUTOR_FUNCTIONAL_CONST) : Executor(ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functorType = Executor_Objective; this->functionPointer = functionPointer; }; virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const { (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( fromString(sub[0], getDefault(this->defaultValue, 0)), fromString(sub[1], getDefault(this->defaultValue, 1)), fromString(sub[2], getDefault(this->defaultValue, 2)), fromString(sub[3], getDefault(this->defaultValue, 3)), fromString(sub[4], getDefault(this->defaultValue, 4))); }; virtual Executor* clone() const { return new __EXECUTOR_FUNCTIONAL_NAME(5)(this->functionPointer); }; }; #define EXECUTOR_FUNCTIONAL_CREATOR0() \ template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST) \ { \ return new __EXECUTOR_FUNCTIONAL_NAME(0)(functionPointer); \ } #define EXECUTOR_FUNCTIONAL_CREATOR1(type0) \ template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ { \ return new __EXECUTOR_FUNCTIONAL_NAME(1)(functionPointer); \ } #define EXECUTOR_FUNCTIONAL_CREATOR2(type0, type1) \ template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ { \ return new __EXECUTOR_FUNCTIONAL_NAME(2)(functionPointer); \ } #define EXECUTOR_FUNCTIONAL_CREATOR3(type0, type1, type2) \ template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ { \ return new __EXECUTOR_FUNCTIONAL_NAME(3)(functionPointer); \ } #define EXECUTOR_FUNCTIONAL_CREATOR4(type0, type1, type2, type3) \ template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ { \ return new __EXECUTOR_FUNCTIONAL_NAME(4)(functionPointer); \ } #define EXECUTOR_FUNCTIONAL_CREATOR5(type0, type1, type2, type3, type4) \ template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(type0##_TYPE, type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE) __EXECUTOR_FUNCTIONAL_CONST) \ { \ return new __EXECUTOR_FUNCTIONAL_NAME(5)(functionPointer); \ } #define FUNCTOR_LIST(x) EXECUTOR_FUNCTIONAL_CREATOR ## x #include "functor_list.h" #undef FUNCTOR_LIST #undef __EXECUTOR_FUNCTIONAL_CONST #undef __EXECUTOR_FUNCTIONAL_NAME #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER