/*! * @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) { return isString(input, defaultValue); }; 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<> std::string getDefault(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getString(); }; #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)(); }; Executor* clone() const { }; }; 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 {}; }; /// DOUBLE PENETRATION 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 {}; }; /// HACK !! THESE WILL BE RESET AGAIN !! template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)() __EXECUTOR_FUNCTIONAL_CONST) { return new __EXECUTOR_FUNCTIONAL_NAME(0)(functionPointer); } template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(bool) __EXECUTOR_FUNCTIONAL_CONST) { return new __EXECUTOR_FUNCTIONAL_NAME(1)(functionPointer); } template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(int) __EXECUTOR_FUNCTIONAL_CONST) { return new __EXECUTOR_FUNCTIONAL_NAME(1)(functionPointer); } template Executor* createExecutor(void (__EXECUTOR_FUNCTIONAL_FUNCTION_POINTER)(bool, int) __EXECUTOR_FUNCTIONAL_CONST) { return new __EXECUTOR_FUNCTIONAL_NAME(2)(functionPointer); } #undef __EXECUTOR_FUNCTIONAL_CONST #undef __EXECUTOR_FUNCTIONAL_NAME #undef __EXECUTOR_FUNCTIONAL_FUNCTION_EXEC #undef __EXECUTOR_FUNCTIONAL_FUNCTION_POINTER