Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6461 was 5944, checked in by bensch, 19 years ago

orxonox/trunk: ini-parser in own subdir now (also moved tiXml-lib to lib/parser

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 "compiler.h"
12#include "parser/tinyxml/tinyxml.h"
13// FORWARD DECLARATION
14
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 */
21template<class T> class ExecutorXML : public Executor
22{
23  public:
24    /**
25     * Constructor of a ExecutorXML
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 char* paramName)
31      : Executor(1, MT_EXT1)
32    {
33      PRINTF(4)("Loading %s from XML-element %p\n", paramName, root);
34
35      if (likely(root != NULL && paramName != NULL))
36        this->element = root->FirstChildElement(paramName);
37      else
38        this->element = NULL;
39
40      this->functionPointer = function;
41      this->functorType = Executor_Objective | Executor_NoLoadString;
42    }
43
44    /**
45     * clones an ExecutorXML, used to copy this Element.
46     * @returns a _new_ Copy of this Executor
47     */
48    virtual Executor* clone () const
49    {
50      ExecutorXML<T>* executor = new ExecutorXML<T>();
51      this->cloning(executor);
52      executor->functionPointer = this->functionPointer;
53      executor->element = this->element;
54      return executor;
55    }
56
57    /**
58     * executes the Command on BaseObject
59     * @param object the BaseObject to execute this Executor on
60     * @param loadString ignored in this case
61     */
62    virtual void execute(BaseObject* object, const void* parameters = NULL)
63    {
64      if (object != NULL && this->element != NULL)
65        (dynamic_cast<T*>(object)->*(functionPointer))(this->element);
66    }
67
68  private:
69    /**
70     * used for the copy-(Clone)-constructor
71     */
72    ExecutorXML() : Executor() { };
73
74
75  private:
76    void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
77    const   TiXmlElement* element;                       //!< The XML-element to call.
78};
79
80#endif /* _EXECUTOR_SPECIALS_H */
Note: See TracBrowser for help on using the repository browser.