Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: prepare for the new Executor

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 "compiler.h"
13#include "parser/tinyxml/tinyxml.h"
14// FORWARD DECLARATION
15
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 */
22template<class T> class ExecutorXML : public Executor
23{
24  public:
25    /**
26   * @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)
33    {
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      else
39        this->element = NULL;
40
41      this->functionPointer = function;
42      this->functorType = Executor_Objective | Executor_NoLoadString;
43    }
44
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    /**
59     * @brief executes the Command on BaseObject
60     * @param object the BaseObject to execute this Executor on
61     * @param loadString ignored in this case
62     */
63    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
64    {
65      if (object != NULL && this->element != NULL)
66        (dynamic_cast<T*>(object)->*(functionPointer))(this->element);
67    }
68
69    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
70    {
71      PRINTF(1)("missuse of XML-operator, OR IMPLEMENT.\n");
72    }
73
74  private:
75    /**
76   * @brief used for the copy-(Clone)-constructor
77     */
78    ExecutorXML() : Executor() { };
79
80
81  private:
82    void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
83    const   TiXmlElement* element;                       //!< The XML-element to call.
84};
85
86#endif /* _EXECUTOR_SPECIALS_H */
Note: See TracBrowser for help on using the repository browser.