Changeset 8051 in orxonox.OLD for trunk/src/lib/util/executor
- Timestamp:
- Jun 1, 2006, 12:57:57 AM (19 years ago)
- Location:
- trunk/src/lib/util/executor
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/executor/executor_lua.cc
r8042 r8051 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include " proto_class.h"18 #include "executor_lua.h" 19 19 20 using namespace std; 20 template<> bool fromLua<bool>(lua_state* state) { return lua_tonumber(state); }; 21 template<> int fromLua<int>(lua_state* state); 22 template<> unsigned int fromLua<unsigned int>(lua_state* state); 23 template<> float fromLua<float>(lua_state* state); 24 template<> char fromLua<char>(lua_state* state); 25 template<> const std::string& fromLua<const std::string&>(lua_state* state); 21 26 22 23 /**24 * standard constructor25 * @todo this constructor is not jet implemented - do it26 */27 ProtoClass::ProtoClass ()28 {29 this->setClassID(CL_PROTO_ID, "ProtoClass");30 31 /* If you make a new class, what is most probably the case when you write this file32 don't forget to:33 1. Add the new file new_class.cc to the ./src/Makefile.am34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS35 36 Advanced Topics:37 - if you want to let your object be managed via the ObjectManager make sure to read38 the object_manager.h header comments. You will use this most certanly only if you39 make many objects of your class, like a weapon bullet.40 */41 }42 43 44 /**45 * standard deconstructor46 */47 ProtoClass::~ProtoClass ()48 {49 // delete what has to be deleted here50 } -
trunk/src/lib/util/executor/executor_lua.h
r8048 r8051 10 10 #include "compiler.h" 11 11 12 #include "compiler.h" 13 #include "parser/tinyxml/tinyxml.h" 12 #include "luaincl.h" 13 14 15 16 template<typename type> type fromLua(lua_state* state) { PRINTF(1)("NOT IMPLEMENTED\n"); }; 17 template<> bool fromLua<bool>(lua_state* state); 18 template<> int fromLua<int>(lua_state* state); 19 template<> unsigned int fromLua<unsigned int>(lua_state* state); 20 template<> float fromLua<float>(lua_state* state); 21 template<> char fromLua<char>(lua_state* state); 22 template<> const std::string& fromLua<const std::string&>(lua_state* state); 23 14 24 // FORWARD DECLARATION 15 25 16 //! Executes a Function with a const TiXmlElement* parameter. 17 /** 18 * This is a Special Executor, that finds ParamName in root as XML-sub-element 19 * This is especially usefull, if you have to Load a SubElement from root in a new Function 20 * What must be defined is a XML-root to search the ParameterName under an a Function to call. 21 */ 22 template<class T> class ExecutorXML : public Executor 26 27 /////////// 28 //// 0 //// 29 /////////// 30 //! Executes a Function with a lua_state* parameter. 31 template<class T> class ExecutorLua0 : public Executor 32 { 33 public: 34 /** 35 * @brief Constructor of a ExecutorXML 36 * @param function a Function to call 37 */ 38 ExecutorLua0(void(T::*function)()) 39 : Executor() 40 { 41 this->functionPointer = function; 42 this->functorType = Executor_Objective | Executor_NoLoadString; 43 } 44 45 /** 46 * @brief executes the Command on BaseObject 47 * @param object the BaseObject to execute this Executor on 48 * @param loadString ignored in this case 49 */ 50 virtual void operator()(BaseObject* object, const SubString& = SubString()) const 51 { 52 PRINTF(1)("no usefull executor\n"); 53 } 54 55 virtual void operator()(BaseObject* object, unsigned int count, void* values) const 56 { 57 (dynamic_cast<T*>(object)->*(functionPointer))(); 58 } 59 60 /** 61 * @returns a _new_ Copy of this Executor 62 */ 63 virtual Executor* clone () const 64 { 65 return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); 66 } 67 }; 68 69 70 71 /////////// 72 //// 1 //// 73 /////////// 74 //! Executes a Function with a lua_state* parameter. 75 template<class T, typename type0> class ExecutorLua1 : public Executor 23 76 { 24 77 public: 25 78 /** 26 79 * @brief Constructor of a ExecutorXML 27 * @param function a Function to call 28 * @param root The XML root to search paramName under 29 * @param paramName the ParameterName the search in root, and lookup the TiXmlElement from 30 */ 31 ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const char* paramName) 32 : Executor(MT_EXT1) 80 * @param function a Function to call 81 */ 82 ExecutorLua0(void(T::*function)(type0)) 83 : Executor(ExecutorParamType<type0>()) 33 84 { 34 PRINTF(4)("Loading %s from XML-element %p\n", paramName, root);35 36 if (likely(root != NULL && paramName != NULL))37 this->element = root->FirstChildElement(paramName);38 else39 this->element = NULL;40 41 85 this->functionPointer = function; 42 86 this->functorType = Executor_Objective | Executor_NoLoadString; 43 87 } 44 88 45 /** 46 * @brief clones an ExecutorXML, used to copy this Element. 47 * @returns a _new_ Copy of this Executor 48 */ 49 virtual Executor* clone () const 50 { 51 ExecutorXML<T>* executor = new ExecutorXML<T>(); 52 this->cloning(executor); 53 executor->functionPointer = this->functionPointer; 54 executor->element = this->element; 55 return executor; 56 } 57 58 /** 89 /** 59 90 * @brief executes the Command on BaseObject 60 91 * @param object the BaseObject to execute this Executor on 61 92 * @param loadString ignored in this case 62 93 */ 63 94 virtual void operator()(BaseObject* object, const SubString& = SubString()) const 64 95 { 65 if (object != NULL && this->element != NULL) 66 (dynamic_cast<T*>(object)->*(functionPointer))(this->element); 96 PRINTF(1)("no usefull executor\n"); 67 97 } 68 98 69 99 virtual void operator()(BaseObject* object, unsigned int count, void* values) const 70 100 { 71 PRINTF(1)("missuse of XML-operator, OR IMPLEMENT.\n"); 101 lua_state* state = (lua_state*)values; 102 type0 value0 = lua_pop values 103 104 (dynamic_cast<T*>(object)->*(functionPointer))(); 72 105 } 73 106 74 private: 75 /** 76 * @brief used for the copy-(Clone)-constructor 77 */ 78 ExecutorXML() : Executor() { }; 107 /** 108 * @returns a _new_ Copy of this Executor 109 */ 110 virtual Executor* clone () const 111 { 112 return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); 113 } 114 }; 79 115 80 116 81 private:82 void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called83 const TiXmlElement* element; //!< The XML-element to call.84 };85 86 117 #endif /* _EXECUTOR_SPECIALS_H */ -
trunk/src/lib/util/executor/executor_xml.h
r8048 r8051 10 10 #include "compiler.h" 11 11 12 #include "compiler.h"13 12 #include "parser/tinyxml/tinyxml.h" 14 // FORWARD DECLARATION15 13 16 14 //! Executes a Function with a const TiXmlElement* parameter.
Note: See TracChangeset
for help on using the changeset viewer.