Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/executor/executor_xml.h @ 9727

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

orxonox/new_class_id: new Executor construct, that is much more typesafe, faster, and easier to extend…

Also changed the LoadParam process, and adapted ScriptEngine calls

Then at the end, some missing headers appeared, and appended them to all the cc-files again.

File size: 2.2 KB
Line 
1/*!
2 * @file executor_xml.h
3 * Definition of a on-screen-shell
4 */
5
6#ifndef _EXECUTOR_XML_H
7#define _EXECUTOR_XML_H
8
9#include "executor.h"
10#include "compiler.h"
11#include "debug.h"
12
13#include "parser/tinyxml/tinyxml.h"
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<const TiXmlElement*>
22{
23public:
24  /**
25   * @brief 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 std::string& paramName)
31      : Executor<const TiXmlElement*>(false, MT_EXT1)
32  {
33    PRINTF(4)("Loading %s from XML-element %p\n", paramName.c_str(), root);
34
35    if (likely(root != NULL))
36      this->element = root->FirstChildElement(paramName);
37    else
38      this->element = NULL;
39
40    this->paramName = paramName;
41    this->functionPointer = function;
42    this->functorType = Executor_Objective;
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<const TiXmlElement*>* clone () const
50  {
51    return new ExecutorXML<T>(functionPointer, element, paramName);
52  }
53
54  /**
55   * @brief executes the Command on BaseObject
56   * @param object the BaseObject to execute this Executor on
57   * @param root ignored in this case
58   */
59  virtual void operator()(BaseObject* object, const TiXmlElement*& element) const
60  {
61    assert (object != NULL);
62    if (this->element != NULL)
63      (dynamic_cast<T*>(object)->*(functionPointer))(this->element);
64  }
65
66private:
67  void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
68  const   TiXmlElement* element;                       //!< The XML-element to call.
69  std::string           paramName;
70};
71
72#endif /* _EXECUTOR_XML_H */
Note: See TracBrowser for help on using the repository browser.