Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/scriptimprovements/src/lib/util/loading/load_param_xml.h @ 10558

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16/*!
17 * @file load_param_xml.h
18 * A Class and macro-functions, that makes our lives easy to load-in parameters from XML
19 */
20
21#ifndef _LOAD_PARAM_XML_H
22#define _LOAD_PARAM_XML_H
23
24#include "load_param.h"
25#include "executor/executor_xml.h"
26
27/**
28 * @brief Loads a Parameter from ROOT named PARAMETER_NAME
29 * onto OBJECT of CLASS, trough FUNCTION
30 * @param ROOT the TiXmlElement to load the Parameter from
31 * @param PARAMETER_NAME the Name of the Parameter to load
32 * @param OBJECT The BaseObject to load the new setting to.
33 * @param CLASS What Class the BaseObejct is of (this is for identifying the Functuon)
34 * @param FUNCTION The function of Class to Load (if you want to call &CLASS::FUNCTION write FUNCTION here).
35 */
36#define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
37         XmlLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS, CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false)
38
39
40/**
41 * @brief Does essentially the same as LoadParamXML, but within a Cycle in an ordered fashion.
42 *
43 * This Function looks in each Element, if the PARAMETER_NAME matches, and loads onto OBJECT
44 * of CLASS the ROOT through FUNCTION
45 *
46 * @see LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION)
47 */
48#define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
49         XmlLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS, CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true)
50
51//! A Class that can load XML tags onto an Object.
52template <class OperateClass = BaseObject> class XmlLoadParam : public LoadParamBase
53{
54public:
55  /**
56   * @brief generates a LoadParam based on
57   * @param root the Root Element to load onto the object.
58   * @param paramName the Parameter name that is loaded.
59   * @param object the Object to apply the changes on.
60   * @param executor the Functional Object, that actually executes the function Call.
61   * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here)
62   */
63  XmlLoadParam(const TiXmlElement* root, const std::string& paramName, OperateClass* object, Executor<const TiXmlElement*>* executor, bool inLoadCycle = false)
64      : LoadParamBase(root, paramName, inLoadCycle), object(object) , executor(executor)
65  {
66    assert(this->object != NULL);
67    assert(this->executor != NULL);
68  }
69
70  /** @brief executes and destroys the executor */
71  virtual ~XmlLoadParam()
72  {
73    this->setDescriptionValues(OperateClass::staticClassID(), executor->getParamCount(), executor->getDefaultValues(), executor->hasRetVal());
74    (*this->executor)(this->object, this->loadElem);
75    delete this->executor;
76  }
77
78  /** @param descriptionText the description @returns self @brief describes the Loading parameter. */
79  XmlLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(OperateClass::staticClassID(), descriptionText); return *this; };
80
81private:
82  OperateClass*                        object;         //!< The Object to apply this to.
83  Executor<const TiXmlElement*>*    executor;       //!< The Executor, that does the actual loading process.
84};
85
86#endif /* _LOAD_PARAM_XML_H */
Note: See TracBrowser for help on using the repository browser.