Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5711 was 5691, checked in by bensch, 19 years ago

orxonox/trunk: moved functor_list.h

File size: 2.4 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
11#include "tinyxml.h"
12// FORWARD DECLARATION
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     * 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(1, 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     * 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     * 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 void* parameters = NULL)
62    {
63      if (object != NULL && this->element != NULL)
64        (dynamic_cast<T*>(object)->*(functionPointer))(this->element);
65    }
66
67  private:
68    /**
69     * used for the copy-(Clone)-constructor
70     */
71    ExecutorXML() : Executor() { };
72
73
74  private:
75    void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
76    const   TiXmlElement* element;                       //!< The XML-element to call.
77};
78
79#endif /* _EXECUTOR_SPECIALS_H */
Note: See TracBrowser for help on using the repository browser.