Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/executor/executor_specials.h @ 7828

Last change on this file since 7828 was 7711, checked in by patrick, 19 years ago

trunk: merged the cd branche back to trunk

File size: 2.5 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  private:
70    /**
71   * @brief used for the copy-(Clone)-constructor
72     */
73    ExecutorXML() : Executor() { };
74
75
76  private:
77    void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
78    const   TiXmlElement* element;                       //!< The XML-element to call.
79};
80
81#endif /* _EXECUTOR_SPECIALS_H */
Note: See TracBrowser for help on using the repository browser.