[4838] | 1 | /*! |
---|
[5632] | 2 | * @file executor.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[5651] | 6 | #ifndef _EXECUTOR_SPECIALS_H |
---|
| 7 | #define _EXECUTOR_SPECIALS_H |
---|
[1853] | 8 | |
---|
[5651] | 9 | #include "executor.h" |
---|
[7711] | 10 | #include "compiler.h" |
---|
[1853] | 11 | |
---|
[5754] | 12 | #include "compiler.h" |
---|
[5944] | 13 | #include "parser/tinyxml/tinyxml.h" |
---|
[4838] | 14 | // FORWARD DECLARATION |
---|
[3543] | 15 | |
---|
[5651] | 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 |
---|
[5170] | 23 | { |
---|
| 24 | public: |
---|
[5651] | 25 | /** |
---|
[7331] | 26 | * @brief Constructor of a ExecutorXML |
---|
[5651] | 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) |
---|
[7197] | 32 | : Executor(MT_EXT1) |
---|
[5651] | 33 | { |
---|
| 34 | PRINTF(4)("Loading %s from XML-element %p\n", paramName, root); |
---|
[5641] | 35 | |
---|
[5651] | 36 | if (likely(root != NULL && paramName != NULL)) |
---|
| 37 | this->element = root->FirstChildElement(paramName); |
---|
| 38 | else |
---|
| 39 | this->element = NULL; |
---|
[5641] | 40 | |
---|
[5651] | 41 | this->functionPointer = function; |
---|
[5652] | 42 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
[5651] | 43 | } |
---|
[5164] | 44 | |
---|
[5651] | 45 | /** |
---|
[7331] | 46 | * @brief clones an ExecutorXML, used to copy this Element. |
---|
[5651] | 47 | * @returns a _new_ Copy of this Executor |
---|
| 48 | */ |
---|
[5641] | 49 | virtual Executor* clone () const |
---|
| 50 | { |
---|
[5651] | 51 | ExecutorXML<T>* executor = new ExecutorXML<T>(); |
---|
[5641] | 52 | this->cloning(executor); |
---|
[5651] | 53 | executor->functionPointer = this->functionPointer; |
---|
| 54 | executor->element = this->element; |
---|
[5641] | 55 | return executor; |
---|
| 56 | } |
---|
[5633] | 57 | |
---|
[5651] | 58 | /** |
---|
[7331] | 59 | * @brief executes the Command on BaseObject |
---|
[5651] | 60 | * @param object the BaseObject to execute this Executor on |
---|
| 61 | * @param loadString ignored in this case |
---|
| 62 | */ |
---|
[7474] | 63 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
[5135] | 64 | { |
---|
[5651] | 65 | if (object != NULL && this->element != NULL) |
---|
| 66 | (dynamic_cast<T*>(object)->*(functionPointer))(this->element); |
---|
[5145] | 67 | } |
---|
[5113] | 68 | |
---|
[5651] | 69 | private: |
---|
| 70 | /** |
---|
[7331] | 71 | * @brief used for the copy-(Clone)-constructor |
---|
[5651] | 72 | */ |
---|
| 73 | ExecutorXML() : Executor() { }; |
---|
[5632] | 74 | |
---|
[5326] | 75 | |
---|
| 76 | private: |
---|
[5651] | 77 | void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called |
---|
| 78 | const TiXmlElement* element; //!< The XML-element to call. |
---|
[5326] | 79 | }; |
---|
| 80 | |
---|
[5651] | 81 | #endif /* _EXECUTOR_SPECIALS_H */ |
---|