[4592] | 1 | /* |
---|
[4250] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[4233] | 3 | |
---|
[4250] | 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 | |
---|
[4592] | 16 | /*! |
---|
[9727] | 17 | * @file load_param_xml.h |
---|
| 18 | * A Class and macro-functions, that makes our lives easy to load-in parameters from XML |
---|
[5129] | 19 | */ |
---|
[4250] | 20 | |
---|
[9727] | 21 | #ifndef _LOAD_PARAM_XML_H |
---|
| 22 | #define _LOAD_PARAM_XML_H |
---|
[4233] | 23 | |
---|
[9727] | 24 | #include "load_param.h" |
---|
[8048] | 25 | #include "executor/executor_xml.h" |
---|
[5549] | 26 | |
---|
[9763] | 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 | */ |
---|
[5651] | 36 | #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[9769] | 37 | XmlLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS, CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) |
---|
[5646] | 38 | |
---|
[9763] | 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 | */ |
---|
[5654] | 48 | #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[9769] | 49 | XmlLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS, CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) |
---|
[5651] | 50 | |
---|
[9763] | 51 | //! A Class that can load XML tags onto an Object. |
---|
[9770] | 52 | template <class OperateClass = BaseObject> class XmlLoadParam : public LoadParamBase |
---|
[5654] | 53 | { |
---|
[9769] | 54 | public: |
---|
| 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 | */ |
---|
[9770] | 63 | XmlLoadParam(const TiXmlElement* root, const std::string& paramName, OperateClass* object, Executor<const TiXmlElement*>* executor, bool inLoadCycle = false) |
---|
[9769] | 64 | : LoadParamBase(root, paramName, inLoadCycle), object(object) , executor(executor) |
---|
| 65 | { |
---|
| 66 | assert(this->object != NULL); |
---|
| 67 | assert(this->executor != NULL); |
---|
| 68 | } |
---|
[5332] | 69 | |
---|
[9769] | 70 | /** @brief executes and destroys the executor */ |
---|
| 71 | virtual ~XmlLoadParam() |
---|
| 72 | { |
---|
[9771] | 73 | this->setDescriptionValues(OperateClass::staticClassID(), executor->getParamCount(), executor->getDefaultValues(), executor->hasRetVal()); |
---|
[9769] | 74 | (*this->executor)(this->object, this->loadElem); |
---|
| 75 | delete this->executor; |
---|
| 76 | } |
---|
[5332] | 77 | |
---|
[9769] | 78 | /** @param descriptionText the description @returns self @brief describes the Loading parameter. */ |
---|
[9770] | 79 | XmlLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(OperateClass::staticClassID(), descriptionText); return *this; }; |
---|
[9769] | 80 | |
---|
| 81 | private: |
---|
[9770] | 82 | OperateClass* object; //!< The Object to apply this to. |
---|
[9769] | 83 | Executor<const TiXmlElement*>* executor; //!< The Executor, that does the actual loading process. |
---|
[5332] | 84 | }; |
---|
| 85 | |
---|
[9727] | 86 | #endif /* _LOAD_PARAM_XML_H */ |
---|