Changeset 9748 in orxonox.OLD for branches/new_class_id/src
- Timestamp:
- Sep 16, 2006, 10:09:59 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util
- Files:
-
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/Makefile.am
r9746 r9748 10 10 executor/executor_lua_state.cc \ 11 11 executor/executor_substring.cc 12 13 # executor/executor_functional.cc14 12 15 13 libORXlibutil_a_SOURCES = \ -
branches/new_class_id/src/lib/util/executor/executor.cc
r9733 r9748 18 18 #include "executor.h" 19 19 20 /** @returns the Type of an Argument taken by the Executor in this case MT_BOOL */ 20 21 template<> MT_Type ExecutorParamType<bool>() { return MT_BOOL; }; 22 /** @returns the Type of an Argument taken by the Executor in this case MT_INT*/ 21 23 template<> MT_Type ExecutorParamType<int>() { return MT_INT; }; 24 /** @returns the Type of an Argument taken by the Executor in this case MT_UINT*/ 22 25 template<> MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; }; 26 /** @returns the Type of an Argument taken by the Executor in this case MT_FLOAT*/ 23 27 template<> MT_Type ExecutorParamType<float>() { return MT_FLOAT; }; 28 /** @returns the Type of an Argument taken by the Executor in this case MT_CHAR*/ 24 29 template<> MT_Type ExecutorParamType<char>() { return MT_CHAR; }; 30 /** @returns the Type of an Argument taken by the Executor in this case MT_STRING*/ 25 31 template<> MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; }; -
branches/new_class_id/src/lib/util/executor/executor.h
r9737 r9748 16 16 17 17 18 18 /** @returns the Type of an Argument taken by the Executor */ 19 19 template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; }; 20 20 template<> MT_Type ExecutorParamType<bool>(); … … 66 66 inline bool hasRetVal() const { return bRetVal; }; 67 67 68 /** executes a Command. @param objec the Object, @param count how many values, @param values the Values*/68 /** executes a Command. @param object the Object, @param values The Value of type CallType to pass to the Executor. */ 69 69 virtual void operator()(BaseClass* object, CallType& values) const = 0; 70 70 … … 76 76 * @param value3 the fourth default value 77 77 * @param value4 the fifth default value 78 * @param value5 the sixth default value 79 * @param value6 the seventh default value 78 80 * @returns itself 79 81 * @note: THIS FUNCTION WILL BE REPLACED BY A CONFIGURATOR (most probably). … … 109 111 protected: 110 112 //! Now follows a List of Executor Constructors, to be fast in creating. 113 //! Creates an Executor with no Argument. 111 114 Executor(bool hasRetVal, FunctionType functionType = FunctionMember) 112 115 : bRetVal(hasRetVal), paramCount(0), functionType(functionType) 113 116 { }; 114 117 118 //! Creates an Executor with 1 Argument. 115 119 Executor(bool hasRetVal, const MultiType& param0, 116 120 FunctionType functionType = FunctionMember) … … 120 124 }; 121 125 126 //! Creates an Executor with 2 Arguments. 122 127 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 123 128 FunctionType functionType = FunctionMember) … … 128 133 }; 129 134 135 //! Creates an Executor with 3 Arguments. 130 136 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 131 137 const MultiType& param2, … … 138 144 }; 139 145 146 //! Creates an Executor with 4 Arguments. 140 147 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 141 148 const MultiType& param2, const MultiType& param3, … … 149 156 }; 150 157 158 //! Creates an Executor with 5 Arguments. 151 159 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 152 160 const MultiType& param2, const MultiType& param3, … … 162 170 }; 163 171 172 //! Creates an Executor with 6 Arguments. 164 173 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 165 174 const MultiType& param2, const MultiType& param3, … … 176 185 }; 177 186 187 //! Creates an Executor with 7 Arguments. 178 188 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 179 189 const MultiType& param2, const MultiType& param3, -
branches/new_class_id/src/lib/util/executor/executor_const_member.h
r9745 r9748 1 1 /*! 2 * @file executor_ member.h2 * @file executor_const_member.h 3 3 * Definition of an Executor to Member Functions 4 4 */ -
branches/new_class_id/src/lib/util/executor/executor_generic.h
r9747 r9748 49 49 static ToType getValue(FromType& CallValue, const MultiType* const defaults) 50 50 { 51 assert(0 && "Might be by mistake");51 assert(0 && "Might want to extend the ExecutorEvaluater::getValue function in an 'Explicit Specialized Template Class'"); 52 52 return defaultValue; 53 53 } 54 /** @param @storeTo Stores the returned value here. @param value The Value to Store. @note invers of getValue */ 55 static void storeRet(FromType& storeTo, FromType value) 56 { 57 assert (0 && "Might want to extend the ExecutorEvaluater::storeRet function in an 'Explicit Specialized Template Class'"); 58 } 59 /** @returns the Default Value of ToType */ 54 60 static FromType& defaultValue() { static FromType defaultValue; return defaultValue; }; 55 61 }; -
branches/new_class_id/src/lib/util/executor/executor_lua_state.cc
r9743 r9748 22 22 std::string temp[7]; 23 23 24 /** 25 * @brief Converts a lua_State into any type. 26 * @param state the State to get the value from. 27 * @param index the position inside of the lua_State to get the value from. 28 * @returns The value if found. 29 */ 24 30 template<typename type> type fromLua(lua_State* state, int index) { type *obj = Lunar<type>::check(state, 1); lua_remove(state, 1); return obj;}; 31 /** 32 * @brief Converts a lua_State into any type. 33 * @param state the State to get the value from. 34 * @param index the position inside of the lua_State to get the value from. 35 * @returns The value if found. 36 */ 25 37 template<> bool fromLua<bool>(lua_State* state, int index) { return lua_toboolean(state, index); }; 38 /** 39 * @brief Converts a lua_State into any type. 40 * @param state the State to get the value from. 41 * @param index the position inside of the lua_State to get the value from. 42 * @returns The value if found. 43 */ 26 44 template<> int fromLua<int>(lua_State* state, int index) { return (int)lua_tonumber(state, index); }; 45 /** 46 * @brief Converts a lua_State into any type. 47 * @param state the State to get the value from. 48 * @param index the position inside of the lua_State to get the value from. 49 * @returns The value if found. 50 */ 27 51 template<> unsigned int fromLua<unsigned int>(lua_State* state, int index) { return (unsigned int)lua_tonumber(state, index); }; 52 /** 53 * @brief Converts a lua_State into any type. 54 * @param state the State to get the value from. 55 * @param index the position inside of the lua_State to get the value from. 56 * @returns The value if found. 57 */ 28 58 template<> float fromLua<float>(lua_State* state, int index) { return (float)lua_tonumber(state, index); }; 59 /** 60 * @brief Converts a lua_State into any type. 61 * @param state the State to get the value from. 62 * @param index the position inside of the lua_State to get the value from. 63 * @returns The value if found. 64 */ 29 65 template<> char fromLua<char>(lua_State* state, int index) { return (char)lua_tonumber(state, index); }; 66 /** 67 * @brief Converts a lua_State into any type. 68 * @param state the State to get the value from. 69 * @param index the position inside of the lua_State to get the value from. 70 * @returns The value if found. 71 */ 30 72 template<> const std::string& fromLua<const std::string&>(lua_State* state, int index) { temp[index] = lua_tostring(state, index); return temp[index]; }; 31 73 32 74 75 76 77 /** 78 * @brief writes a value into a lua_State. 79 * @param state the state to write into. 80 * @param value the Value of type to write into the State. 81 */ 33 82 template<typename type> void toLua(lua_State* state, type value) { Lunar<type>::push(state, value, false); }; 83 /** 84 * @brief writes a value into a lua_State. 85 * @param state the state to write into. 86 * @param value the Value of type to write into the State. 87 */ 34 88 template<> void toLua<bool>(lua_State* state, bool value) { lua_pushboolean(state, (int) value); }; 89 /** 90 * @brief writes a value into a lua_State. 91 * @param state the state to write into. 92 * @param value the Value of type to write into the State. 93 */ 35 94 template<> void toLua<int>(lua_State* state, int value) { lua_pushnumber(state, (lua_Number) value); }; 95 /** 96 * @brief writes a value into a lua_State. 97 * @param state the state to write into. 98 * @param value the Value of type to write into the State. 99 */ 36 100 template<> void toLua<unsigned int>(lua_State* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); }; 101 /** 102 * @brief writes a value into a lua_State. 103 * @param state the state to write into. 104 * @param value the Value of type to write into the State. 105 */ 37 106 template<> void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); }; 107 /** 108 * @brief writes a value into a lua_State. 109 * @param state the state to write into. 110 * @param value the Value of type to write into the State. 111 */ 38 112 template<> void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); }; 113 /** 114 * @brief writes a value into a lua_State. 115 * @param state the state to write into. 116 * @param value the Value of type to write into the State. 117 */ 39 118 template<> void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); } -
branches/new_class_id/src/lib/util/executor/executor_lua_state.h
r9747 r9748 1 1 /*! 2 * @file executor_ generic.h3 * Definition of a Generic Executor2 * @file executor_lua_state.h 3 * Definition of a Executor that takes lua_State* as input. 4 4 */ 5 5 … … 32 32 #undef FUNCTOR_CALL_TYPE 33 33 #endif 34 //! Define the Functor call type as lua_State*. 34 35 #define FUNCTOR_CALL_TYPE lua_State* 35 36 36 37 37 template<typename type> type fromLua(lua_State* state, int index); … … 64 64 return (fromLua<ToType>(CallValue, index+1)); 65 65 } 66 /** 67 * @param state the state to write into 68 * @param value the Value to write there. 69 */ 66 70 template <typename FromType> 67 71 static void storeRet(lua_State*& state, FromType value) … … 69 73 toLua<FromType>(state, value); 70 74 } 75 /** @returns the Null Value of a lua_State*, namely (pointer-type) NULL */ 71 76 static lua_State*& defaultValue() { static lua_State* nullState; return nullState; }; 72 77 }; -
branches/new_class_id/src/lib/util/executor/executor_static.h
r9745 r9748 1 1 /*! 2 * @file executor_ member.h3 * Definition of an Executor to Member Functions2 * @file executor_static.h 3 * Definition of an Executor to Static Functions (either Static-Class or C-Style) 4 4 */ 5 5 /* -
branches/new_class_id/src/lib/util/executor/executor_substring.cc
r9742 r9748 17 17 #include "helper_functions.h" 18 18 19 /** 20 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 21 * @param input the input as a String. 22 * @param defaultValue the Default Value set, if the input could not be converted into type. 23 * @returns either the converted value or defaultValue. 24 */ 19 25 template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); }; 26 /** 27 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 28 * @param input the input as a String. 29 * @param defaultValue the Default Value set, if the input could not be converted into type. 30 * @returns either the converted value or defaultValue. 31 */ 20 32 template<> int fromString<int>(const std::string& input, int defaultValue) { return isInt(input, defaultValue); }; 33 /** 34 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 35 * @param input the input as a String. 36 * @param defaultValue the Default Value set, if the input could not be converted into type. 37 * @returns either the converted value or defaultValue. 38 */ 21 39 template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); }; 40 /** 41 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 42 * @param input the input as a String. 43 * @param defaultValue the Default Value set, if the input could not be converted into type. 44 * @returns either the converted value or defaultValue. 45 */ 22 46 template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); }; 47 /** 48 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 49 * @param input the input as a String. 50 * @param defaultValue the Default Value set, if the input could not be converted into type. 51 * @returns either the converted value or defaultValue. 52 */ 23 53 template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); }; 54 /** 55 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 56 * @param input the input as a String. 57 * @param defaultValue the Default Value set, if the input could not be converted into type. 58 * @returns either the converted value or defaultValue. 59 */ 24 60 template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return (input.size() > 0) ? input : defaultValue; }; 25 61 26 62 63 /** 64 * @brief converts to any type from a MultiType 65 * @param multi the MultiType to convert. 66 * @returns the converted Value. 67 */ 27 68 template<> bool fromMulti<bool>(const MultiType& multi) { return multi.getBool(); }; 69 /** 70 * @brief converts to any type from a MultiType 71 * @param multi the MultiType to convert. 72 * @returns the converted Value. 73 */ 28 74 template<> int fromMulti<int>(const MultiType& multi) { return multi.getInt(); } 75 /** 76 * @brief converts to any type from a MultiType 77 * @param multi the MultiType to convert. 78 * @returns the converted Value. 79 */ 29 80 template<> unsigned int fromMulti<unsigned int>(const MultiType& multi) { return multi.getInt(); }; 81 /** 82 * @brief converts to any type from a MultiType 83 * @param multi the MultiType to convert. 84 * @returns the converted Value. 85 */ 30 86 template<> float fromMulti<float>(const MultiType& multi) { return multi.getFloat(); }; 87 /** 88 * @brief converts to any type from a MultiType 89 * @param multi the MultiType to convert. 90 * @returns the converted Value. 91 */ 31 92 template<> char fromMulti<char>(const MultiType& multi) { return multi.getChar(); }; 93 /** 94 * @brief converts to any type from a MultiType 95 * @param multi the MultiType to convert. 96 * @returns the converted Value. 97 */ 32 98 template<> const std::string& fromMulti<const std::string&>(const MultiType& multi) { return multi.getConstString(); }; 33 99 34 100 101 /** 102 * @brief retrieves a default value from an array of default values, at possition i. 103 * @param defaultValues the Array of default values. 104 * @param i the index. 105 * @returns the Default Value at Position i 106 */ 35 107 template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); }; 108 /** 109 * @brief retrieves a default value from an array of default values, at possition i. 110 * @param defaultValues the Array of default values. 111 * @param i the index. 112 * @returns the Default Value at Position i 113 */ 36 114 template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; 115 /** 116 * @brief retrieves a default value from an array of default values, at possition i. 117 * @param defaultValues the Array of default values. 118 * @param i the index. 119 * @returns the Default Value at Position i 120 */ 37 121 template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; 122 /** 123 * @brief retrieves a default value from an array of default values, at possition i. 124 * @param defaultValues the Array of default values. 125 * @param i the index. 126 * @returns the Default Value at Position i 127 */ 38 128 template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); }; 129 /** 130 * @brief retrieves a default value from an array of default values, at possition i. 131 * @param defaultValues the Array of default values. 132 * @param i the index. 133 * @returns the Default Value at Position i 134 */ 39 135 template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); }; 136 /** 137 * @brief retrieves a default value from an array of default values, at possition i. 138 * @param defaultValues the Array of default values. 139 * @param i the index. 140 * @returns the Default Value at Position i 141 */ 40 142 template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getStoredString(); }; 41 42 43 44 45 46 47 48 /**49 * A LITTLE TESTING SUITE FOR THE EXECUTOR.50 *51 #include "executor/executor_functional.h"52 53 #define EXECUTOR_FUNCTIONAL_USE_STATIC54 #include "executor/executor_functional.h"55 56 class TestClass : public BaseObject57 {58 public:59 TestClass() {};60 61 void printTest() { printf ("TEST\n"); };62 void printTestInt(int i) { printf ("%d\n", i); };63 void printTestBool(bool b) { printf("%d\n", (int)b); };64 void printTwoVals(int b, int i) { printf ("%d %d\n", b, i); };65 void printStrings(const std::string& name) { printf("String:: '%s'\n", name.c_str()); };66 static void printStatic() { printf("STATIC\n");};67 };68 69 void TEST()70 {71 TestClass test;72 SubString testStrings("1 SCHEISSE, 2, 3", ",", SubString::WhiteSpaces, false);73 (*createExecutor<TestClass>(&TestClass::printTest))(&test, testStrings);74 (*createExecutor<TestClass>(&TestClass::printTestInt))(&test, testStrings);75 (*createExecutor<TestClass>(&TestClass::printTestBool))(&test, testStrings);76 (*createExecutor<TestClass>(&TestClass::printTwoVals))(&test, testStrings);77 (*createExecutor<TestClass>(&TestClass::printStatic))(&test, testStrings);78 (*createExecutor<TestClass>(&TestClass::printStrings))(&test, testStrings);79 80 }81 */ -
branches/new_class_id/src/lib/util/executor/executor_substring.h
r9747 r9748 1 1 /*! 2 * @file executor_ generic.h2 * @file executor_substring.h 3 3 * Definition of a Generic Executor 4 4 */ … … 30 30 #undef FUNCTOR_CALL_TYPE 31 31 #endif 32 //! Use SubString as the FUNCTION_CALL_TYPE so that we can easily extend the Engine. 32 33 #define FUNCTOR_CALL_TYPE const SubString 33 34 35 /** 36 * @brief converts an input string into a value, if no value was converted, uses defaultValue. 37 * @param input the input as a String. 38 * @param defaultValue the Default Value set, if the input could not be converted into type. 39 * @returns either the converted value or defaultValue. 40 */ 34 41 template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; }; 35 42 template<> bool fromString<bool>(const std::string& input, bool defaultValue); … … 40 47 template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue); 41 48 49 /** 50 * @brief converts to any type from a MultiType 51 * @param multi the MultiType to convert. 52 * @returns the converted Value. 53 */ 42 54 template<typename type> type fromMulti(const MultiType& multi) { /* return defaultValue; */ }; 43 55 template<> bool fromMulti<bool>(const MultiType& multi); … … 48 60 template<> const std::string& fromMulti<const std::string&>(const MultiType& multi); 49 61 50 62 /** 63 * @brief retrieves a default value from an array of default values, at possition i. 64 * @param defaultValues the Array of default values. 65 * @param i the index. 66 * @returns the Default Value at Position i 67 */ 51 68 template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; 52 69 template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i); … … 77 94 fromMulti<ToType>(defaults[index]); 78 95 } 96 /** @returns the default Value of a SubString, namely NullSubString or SubString() */ 79 97 static const SubString& defaultValue() { return SubString::NullSubString; }; 80 98 }; -
branches/new_class_id/src/lib/util/executor/executor_xml.h
r9735 r9748 54 54 * @brief executes the Command on BaseObject 55 55 * @param object the BaseObject to execute this Executor on 56 * @param root ignored in this case56 * @param element ignored in this case 57 57 */ 58 58 virtual void operator()(BaseObject* object, const TiXmlElement*& element) const … … 64 64 65 65 private: 66 void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called 66 void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called. 67 67 const TiXmlElement* element; //!< The XML-element to call. 68 std::string paramName; 68 std::string paramName; //!< The Name of the Parameter this Executor should call. 69 69 }; 70 70 -
branches/new_class_id/src/lib/util/executor/functor_const_member.h
r9745 r9748 1 1 /*! 2 * @file functor_ member.h2 * @file functor_const_member.h 3 3 * Definition of an Functor 4 4 */ -
branches/new_class_id/src/lib/util/executor/functor_list.h
r9740 r9748 1 /*! 2 * @file functor_list.h 3 * all the Different types of Functions one can include by using a simple createExecutor call 4 * with a FunctionPointer as Argument 5 */ 1 6 /* 2 7 orxonox - the future of 3D-vertical-scrollers … … 10 15 */ 11 16 12 /*!13 * @file functors_list.h14 * all the Different types of Functions one can include by using a simple createExecutor call15 * with a FunctionPointer as Argument16 */17 17 18 18 #ifdef FUNCTOR_LIST -
branches/new_class_id/src/lib/util/executor/functor_static.h
r9745 r9748 1 1 /*! 2 * @file functor_ member.h3 * Definition of an Functor2 * @file functor_static.h 3 * Definition of Functors to Functions of Static Type 4 4 */ 5 5
Note: See TracChangeset
for help on using the changeset viewer.