Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/executor/executor_xml.h @ 8195

Last change on this file since 8195 was 8051, checked in by bensch, 18 years ago

lua: new Executor for lua-interpretation

File size: 2.6 KB
Line 
1/*!
2 * @file executor.h
3 * Definition of a on-screen-shell
4 */
5
6#ifndef _EXECUTOR_SPECIALS_H
7#define _EXECUTOR_SPECIALS_H
8
9#include "executor.h"
10#include "compiler.h"
11
12#include "parser/tinyxml/tinyxml.h"
13
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 */
20template<class T> class ExecutorXML : public Executor
21{
22  public:
23    /**
24   * @brief 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)
30      : Executor(MT_EXT1)
31    {
32      PRINTF(4)("Loading %s from XML-element %p\n", paramName, root);
33
34      if (likely(root != NULL && paramName != NULL))
35        this->element = root->FirstChildElement(paramName);
36      else
37        this->element = NULL;
38
39      this->functionPointer = function;
40      this->functorType = Executor_Objective | Executor_NoLoadString;
41    }
42
43    /**
44     * @brief clones an ExecutorXML, used to copy this Element.
45     * @returns a _new_ Copy of this Executor
46     */
47    virtual Executor* clone () const
48    {
49      ExecutorXML<T>* executor = new ExecutorXML<T>();
50      this->cloning(executor);
51      executor->functionPointer = this->functionPointer;
52      executor->element = this->element;
53      return executor;
54    }
55
56    /**
57     * @brief 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 operator()(BaseObject* object, const SubString& = SubString()) const
62    {
63      if (object != NULL && this->element != NULL)
64        (dynamic_cast<T*>(object)->*(functionPointer))(this->element);
65    }
66
67    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
68    {
69      PRINTF(1)("missuse of XML-operator, OR IMPLEMENT.\n");
70    }
71
72  private:
73    /**
74   * @brief used for the copy-(Clone)-constructor
75     */
76    ExecutorXML() : Executor() { };
77
78
79  private:
80    void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
81    const   TiXmlElement* element;                       //!< The XML-element to call.
82};
83
84#endif /* _EXECUTOR_SPECIALS_H */
Note: See TracBrowser for help on using the repository browser.