Changeset 9869 in orxonox.OLD for trunk/src/lib/util/loading/load_param.cc
- 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.cc
r9406 r9869 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING 17 17 18 #include "util/loading/load_param.h" 19 #include "load_param_description.h" 20 21 #include <stdarg.h> 22 18 #include "load_param.h" 19 #include "load_param_class_description.h" 20 #include "compiler.h" 21 #include "debug.h" 23 22 /** 24 * Constructs a new LoadParameter23 * @brief Constructs a new LoadParameter 25 24 * @param root the XML-element to load this Parameter from 26 25 * @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. 26 * @param inLoadCycle If we are in a LoadCycle (loading differs.). 29 27 */ 30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle)31 : object(object), paramName(paramName)28 LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle) 29 : paramName(paramName), inLoadCycle(inLoadCycle) 32 30 { 33 this->inLoadCycle = inLoadCycle;34 35 31 // determin the LoadString. 36 32 if (likely(!inLoadCycle)) … … 40 36 else 41 37 this->loadElem = NULL; 38 } 42 39 43 // set the Executor.44 this->executor = executor;45 40 46 //if (this->executor) 47 // this->executor->setName(paramName); 41 /** 42 * @param classID the ID of the class. This is needed to identify into what class this Parameter belongs. 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 ClassID& classID, const std::string& descriptionText) 47 { 48 PRINTF(5)("Describing Class '%s'(id:%d) Parameter '%s': description '%s'\n", 49 classID.name().c_str(), classID.id(), paramName.c_str(), descriptionText.c_str()); 50 51 if (LoadParamClassDescription::descriptionsCaptured()) 52 LoadParamClassDescription::describeClass(classID, paramName, descriptionText); 48 53 } 49 54 50 55 /** 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 all 54 * Execution-Conditions are met, they are executed here. 56 * @brief sets the Values of the Description to a usefull text. 55 57 */ 56 CLoadParam::~CLoadParam()58 void LoadParamBase::setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal) 57 59 { 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 } 60 if(LoadParamClassDescription::descriptionsCaptured()) 61 LoadParamClassDescription::setValuesOf(classID, paramName, paramCount, defaultValues, retVal); 72 62 } 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 }91 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 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 63 220 64 … … 227 71 * @returns the Value of the parameter if found, NULL otherwise 228 72 */ 229 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName)73 std::string LoadParamBase::grabParameter(const TiXmlElement* root, const std::string& parameterName) 230 74 { 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) 75 const TiXmlElement* const element = grabParameterElement(root, parameterName); 76 if (element != NULL) 77 return element->Value(); 78 else 242 79 { 243 if( node->ToText()) return node->Value();244 node = node->NextSibling();80 static std::string empty(""); 81 return empty; 245 82 } 246 return "";247 83 } 248 84 … … 252 88 * @returns the Element of the parameter if found, NULL otherwise 253 89 */ 254 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName)90 const TiXmlElement* LoadParamBase::grabParameterElement(const TiXmlElement* root, const std::string& parameterName) 255 91 { 256 92 const TiXmlElement* element; … … 271 107 return NULL; 272 108 } 273 274 275
Note: See TracChangeset
for help on using the changeset viewer.