Changeset 5558 in orxonox.OLD for branches/world_entities/src/util/loading/load_param.cc
- Timestamp:
- Nov 13, 2005, 3:10:49 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/world_entities/src/util/loading/load_param.cc
r5334 r5558 17 17 18 18 #include "load_param.h" 19 #include "load_param_description.h" 19 20 20 21 #include "list.h" 21 #include "base_object.h"22 22 23 23 #include <stdarg.h> … … 31 31 * @param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...) 32 32 */ 33 BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,33 LoadParamBase::LoadParamBase(const TiXmlElement* root, BaseObject* object, const char* paramName, 34 34 int paramCount, bool multi, const void* pointerToParam, ...) 35 35 { … … 39 39 this->pointerToParam = pointerToParam; 40 40 41 if (paramCount == 0 || this->pointerToParam )41 if (paramCount == 0 || this->pointerToParam != NULL) 42 42 this->loadString = "none"; 43 43 else … … 110 110 * @returns a pointer to itself. 111 111 */ 112 BaseLoadParam* BaseLoadParam::describe(const char* descriptionText)112 LoadParamBase* LoadParamBase::describe(const char* descriptionText) 113 113 { 114 114 if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription()) … … 117 117 } 118 118 return this; 119 }120 121 /**122 * @param paramName the name of the parameter to load123 */124 LoadParamDescription::LoadParamDescription(const char* paramName)125 {126 this->types = NULL;127 this->description = NULL;128 this->defaultValues = NULL;129 this->paramName = new char[strlen(paramName)+1];130 strcpy(this->paramName, paramName);131 }132 133 /**134 * removes all the alocated memory135 */136 LoadParamDescription::~LoadParamDescription()137 {138 if (this->defaultValues != NULL)139 {140 for(int i = 0; i < this->paramCount; i++)141 {142 delete[] this->defaultValues[i];143 }144 }145 146 delete[] this->types;147 delete[] this->defaultValues;148 delete[] this->paramName;149 delete[] this->description;150 }151 152 /**153 * @param descriptionText The text to set as a description for this Parameter154 */155 void LoadParamDescription::setDescription(const char* descriptionText)156 {157 this->description = new char[strlen(descriptionText)+1];158 strcpy(this->description, descriptionText);159 }160 161 /**162 * prints out this parameter, its input method and the description (if availiable)163 */164 void LoadParamDescription::print() const165 {166 PRINT(3)(" <%s>", this->paramName);167 for (int i = 0; i < this->paramCount; i++)168 {169 if (i > 0)170 PRINT(3)(",");171 switch (this->types[i])172 {173 default:174 PRINTF(3)("none");175 break;176 case ParameterBool:177 PRINT(3)("bool");178 break;179 case ParameterChar:180 PRINT(3)("char");181 break;182 case ParameterString:183 PRINT(3)("string");184 break;185 case ParameterInt:186 PRINT(3)("int");187 break;188 case ParameterUInt:189 PRINT(3)("Uint");190 break;191 case ParameterFloat:192 PRINT(3)("float");193 break;194 case ParameterLong:195 PRINT(3)("long");196 break;197 case ParameterXML:198 PRINT(3)("XML");199 break;200 }201 }202 PRINT(3)("</%s>", this->paramName);203 if (this->description)204 PRINT(3)(" -- %s", this->description);205 // default values206 if (this->paramCount > 0)207 {208 PRINT(3)(" (Default: ");209 for (int i = 0; i < this->paramCount; i++)210 {211 if (i > 0)212 PRINT(3)(", ");213 if (this->types[i] & ParameterString)214 { // leave brackets !!215 PRINT(3)("\"%s\"", this->defaultValues[i]);216 }217 else218 {219 PRINT(3)("%s", this->defaultValues[i]);220 }221 }222 PRINT(3)(")");223 }224 PRINT(3)("\n");225 }226 227 /**228 * A list, that holds all the classes that are loadable (classes not objects!!)229 */230 tList<LoadClassDescription>* LoadClassDescription::classList = NULL;231 232 /**233 * if the description of Parameters should be executed234 */235 bool LoadClassDescription::parametersDescription = true;236 237 /**238 * @param className the name of the class to be loadable239 */240 LoadClassDescription::LoadClassDescription(const char* className)241 {242 this->className = new char[strlen(className)+1];243 strcpy(this->className, className);244 245 if (LoadClassDescription::classList == NULL)246 LoadClassDescription::classList = new tList<LoadClassDescription>;247 248 LoadClassDescription::classList->add(this);249 250 this->paramList = new tList<LoadParamDescription>;251 }252 253 /**254 * deletes a classDescription (deletes all the parameterDescriptions as well255 */256 LoadClassDescription::~LoadClassDescription()257 {258 tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();259 LoadParamDescription* enumParamDesc = iterator->firstElement();260 while (enumParamDesc)261 {262 delete enumParamDesc;263 enumParamDesc = iterator->nextElement();264 }265 delete iterator;266 delete this->paramList;267 268 delete[] this->className;269 }270 271 void LoadClassDescription::deleteAllDescriptions()272 {273 if (LoadClassDescription::classList != NULL)274 {275 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();276 LoadClassDescription* delElem = iterator->firstElement();277 while (delElem != NULL)278 {279 delete delElem;280 delElem = iterator->nextElement();281 }282 delete iterator;283 delete LoadClassDescription::classList;284 }285 LoadClassDescription::classList = NULL;286 }287 288 289 /**290 * adds a class to the list of loadable classes291 * @param className The name of the class to add292 293 this function searches for the className string, and if found just returns the appropriate Class.294 Otherwise it returns a new classDescription295 */296 LoadClassDescription* LoadClassDescription::addClass(const char* className)297 {298 if (LoadClassDescription::classList != NULL)299 {300 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();301 LoadClassDescription* enumClassDesc = iterator->firstElement();302 while (enumClassDesc)303 {304 if (!strcmp(enumClassDesc->className, className))305 {306 delete iterator;307 return enumClassDesc;308 }309 enumClassDesc = iterator->nextElement();310 }311 delete iterator;312 }313 return new LoadClassDescription(className);314 }315 316 /**317 * does the same as addClass(const char* className), but with params318 * @param paramName the name of the parameter to add.319 */320 LoadParamDescription* LoadClassDescription::addParam(const char* paramName)321 {322 tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();323 LoadParamDescription* enumParamDesc = iterator->firstElement();324 while (enumParamDesc)325 {326 if (!strcmp(enumParamDesc->paramName, paramName))327 {328 delete iterator;329 //return enumParamDesc;330 return NULL;331 }332 enumParamDesc = iterator->nextElement();333 }334 delete iterator;335 336 LoadParamDescription* newParam = new LoadParamDescription(paramName);337 338 this->paramList->add(newParam);339 return newParam;340 }341 342 /**343 * prints out all loadable Classes, and their parameters344 * @param fileName prints the output to a File345 * @todo implement it346 */347 void LoadClassDescription::printAll(const char* fileName)348 {349 PRINT(3)("===============================================================\n");350 PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");351 if (LoadClassDescription::classList != NULL)352 {353 tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator();354 LoadClassDescription* enumClassDesc = classIT->firstElement();355 while (enumClassDesc)356 {357 PRINT(3)("<%s>\n", enumClassDesc->className);358 tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator();359 LoadParamDescription* enumParamDesc = paramIT->firstElement();360 while (enumParamDesc)361 {362 enumParamDesc->print();363 enumParamDesc = paramIT->nextElement();364 }365 delete paramIT;366 367 PRINT(3)("</%s>\n\n", enumClassDesc->className);368 enumClassDesc = classIT->nextElement();369 }370 delete classIT;371 }372 else373 PRINT(3)("no Classes defined so far\n");374 PRINT(3)("===============================================================\n");375 }376 377 /**378 * searches for classes, which beginn with classNameBegin379 * @param classNameBegin the beginning string of a Class380 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,381 * !! The strings MUST NOT be deleted !!382 */383 tList<const char>* LoadClassDescription::searchClassWithShort(const char* classNameBegin)384 {385 unsigned int searchLength = strlen(classNameBegin);386 tList<const char>* retVal = new tList<const char>;387 388 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();389 LoadClassDescription* enumClassDesc = iterator->firstElement();390 while (enumClassDesc)391 {392 if (strlen(enumClassDesc->className)>searchLength+1 &&393 !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))394 {395 retVal->add(enumClassDesc->className);396 }397 enumClassDesc = iterator->nextElement();398 }399 delete iterator;400 401 return retVal;402 119 } 403 120
Note: See TracChangeset
for help on using the changeset viewer.