Changeset 9869 in orxonox.OLD for trunk/src/lib/util/loading/load_param.h
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/loading/load_param.h
r8048 r9869 22 22 #define _LOAD_PARAM_H 23 23 24 #include "base_object.h" 24 #include "util/executor/executor_substring.h" 25 #include "util/executor/executor_member.h" 26 #include "util/executor/functor_member.h" 25 27 26 #include "executor/executor.h" 27 #include "executor/executor_xml.h" 28 #include "parser/tinyxml/tinyxml.h" 28 29 29 30 // Forward Declaration // 30 31 class LoadClassDescription; 31 32 class LoadParamDescription; 32 class MultiType; 33 33 class TiXmlElement; 34 34 35 35 /** 36 36 * Loads a Parameter from ROOT named PARAMETER_NAME 37 * onto OBJECT of CLASS, trough theFUNCTION37 * onto OBJECT of CLASS, trough FUNCTION 38 38 * @param ROOT the TiXmlElement to load the Parameter from 39 39 * @param PARAMETER_NAME the Name of the Parameter to load … … 43 43 */ 44 44 #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 45 CLoadParam (ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false)45 CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), false) 46 46 47 /** 48 * @brief Does essentially the same as LoadParam, but within a Cycle in an ordered fashion. 49 * 50 * This Function looks in each Element, if the PARAMETER_NAME matches, and loads onto OBJECT 51 * of CLASS the ROOT through FUNCTION 52 * 53 * @see LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) 54 */ 47 55 #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 48 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true) 49 50 #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 51 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) 52 53 #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 54 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) 55 56 CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), true) 56 57 57 58 /** … … 78 79 } 79 80 81 80 82 /************************** 81 83 **** REAL DECLARATIONS **** 82 84 **************************/ 83 //! abstract Base class for a Loadable parameter84 class CLoadParam : public BaseObject85 //!< A BaseClass for all LoadParam's. 86 class LoadParamBase 85 87 { 86 public: 87 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false); 88 virtual ~CLoadParam(); 88 protected: 89 LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle = false); 89 90 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); 91 protected: 92 void describe(const ClassID& classID, const std::string& descriptionText); 93 void setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal = false); 94 95 public: 96 static std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); 97 static const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); 98 99 protected: 100 const std::string paramName; //!< The Name of the Parameter this LoadParams applies to. 101 bool inLoadCycle; //!< If the Parameter is in a LoadCycle. 102 103 const TiXmlElement* loadElem; //!< The Element to load. 104 }; 95 105 96 106 97 private: 98 bool inLoadCycle; 99 Executor* executor; 100 BaseObject* object; 101 const std::string paramName; 107 //! The Loading Class of the LoadParam, that acctually executes the loading process. 108 template <class OperateClass> class CLoadParam : public LoadParamBase 109 { 110 public: 111 /** 112 * @brief generates a LoadParam based on: 113 * @param root the Root Element to load onto the object. @param paramName the Parameter name that is loaded. 114 * @param object the Object to apply the changes on. @param executor the Functional Object, that actually executes the function Call. 115 * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here) 116 */ 117 CLoadParam(const TiXmlElement* root, const std::string& paramName, OperateClass* object, Executor<const SubString, OperateClass>* executor, bool inLoadCycle = false) 118 : LoadParamBase(root, paramName, inLoadCycle) 119 { 120 assert (executor != NULL); 121 this->object = object; 122 this->executor = executor; 123 } 124 virtual ~CLoadParam() 125 { 126 std::string loadString; 127 if (this->loadElem != NULL && this->loadElem->ToText()) 128 { 129 loadString = this->loadElem->Value(); 130 if (!loadString.empty()) 131 { 132 /* PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", 133 this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName());*/ 134 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\')); 135 } 136 } 137 this->setDescriptionValues(OperateClass::staticClassID(), executor->getParamCount(), executor->getDefaultValues(), executor->hasRetVal()); 138 delete this->executor; 139 } 140 /** 141 * @brief set the default values of the executor 142 * @param value0 the first default value @param value1 the second default value 143 * @param value2 the third default value @param value3 the fourth default value 144 * @param value4 the fifth default value 145 */ 146 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 147 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 148 const MultiType& value4 = MT_NULL) 149 { this->executor->defaultValues(value0, value1, value2, value3, value4); return *this; }; 150 //! Describes a LoadParam 151 CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(OperateClass::staticClassID(), descriptionText); return *this; }; 152 // CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor); 102 153 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; 154 private: 155 Executor<const SubString, OperateClass>* executor; //!< The Executor, that actually executes the Loading process. 156 OperateClass* object; //!< The Object this LoadParam operates on. 109 157 }; 110 158 111 // helper function112 113 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);114 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);115 116 159 #endif /* _LOAD_PARAM_H */
Note: See TracChangeset
for help on using the changeset viewer.