Changeset 9727 in orxonox.OLD for branches/new_class_id/src/lib/util/loading/load_param_xml.h
- Timestamp:
- Sep 14, 2006, 5:24:31 PM (18 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/load_param_xml.h
r9726 r9727 15 15 16 16 /*! 17 * @file load_param .h18 * A Class and macro-functions, that makes our lives easy to load-in parameters 17 * @file load_param_xml.h 18 * A Class and macro-functions, that makes our lives easy to load-in parameters from XML 19 19 */ 20 20 21 #ifndef _LOAD_PARAM_ H22 #define _LOAD_PARAM_ H21 #ifndef _LOAD_PARAM_XML_H 22 #define _LOAD_PARAM_XML_H 23 23 24 #include "base_object.h" 25 26 #include "executor/executor.h" 24 #include "load_param.h" 27 25 #include "executor/executor_xml.h" 28 26 29 // Forward Declaration //30 class LoadClassDescription;31 class LoadParamDescription;32 class MultiType;33 34 35 /**36 * Loads a Parameter from ROOT named PARAMETER_NAME37 * onto OBJECT of CLASS, trough the FUNCTION38 * @param ROOT the TiXmlElement to load the Parameter from39 * @param PARAMETER_NAME the Name of the Parameter to load40 * @param OBJECT The BaseObject to load the new setting to.41 * @param CLASS What Class the BaseObejct is of (this is for identifying the Functuon)42 * @param FUNCTION The function of Class to Load (if you want to call &CLASS::FUNCTION write FUNCTION here).43 */44 #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \45 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false)46 47 #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \48 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true)49 50 27 #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 51 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false)28 XmlLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) 52 29 53 30 #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 54 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true)31 XmlLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) 55 32 56 57 /** 58 * this Starts a Cycle in the Loading Process 59 * be aware, that in the cycle the first parameter of load_param should because 60 * called element, and that you must say true at the Fith parameter, or it will fail 61 * also you will have to close the Cycle again with LOAD_PARAM_END_CYCLE 62 * 63 * @param ROOT The root XLM-element to search element under. 64 * @param ELEMENT the element to search 65 */ 66 #define LOAD_PARAM_START_CYCLE(ROOT, ELEMENT) \ 67 const TiXmlElement* ELEMENT; \ 68 ELEMENT= ROOT->FirstChildElement(); \ 69 while( ELEMENT != NULL) \ 70 { 71 /** 72 * closes a LoadParam Loop 73 * @see LOAD_PARAM_START_CYCLE 74 * @param ELEMENT the Element to step through. 75 */ 76 #define LOAD_PARAM_END_CYCLE(ELEMENT) \ 77 ELEMENT = ELEMENT->NextSiblingElement(); \ 78 } 79 80 /************************** 81 **** REAL DECLARATIONS **** 82 **************************/ 83 //! abstract Base class for a Loadable parameter 84 class CLoadParam : public BaseObject 33 class XmlLoadParam : public LoadParamBase 85 34 { 86 35 public: 87 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false);88 virtual ~ CLoadParam();36 XmlLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const TiXmlElement*>* executor, bool inLoadCycle = false); 37 virtual ~XmlLoadParam(); 89 38 90 CLoadParam& describe(const std::string& descriptionText); 91 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 92 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 93 const MultiType& value4 = MT_NULL); 94 CLoadParam& attribute(const std::string& attributeName, const Executor& executor); 95 39 XmlLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; }; 96 40 97 41 private: 98 bool inLoadCycle; 99 Executor* executor; 100 BaseObject* object; 101 const std::string paramName; 102 103 LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter 104 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 105 const TiXmlElement* loadElem; //!< The Element to load. 106 const void* pointerToParam; //!< A Pointer to a Parameter. 107 108 MultiType* defaultValue; 42 Executor<const TiXmlElement*>* executor; 109 43 }; 110 44 111 // helper function 112 113 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); 114 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); 115 116 #endif /* _LOAD_PARAM_H */ 45 #endif /* _LOAD_PARAM_XML_H */
Note: See TracChangeset
for help on using the changeset viewer.