[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" |
---|
[1853] | 10 | |
---|
[5651] | 11 | #include "tinyxml.h" |
---|
[4838] | 12 | // FORWARD DECLARATION |
---|
[3543] | 13 | |
---|
[5651] | 14 | //! Executes a Function with a const TiXmlElement* parameter. |
---|
| 15 | /** |
---|
| 16 | * This is a Special Executor, that finds ParamName in root as XML-sub-element |
---|
| 17 | * This is especially usefull, if you have to Load a SubElement from root in a new Function |
---|
| 18 | * What must be defined is a XML-root to search the ParameterName under an a Function to call. |
---|
| 19 | */ |
---|
| 20 | template<class T> class ExecutorXML : public Executor |
---|
[5170] | 21 | { |
---|
| 22 | public: |
---|
[5651] | 23 | /** |
---|
| 24 | * Constructor of a ExecutorXML |
---|
| 25 | * @param function a Function to call |
---|
| 26 | * @param root The XML root to search paramName under |
---|
| 27 | * @param paramName the ParameterName the search in root, and lookup the TiXmlElement from |
---|
| 28 | */ |
---|
| 29 | ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const char* paramName) |
---|
[5659] | 30 | : Executor(1, MT_EXT1) |
---|
[5651] | 31 | { |
---|
| 32 | PRINTF(4)("Loading %s from XML-element %p\n", paramName, root); |
---|
[5641] | 33 | |
---|
[5651] | 34 | if (likely(root != NULL && paramName != NULL)) |
---|
| 35 | this->element = root->FirstChildElement(paramName); |
---|
| 36 | else |
---|
| 37 | this->element = NULL; |
---|
[5641] | 38 | |
---|
[5651] | 39 | this->functionPointer = function; |
---|
[5652] | 40 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
[5651] | 41 | } |
---|
[5164] | 42 | |
---|
[5651] | 43 | /** |
---|
| 44 | * clones an ExecutorXML, used to copy this Element. |
---|
| 45 | * @returns a _new_ Copy of this Executor |
---|
| 46 | */ |
---|
[5641] | 47 | virtual Executor* clone () const |
---|
| 48 | { |
---|
[5651] | 49 | ExecutorXML<T>* executor = new ExecutorXML<T>(); |
---|
[5641] | 50 | this->cloning(executor); |
---|
[5651] | 51 | executor->functionPointer = this->functionPointer; |
---|
| 52 | executor->element = this->element; |
---|
[5641] | 53 | return executor; |
---|
| 54 | } |
---|
[5633] | 55 | |
---|
[5651] | 56 | /** |
---|
| 57 | * executes the Command on BaseObject |
---|
| 58 | * @param object the BaseObject to execute this Executor on |
---|
| 59 | * @param loadString ignored in this case |
---|
| 60 | */ |
---|
| 61 | virtual void execute(BaseObject* object, const char* loadString) |
---|
[5135] | 62 | { |
---|
[5651] | 63 | if (object != NULL && this->element != NULL) |
---|
| 64 | (dynamic_cast<T*>(object)->*(functionPointer))(this->element); |
---|
[5145] | 65 | } |
---|
[5113] | 66 | |
---|
[5651] | 67 | private: |
---|
| 68 | /** |
---|
[5652] | 69 | * used for the copy-(Clone)-constructor |
---|
[5651] | 70 | */ |
---|
| 71 | ExecutorXML() : Executor() { }; |
---|
[5632] | 72 | |
---|
[5326] | 73 | |
---|
| 74 | private: |
---|
[5651] | 75 | void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called |
---|
| 76 | const TiXmlElement* element; //!< The XML-element to call. |
---|
[5326] | 77 | }; |
---|
| 78 | |
---|
[5651] | 79 | #endif /* _EXECUTOR_SPECIALS_H */ |
---|