[4838] | 1 | /*! |
---|
[8271] | 2 | * @file executor_xml.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[8271] | 6 | #ifndef _EXECUTOR_XML_H |
---|
| 7 | #define _EXECUTOR_XML_H |
---|
[1853] | 8 | |
---|
[5651] | 9 | #include "executor.h" |
---|
[7711] | 10 | #include "compiler.h" |
---|
[8362] | 11 | #include "debug.h" |
---|
[1853] | 12 | |
---|
[5944] | 13 | #include "parser/tinyxml/tinyxml.h" |
---|
[3543] | 14 | |
---|
[5651] | 15 | //! Executes a Function with a const TiXmlElement* parameter. |
---|
| 16 | /** |
---|
| 17 | * This is a Special Executor, that finds ParamName in root as XML-sub-element |
---|
| 18 | * This is especially usefull, if you have to Load a SubElement from root in a new Function |
---|
| 19 | * What must be defined is a XML-root to search the ParameterName under an a Function to call. |
---|
| 20 | */ |
---|
[9869] | 21 | template<class T, class BaseClass = BaseObject> class ExecutorXML : public Executor<const TiXmlElement*> |
---|
[5170] | 22 | { |
---|
[9869] | 23 | public: |
---|
| 24 | /** |
---|
[7331] | 25 | * @brief Constructor of a ExecutorXML |
---|
[9869] | 26 | * @param function a Function to call |
---|
| 27 | * @param root The XML root to search paramName under |
---|
| 28 | * @param paramName the ParameterName the search in root, and lookup the TiXmlElement from |
---|
| 29 | */ |
---|
| 30 | ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const std::string& paramName) |
---|
| 31 | : Executor<const TiXmlElement*>(false, MT_EXT1) |
---|
| 32 | { |
---|
| 33 | PRINTF(4)("Loading %s from XML-element %p\n", paramName.c_str(), root); |
---|
[5641] | 34 | |
---|
[9869] | 35 | if (likely(root != NULL)) |
---|
| 36 | this->element = root->FirstChildElement(paramName); |
---|
| 37 | else |
---|
| 38 | this->element = NULL; |
---|
[5641] | 39 | |
---|
[9869] | 40 | this->paramName = paramName; |
---|
| 41 | this->functionPointer = function; |
---|
| 42 | } |
---|
[5164] | 43 | |
---|
[9869] | 44 | /** |
---|
| 45 | * @brief clones an ExecutorXML, used to copy this Element. |
---|
| 46 | * @returns a _new_ Copy of this Executor |
---|
| 47 | */ |
---|
| 48 | virtual Executor<const TiXmlElement*>* clone () const |
---|
| 49 | { |
---|
| 50 | return new ExecutorXML<T>(functionPointer, element, paramName); |
---|
| 51 | } |
---|
[5633] | 52 | |
---|
[9869] | 53 | /** |
---|
| 54 | * @brief executes the Command on BaseObject |
---|
| 55 | * @param object the BaseObject to execute this Executor on |
---|
| 56 | * @param element ignored in this case |
---|
| 57 | */ |
---|
| 58 | virtual void operator()(BaseObject* object, const TiXmlElement*& element) const |
---|
| 59 | { |
---|
| 60 | assert (object != NULL); |
---|
| 61 | if (this->element != NULL) |
---|
| 62 | (dynamic_cast<T*>(object)->*(functionPointer))(this->element); |
---|
| 63 | } |
---|
[5113] | 64 | |
---|
[9869] | 65 | private: |
---|
| 66 | void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called. |
---|
| 67 | const TiXmlElement* element; //!< The XML-element to call. |
---|
| 68 | std::string paramName; //!< The Name of the Parameter this Executor should call. |
---|
[5326] | 69 | }; |
---|
| 70 | |
---|
[8271] | 71 | #endif /* _EXECUTOR_XML_H */ |
---|