Changeset 9727 in orxonox.OLD for branches/new_class_id/src/lib/util/loading
- Timestamp:
- Sep 14, 2006, 5:24:31 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util/loading
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/game_loader.cc
r9715 r9727 21 21 #include "util/loading/load_param.h" 22 22 23 #include "debug.h" 23 24 #include "shell_command.h" 24 25 #include "campaign.h" -
branches/new_class_id/src/lib/util/loading/load_param.cc
r9406 r9727 18 18 #include "util/loading/load_param.h" 19 19 #include "load_param_description.h" 20 21 #include <stdarg.h> 22 20 #include "compiler.h" 21 #include "debug.h" 23 22 /** 24 23 * Constructs a new LoadParameter … … 28 27 * @param executor the Executor, that executes the loading procedure. 29 28 */ 30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle) 31 : object(object), paramName(paramName) 32 { 33 this->inLoadCycle = inLoadCycle; 34 29 LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object, bool inLoadCycle) 30 : object(object), paramName(paramName), inLoadCycle(inLoadCycle) 31 { 35 32 // determin the LoadString. 36 33 if (likely(!inLoadCycle)) … … 40 37 else 41 38 this->loadElem = NULL; 42 39 } 40 41 42 /** 43 * @param descriptionText The text to set as a description for this Parameter 44 * @returns a pointer to itself. 45 */ 46 void LoadParamBase::describe(const std::string& descriptionText) 47 { 48 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) 49 { 50 this->paramDesc->setDescription(descriptionText); 51 } 52 } 53 54 55 56 57 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const SubString>* executor, bool inLoadCycle) 58 : LoadParamBase(root, paramName, object, inLoadCycle) 59 { 60 assert (executor != NULL); 43 61 // set the Executor. 44 62 this->executor = executor; 45 46 63 //if (this->executor) 47 64 // this->executor->setName(paramName); … … 56 73 CLoadParam::~CLoadParam() 57 74 { 58 if (likely(this->executor != NULL)) 59 { 60 std::string loadString = ""; 61 if (this->loadElem != NULL && this->loadElem->ToText()) 62 loadString = this->loadElem->Value(); 63 if (likely(this->object != NULL) && 64 ( !loadString.empty() || 65 ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString))) 75 assert(this->object != NULL); 76 77 std::string loadString; 78 if (this->loadElem != NULL && this->loadElem->ToText()) 79 { 80 loadString = this->loadElem->Value(); 81 if (!loadString.empty()) 66 82 { 67 PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName()); 83 PRINTF(0)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", 84 this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName()); 68 85 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\')); 69 86 } 70 delete this->executor;71 }87 } 88 delete this->executor; 72 89 } 73 90 … … 90 107 } 91 108 92 93 94 /**95 * @param descriptionText The text to set as a description for this Parameter96 * @returns a pointer to itself.97 */98 CLoadParam& CLoadParam::describe(const std::string& descriptionText)99 {100 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty())101 {102 this->paramDesc->setDescription(descriptionText);103 }104 return *this;105 }106 109 107 110 // const LoadParamDescription* LoadParamDescription::getClass(const char* className) -
branches/new_class_id/src/lib/util/loading/load_param.h
r8048 r9727 25 25 26 26 #include "executor/executor.h" 27 #include " executor/executor_xml.h"27 #include "parser/tinyxml/tinyxml.h" 28 28 29 29 // Forward Declaration // 30 30 class LoadClassDescription; 31 31 class LoadParamDescription; 32 class MultiType;33 34 32 35 33 /** … … 47 45 #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 48 46 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 47 57 48 /** … … 78 69 } 79 70 71 80 72 /************************** 81 73 **** REAL DECLARATIONS **** 82 74 **************************/ 83 //! abstract Base class for a Loadable parameter 84 class CLoadParam : public BaseObject 75 class LoadParamBase : public BaseObject 85 76 { 86 public: 87 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false); 88 virtual ~CLoadParam(); 77 protected: 78 LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object, bool inLoadCycle = false); 89 79 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); 80 protected: 81 void describe(const std::string& descriptionText); 82 83 protected: 84 BaseObject* object; 85 const std::string paramName; 86 bool inLoadCycle; 87 88 LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter 89 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 90 const TiXmlElement* loadElem; //!< The Element to load. 91 }; 95 92 96 93 97 private: 98 bool inLoadCycle; 99 Executor* executor; 100 BaseObject* object; 101 const std::string paramName; 94 //! abstract Base class for a Loadable parameter 95 class CLoadParam : public LoadParamBase 96 { 97 public: 98 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const SubString>* executor, bool inLoadCycle = false); 99 virtual ~CLoadParam(); 102 100 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. 101 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 102 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 103 const MultiType& value4 = MT_NULL); 104 CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; }; 105 // CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor); 107 106 108 MultiType* defaultValue; 107 108 private: 109 Executor<const SubString>* executor; 109 110 }; 110 111 -
branches/new_class_id/src/lib/util/loading/load_param_description.h
r7221 r9727 57 57 class LoadClassDescription 58 58 { 59 friend class CLoadParam;59 friend class LoadParamBase; 60 60 public: 61 61 LoadClassDescription(const std::string& className); -
branches/new_class_id/src/lib/util/loading/load_param_xml.cc
r9726 r9727 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING 17 17 18 #include "util/loading/load_param .h"18 #include "util/loading/load_param_xml.h" 19 19 #include "load_param_description.h" 20 20 21 #include <stdarg.h> 22 23 /** 24 * Constructs a new LoadParameter 25 * @param root the XML-element to load this Parameter from 26 * @param paramName the Parameter to load 27 * @param object the BaseObject, to load this parameter on to (will be cast to executor's Parameter) 28 * @param executor the Executor, that executes the loading procedure. 29 */ 30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle) 31 : object(object), paramName(paramName) 21 XmlLoadParam::XmlLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const TiXmlElement*>* executor, bool inLoadCycle ) 22 : LoadParamBase(root, paramName, object, inLoadCycle) 32 23 { 33 this->inLoadCycle = inLoadCycle;34 35 // determin the LoadString.36 if (likely(!inLoadCycle))37 this->loadElem = grabParameterElement(root, paramName);38 else if (paramName == root->Value())39 this->loadElem = (TiXmlElement*)root->FirstChild();40 else41 this->loadElem = NULL;42 43 // set the Executor.44 24 this->executor = executor; 45 46 //if (this->executor)47 // this->executor->setName(paramName);48 }49 50 /**51 * This is a VERY SPECIAL deconsrtuctor.52 * It is made, so that it loads the Parameters on destruction.53 * meaning, if an Executor a valid Object exist, and all54 * Execution-Conditions are met, they are executed here.55 */56 CLoadParam::~CLoadParam()57 {58 if (likely(this->executor != NULL))59 {60 std::string loadString = "";61 if (this->loadElem != NULL && this->loadElem->ToText())62 loadString = this->loadElem->Value();63 if (likely(this->object != NULL) &&64 ( !loadString.empty() ||65 ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString)))66 {67 PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName());68 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\'));69 }70 delete this->executor;71 }72 }73 74 /**75 * @brief set the default values of the executor76 * @param value0 the first default value77 * @param value1 the second default value78 * @param value2 the third default value79 * @param value3 the fourth default value80 * @param value4 the fifth default value81 */82 CLoadParam& CLoadParam::defaultValues(const MultiType& value0, const MultiType& value1,83 const MultiType& value2, const MultiType& value3,84 const MultiType& value4)85 {86 assert(this->executor != NULL);87 this->executor->defaultValues(value0, value1, value2, value3, value4);88 89 return *this;90 25 } 91 26 92 27 28 XmlLoadParam::~XmlLoadParam() 29 { 30 assert(this->object != NULL); 93 31 94 /** 95 * @param descriptionText The text to set as a description for this Parameter 96 * @returns a pointer to itself. 97 */ 98 CLoadParam& CLoadParam::describe(const std::string& descriptionText) 99 { 100 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) 101 { 102 this->paramDesc->setDescription(descriptionText); 103 } 104 return *this; 32 (*this->executor)(this->object, this->loadElem); 33 34 delete this->executor; 105 35 } 106 107 // const LoadParamDescription* LoadParamDescription::getClass(const char* className)108 // {109 // tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();110 // LoadClassDescription* enumClassDesc = iterator->firstElement();111 // while (enumClassDesc)112 // {113 // if (!strcmp(enumClassDesc->className, classNameBegin, className))114 // {115 // delete iterator;116 // return enumClassDesc;117 // }118 // enumClassDesc = iterator->nextElement();119 // }120 // delete iterator;121 //122 // return NULL;123 // }124 125 126 127 128 /*129 * @param object The object this Parameter is loaded too.130 * @param root: the XML-element to load this option from.131 * @param paramName: The name of the parameter loaded.132 * @param paramCount: how many parameters this loading-function takes133 * @param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences.134 * @param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...)135 */136 /*LoadParam::LoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,137 int paramCount, bool multi, const void* pointerToParam, ...)138 {139 this->setClassID(CL_LOAD_PARAM, "LoadParam");140 this->executor = NULL;141 142 this->loadString = NULL;143 this->pointerToParam = pointerToParam;144 145 if (paramCount == 0 || this->pointerToParam != NULL)146 this->loadString = "none";147 else148 {149 if (likely(!multi))150 this->loadString = grabParameter(root, paramName);151 else152 {153 if (!strcmp(root->Value(), paramName))154 {155 const TiXmlNode* val = root->FirstChild();156 if( val->ToText())157 this->loadString = val->Value();158 }159 }160 }161 162 this->paramDesc = NULL;163 if (LoadClassDescription::parametersDescription)164 {165 // locating the class166 this->classDesc = LoadClassDescription::addClass(object->getClassCName());167 168 if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL)169 {170 171 this->paramDesc->paramCount = paramCount;172 this->paramDesc->types = new int[paramCount];173 this->paramDesc->defaultValues = new char*[paramCount];174 175 va_list types;176 va_start (types, pointerToParam);177 char defaultVal[512];178 for(int i = 0; i < paramCount; i++)179 {180 defaultVal[0] = '\0';181 // parameters parsed182 int tmpType = va_arg (types, int);183 this->paramDesc->types[i] = tmpType;184 switch (tmpType)185 {186 case MT_INT:187 sprintf(defaultVal, "%d", va_arg(types, int));188 break;189 // case MT_LONG:190 // sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE));191 // break;192 case MT_FLOAT:193 sprintf(defaultVal, "%0.3f", va_arg(types, double));194 break;195 case MT_STRING:196 sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE));197 break;198 case MT_EXT1:199 sprintf(defaultVal, "");200 break;201 }202 this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1];203 strcpy(this->paramDesc->defaultValues[i], defaultVal);204 }205 va_end(types);206 207 int argCount = 0;208 }209 }210 }*/211 212 213 214 215 216 217 218 219 220 221 //////////////////////222 // HELPER FUNCTIONS //223 //////////////////////224 /**225 * @param root: The XML-element to grab a parameter from226 * @param parameterName: the parameter to grab227 * @returns the Value of the parameter if found, NULL otherwise228 */229 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName)230 {231 const TiXmlElement* element;232 const TiXmlNode* node;233 234 if (root == NULL)235 return "";236 237 element = root->FirstChildElement( parameterName);238 if( element == NULL) return "";239 240 node = element->FirstChild();241 while( node != NULL)242 {243 if( node->ToText()) return node->Value();244 node = node->NextSibling();245 }246 return "";247 }248 249 /**250 * @param root: The XML-element to grab a parameter from251 * @param parameterName: the parameter to grab252 * @returns the Element of the parameter if found, NULL otherwise253 */254 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName)255 {256 const TiXmlElement* element;257 const TiXmlNode* node;258 259 if (root == NULL)260 return NULL;261 262 element = root->FirstChildElement( parameterName);263 if( element == NULL) return NULL;264 265 node = element->FirstChild();266 while( node != NULL)267 {268 if( node->ToText()) return (TiXmlElement*)node;269 node = node->NextSibling();270 }271 return NULL;272 }273 274 275 -
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.