Changeset 9769 in orxonox.OLD for branches/new_class_id/src/lib/util/loading
- Timestamp:
- Sep 19, 2006, 9:35:11 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util/loading
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/load_param.cc
r9765 r9769 27 27 * @param inLoadCycle If we are in a LoadCycle (loading differs.). 28 28 */ 29 LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object,bool inLoadCycle)30 : object(object),paramName(paramName), inLoadCycle(inLoadCycle)29 LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle) 30 : paramName(paramName), inLoadCycle(inLoadCycle) 31 31 { 32 32 // determin the LoadString. … … 55 55 56 56 57 /**58 * @brief generates a LoadParam based on59 * @param root the Root Element to load onto the object.60 * @param paramName the Parameter name that is loaded.61 * @param object the Object to apply the changes on.62 * @param executor the Functional Object, that actually executes the function Call.63 * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here)64 */65 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const SubString>* executor, bool inLoadCycle)66 : LoadParamBase(root, paramName, object, inLoadCycle)67 {68 assert (executor != NULL);69 // set the Executor.70 this->executor = executor;71 //if (this->executor)72 // this->executor->setName(paramName);73 }74 75 /**76 * This is a VERY SPECIAL deconsrtuctor.77 * It is made, so that it loads the Parameters on destruction.78 * meaning, if an Executor a valid Object exist, and all79 * Execution-Conditions are met, they are executed here.80 */81 CLoadParam::~CLoadParam()82 {83 assert(this->object != NULL);84 85 std::string loadString;86 if (this->loadElem != NULL && this->loadElem->ToText())87 {88 loadString = this->loadElem->Value();89 if (!loadString.empty())90 {91 PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n",92 this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName());93 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\'));94 }95 }96 delete this->executor;97 }98 99 /**100 * @brief set the default values of the executor101 * @param value0 the first default value102 * @param value1 the second default value103 * @param value2 the third default value104 * @param value3 the fourth default value105 * @param value4 the fifth default value106 */107 CLoadParam& CLoadParam::defaultValues(const MultiType& value0, const MultiType& value1,108 const MultiType& value2, const MultiType& value3,109 const MultiType& value4)110 {111 assert(this->executor != NULL);112 this->executor->defaultValues(value0, value1, value2, value3, value4);113 114 return *this;115 }116 57 117 58 -
branches/new_class_id/src/lib/util/loading/load_param.h
r9765 r9769 45 45 */ 46 46 #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 47 CLoadParam (ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false)47 CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), false) 48 48 49 49 /** … … 56 56 */ 57 57 #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 58 CLoadParam (ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true)58 CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), true) 59 59 60 60 /** … … 89 89 { 90 90 protected: 91 LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object,bool inLoadCycle = false);91 LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle = false); 92 92 93 93 protected: … … 95 95 96 96 protected: 97 BaseObject* object; //!< The Object to work on98 97 const std::string paramName; //!< The Name of the Parameter this LoadParams applies to. 99 98 bool inLoadCycle; //!< If the Parameter is in a LoadCycle. … … 104 103 105 104 //! The Loading Class of the LoadParam, that acctually executes the loading process. 106 class CLoadParam : public LoadParamBase105 template <class OperateClass> class CLoadParam : public LoadParamBase 107 106 { 108 107 public: 109 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const SubString>* executor, bool inLoadCycle = false); 110 virtual ~CLoadParam(); 111 108 /** 109 * @brief generates a LoadParam based on 110 * @param root the Root Element to load onto the object. 111 * @param paramName the Parameter name that is loaded. 112 * @param object the Object to apply the changes on. 113 * @param executor the Functional Object, that actually executes the function Call. 114 * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here) 115 */ 116 CLoadParam(const TiXmlElement* root, const std::string& paramName, OperateClass* object, Executor<const SubString, OperateClass>* executor, bool inLoadCycle = false) 117 : LoadParamBase(root, paramName, inLoadCycle) 118 { 119 assert (executor != NULL); 120 this->object = object; 121 this->executor = executor; 122 } 123 virtual ~CLoadParam() 124 { 125 std::string loadString; 126 if (this->loadElem != NULL && this->loadElem->ToText()) 127 { 128 loadString = this->loadElem->Value(); 129 if (!loadString.empty()) 130 { 131 /* PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", 132 this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName());*/ 133 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\')); 134 } 135 } 136 delete this->executor; 137 } 138 /** 139 * @brief set the default values of the executor 140 * @param value0 the first default value @param value1 the second default value 141 * @param value2 the third default value @param value3 the fourth default value 142 * @param value4 the fifth default value 143 */ 112 144 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 113 145 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 114 const MultiType& value4 = MT_NULL); 146 const MultiType& value4 = MT_NULL) 147 { this->executor->defaultValues(value0, value1, value2, value3, value4); return *this; }; 115 148 CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; }; 116 149 // CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor); … … 118 151 119 152 private: 120 Executor<const SubString>* executor; //!< The Executor, that actually executes the Loading process. 153 Executor<const SubString, OperateClass>* executor; //!< The Executor, that actually executes the Loading process. 154 OperateClass* object; 121 155 }; 122 156 -
branches/new_class_id/src/lib/util/loading/load_param_xml.cc
r9763 r9769 1 /*2 orxonox - the future of 3D-vertical-scrollers3 4 Copyright (C) 2004 orx5 6 This program is free software; you can redistribute it and/or modify7 it under the terms of the GNU General Public License as published by8 the Free Software Foundation; either version 2, or (at your option)9 any later version.10 11 ### File Specific:12 main-programmer: Benjamin Grauer13 co-programmer: ...14 */15 1 16 2 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING … … 19 5 #include "load_param_description.h" 20 6 21 22 /**23 * @brief generates a LoadParam based on24 * @param root the Root Element to load onto the object.25 * @param paramName the Parameter name that is loaded.26 * @param object the Object to apply the changes on.27 * @param executor the Functional Object, that actually executes the function Call.28 * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here)29 */30 XmlLoadParam::XmlLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const TiXmlElement*>* executor, bool inLoadCycle )31 : LoadParamBase(root, paramName, object, inLoadCycle)32 {33 this->executor = executor;34 }35 36 37 XmlLoadParam::~XmlLoadParam()38 {39 assert(this->object != NULL);40 41 (*this->executor)(this->object, this->loadElem);42 43 delete this->executor;44 } -
branches/new_class_id/src/lib/util/loading/load_param_xml.h
r9763 r9769 35 35 */ 36 36 #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 37 XmlLoadParam (ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false)37 XmlLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS, CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) 38 38 39 39 … … 47 47 */ 48 48 #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 49 XmlLoadParam (ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true)49 XmlLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS, CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) 50 50 51 51 //! A Class that can load XML tags onto an Object. 52 class XmlLoadParam : public LoadParamBase52 template <class BaseClass = BaseObject> class XmlLoadParam : public LoadParamBase 53 53 { 54 public: 55 XmlLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const TiXmlElement*>* executor, bool inLoadCycle = false); 56 virtual ~XmlLoadParam(); 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 */ 63 XmlLoadParam(const TiXmlElement* root, const std::string& paramName, BaseClass* 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 } 57 69 58 /** @param descriptionText the description @returns self @brief describes the Loading parameter. */ 59 XmlLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; }; 70 /** @brief executes and destroys the executor */ 71 virtual ~XmlLoadParam() 72 { 73 (*this->executor)(this->object, this->loadElem); 74 delete this->executor; 75 } 60 76 61 private: 62 Executor<const TiXmlElement*>* executor; //!< The Executor, that does the actual loading process. 77 /** @param descriptionText the description @returns self @brief describes the Loading parameter. */ 78 XmlLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; }; 79 80 private: 81 BaseClass* object; //!< The Object to apply this to. 82 Executor<const TiXmlElement*>* executor; //!< The Executor, that does the actual loading process. 63 83 }; 64 84
Note: See TracChangeset
for help on using the changeset viewer.