[4597] | 1 | /* |
---|
[4250] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
[4285] | 12 | main-programmer: Benjamin Grauer |
---|
[4250] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[5546] | 16 | #include "load_param_description.h" |
---|
[5556] | 17 | |
---|
[5691] | 18 | #include "multi_type.h" |
---|
[4254] | 19 | #include <stdarg.h> |
---|
[8362] | 20 | #include "debug.h" |
---|
| 21 | |
---|
[4860] | 22 | /** |
---|
[4836] | 23 | * @param paramName the name of the parameter to load |
---|
[5546] | 24 | */ |
---|
[7221] | 25 | LoadParamDescription::LoadParamDescription(const std::string& paramName) |
---|
[4254] | 26 | { |
---|
| 27 | this->types = NULL; |
---|
[5211] | 28 | this->defaultValues = NULL; |
---|
[7221] | 29 | this->paramName = paramName; |
---|
[4254] | 30 | } |
---|
| 31 | |
---|
[4256] | 32 | /** |
---|
[4836] | 33 | * removes all the alocated memory |
---|
[5546] | 34 | */ |
---|
[4746] | 35 | LoadParamDescription::~LoadParamDescription() |
---|
[4254] | 36 | { |
---|
[5099] | 37 | if (this->defaultValues != NULL) |
---|
[4623] | 38 | { |
---|
[5099] | 39 | for(int i = 0; i < this->paramCount; i++) |
---|
| 40 | { |
---|
[5218] | 41 | delete[] this->defaultValues[i]; |
---|
[5099] | 42 | } |
---|
[4623] | 43 | } |
---|
| 44 | |
---|
[5211] | 45 | delete[] this->types; |
---|
| 46 | delete[] this->defaultValues; |
---|
[4254] | 47 | } |
---|
| 48 | |
---|
[4256] | 49 | /** |
---|
[4836] | 50 | * @param descriptionText The text to set as a description for this Parameter |
---|
[5546] | 51 | */ |
---|
[7221] | 52 | void LoadParamDescription::setDescription(const std::string& descriptionText) |
---|
[4255] | 53 | { |
---|
[7221] | 54 | this->description = descriptionText; |
---|
[4255] | 55 | } |
---|
[4254] | 56 | |
---|
[4256] | 57 | /** |
---|
[4836] | 58 | * prints out this parameter, its input method and the description (if availiable) |
---|
[5546] | 59 | */ |
---|
[4746] | 60 | void LoadParamDescription::print() const |
---|
[4255] | 61 | { |
---|
[7221] | 62 | PRINT(3)(" <%s>", this->paramName.c_str()); |
---|
[4255] | 63 | for (int i = 0; i < this->paramCount; i++) |
---|
[5546] | 64 | { |
---|
| 65 | if (i > 0) |
---|
| 66 | PRINT(3)(","); |
---|
[5634] | 67 | // FIXME |
---|
| 68 | // switch (this->types[i]) |
---|
| 69 | // { |
---|
| 70 | // default: |
---|
| 71 | // PRINTF(3)("none"); |
---|
| 72 | // break; |
---|
| 73 | // case ParameterBool: |
---|
| 74 | // PRINT(3)("bool"); |
---|
| 75 | // break; |
---|
| 76 | // case ParameterChar: |
---|
| 77 | // PRINT(3)("char"); |
---|
| 78 | // break; |
---|
| 79 | // case ParameterString: |
---|
| 80 | // PRINT(3)("string"); |
---|
| 81 | // break; |
---|
| 82 | // case ParameterInt: |
---|
| 83 | // PRINT(3)("int"); |
---|
| 84 | // break; |
---|
| 85 | // case ParameterUInt: |
---|
| 86 | // PRINT(3)("Uint"); |
---|
| 87 | // break; |
---|
| 88 | // case ParameterFloat: |
---|
| 89 | // PRINT(3)("float"); |
---|
| 90 | // break; |
---|
| 91 | // case ParameterLong: |
---|
| 92 | // PRINT(3)("long"); |
---|
| 93 | // break; |
---|
| 94 | // case ParameterXML: |
---|
| 95 | // PRINT(3)("XML"); |
---|
| 96 | // break; |
---|
| 97 | // } |
---|
[5546] | 98 | } |
---|
[7221] | 99 | PRINT(3)("</%s>", this->paramName.c_str()); |
---|
| 100 | if (!this->description.empty()) |
---|
| 101 | PRINT(3)(" -- %s", this->description.c_str()); |
---|
[4623] | 102 | // default values |
---|
| 103 | if (this->paramCount > 0) |
---|
| 104 | { |
---|
[4637] | 105 | PRINT(3)(" (Default: "); |
---|
[4623] | 106 | for (int i = 0; i < this->paramCount; i++) |
---|
| 107 | { |
---|
| 108 | if (i > 0) |
---|
| 109 | PRINT(3)(", "); |
---|
[5634] | 110 | if (this->types[i] & MT_STRING) |
---|
[4625] | 111 | { // leave brackets !! |
---|
| 112 | PRINT(3)("\"%s\"", this->defaultValues[i]); |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | { |
---|
| 116 | PRINT(3)("%s", this->defaultValues[i]); |
---|
| 117 | } |
---|
[4623] | 118 | } |
---|
| 119 | PRINT(3)(")"); |
---|
| 120 | } |
---|
[4255] | 121 | PRINT(3)("\n"); |
---|
| 122 | } |
---|
| 123 | |
---|
[4256] | 124 | /** |
---|
[4836] | 125 | * A list, that holds all the classes that are loadable (classes not objects!!) |
---|
[5546] | 126 | */ |
---|
[7130] | 127 | std::list<LoadClassDescription*>* LoadClassDescription::classList = NULL; |
---|
[4254] | 128 | |
---|
[4251] | 129 | /** |
---|
[4836] | 130 | * if the description of Parameters should be executed |
---|
[5546] | 131 | */ |
---|
[5534] | 132 | bool LoadClassDescription::parametersDescription = false; |
---|
[4254] | 133 | |
---|
[4256] | 134 | /** |
---|
[4836] | 135 | * @param className the name of the class to be loadable |
---|
[5546] | 136 | */ |
---|
[7221] | 137 | LoadClassDescription::LoadClassDescription(const std::string& className) |
---|
[4254] | 138 | { |
---|
[7221] | 139 | this->className = className; |
---|
[4254] | 140 | |
---|
[5226] | 141 | if (LoadClassDescription::classList == NULL) |
---|
[7130] | 142 | LoadClassDescription::classList = new std::list<LoadClassDescription*>; |
---|
[4254] | 143 | |
---|
[7130] | 144 | LoadClassDescription::classList->push_back(this); |
---|
[4254] | 145 | } |
---|
| 146 | |
---|
[4256] | 147 | /** |
---|
[4836] | 148 | * deletes a classDescription (deletes all the parameterDescriptions as well |
---|
[5546] | 149 | */ |
---|
[4746] | 150 | LoadClassDescription::~LoadClassDescription() |
---|
[4254] | 151 | { |
---|
[7130] | 152 | std::list<LoadParamDescription*>::iterator it = this->paramList.begin(); |
---|
| 153 | while (!this->paramList.empty()) |
---|
[5546] | 154 | { |
---|
[7130] | 155 | delete this->paramList.front(); |
---|
| 156 | this->paramList.pop_front(); |
---|
[5546] | 157 | } |
---|
[4254] | 158 | } |
---|
| 159 | |
---|
[5226] | 160 | void LoadClassDescription::deleteAllDescriptions() |
---|
| 161 | { |
---|
| 162 | if (LoadClassDescription::classList != NULL) |
---|
| 163 | { |
---|
[7130] | 164 | while (!LoadClassDescription::classList->empty()) |
---|
[5226] | 165 | { |
---|
[7130] | 166 | delete LoadClassDescription::classList->front(); |
---|
| 167 | LoadClassDescription::classList->pop_front(); |
---|
[5226] | 168 | } |
---|
| 169 | delete LoadClassDescription::classList; |
---|
| 170 | } |
---|
| 171 | LoadClassDescription::classList = NULL; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | |
---|
[4256] | 175 | /** |
---|
[4836] | 176 | * adds a class to the list of loadable classes |
---|
| 177 | * @param className The name of the class to add |
---|
[4254] | 178 | |
---|
[4256] | 179 | this function searches for the className string, and if found just returns the appropriate Class. |
---|
| 180 | Otherwise it returns a new classDescription |
---|
[5546] | 181 | */ |
---|
[7221] | 182 | LoadClassDescription* LoadClassDescription::addClass(const std::string& className) |
---|
[4254] | 183 | { |
---|
[5226] | 184 | if (LoadClassDescription::classList != NULL) |
---|
| 185 | { |
---|
[7130] | 186 | std::list<LoadClassDescription*>::iterator it = LoadClassDescription::classList->begin(); |
---|
| 187 | while (it != LoadClassDescription::classList->end()) |
---|
[5546] | 188 | { |
---|
[7221] | 189 | if ((*it)->className == className) |
---|
[5546] | 190 | { |
---|
[7130] | 191 | return (*it); |
---|
[5546] | 192 | } |
---|
[7130] | 193 | it++; |
---|
[5546] | 194 | } |
---|
[5226] | 195 | } |
---|
[4254] | 196 | return new LoadClassDescription(className); |
---|
| 197 | } |
---|
| 198 | |
---|
[4256] | 199 | /** |
---|
[7221] | 200 | * does the same as addClass(const std::string& className), but with params |
---|
[4836] | 201 | * @param paramName the name of the parameter to add. |
---|
[5546] | 202 | */ |
---|
[7221] | 203 | LoadParamDescription* LoadClassDescription::addParam(const std::string& paramName) |
---|
[4254] | 204 | { |
---|
[7130] | 205 | std::list<LoadParamDescription*>::iterator it = this->paramList.begin(); |
---|
| 206 | while (it != this->paramList.end()) |
---|
[5546] | 207 | { |
---|
[7221] | 208 | if ((*it)->paramName == paramName) |
---|
[4254] | 209 | { |
---|
[5546] | 210 | return NULL; |
---|
[4254] | 211 | } |
---|
[7130] | 212 | it++; |
---|
[5546] | 213 | } |
---|
[4254] | 214 | |
---|
[5227] | 215 | LoadParamDescription* newParam = new LoadParamDescription(paramName); |
---|
| 216 | |
---|
[7130] | 217 | this->paramList.push_back(newParam); |
---|
[5227] | 218 | return newParam; |
---|
[4254] | 219 | } |
---|
[4255] | 220 | |
---|
[4256] | 221 | /** |
---|
[4836] | 222 | * prints out all loadable Classes, and their parameters |
---|
[5100] | 223 | * @param fileName prints the output to a File |
---|
| 224 | * @todo implement it |
---|
[5546] | 225 | */ |
---|
[7221] | 226 | void LoadClassDescription::printAll(const std::string& fileName) |
---|
[4255] | 227 | { |
---|
[4259] | 228 | PRINT(3)("===============================================================\n"); |
---|
| 229 | PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n"); |
---|
[5226] | 230 | if (LoadClassDescription::classList != NULL) |
---|
| 231 | { |
---|
[7130] | 232 | std::list<LoadClassDescription*>::iterator classDesc = LoadClassDescription::classList->begin(); |
---|
| 233 | while (classDesc != LoadClassDescription::classList->end()) |
---|
[5546] | 234 | { |
---|
[7221] | 235 | PRINT(3)("<%s>\n", (*classDesc)->className.c_str()); |
---|
[7130] | 236 | std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin(); |
---|
| 237 | while (param != (*classDesc)->paramList.end()) |
---|
[5546] | 238 | { |
---|
[7130] | 239 | (*param)->print(); |
---|
| 240 | param++; |
---|
[5546] | 241 | } |
---|
[7221] | 242 | PRINT(3)("</%s>\n\n", (*classDesc)->className.c_str()); |
---|
[7130] | 243 | classDesc++; |
---|
[5546] | 244 | } |
---|
[5226] | 245 | } |
---|
| 246 | else |
---|
| 247 | PRINT(3)("no Classes defined so far\n"); |
---|
[4259] | 248 | PRINT(3)("===============================================================\n"); |
---|
[4255] | 249 | } |
---|
[4492] | 250 | |
---|
[5100] | 251 | /** |
---|
| 252 | * searches for classes, which beginn with classNameBegin |
---|
| 253 | * @param classNameBegin the beginning string of a Class |
---|
[5113] | 254 | * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards, |
---|
[5100] | 255 | * !! The strings MUST NOT be deleted !! |
---|
| 256 | */ |
---|
[7221] | 257 | std::list<std::string> LoadClassDescription::searchClassWithShort(const std::string& classNameBegin) |
---|
[5100] | 258 | { |
---|
[7130] | 259 | /// FIXME |
---|
| 260 | // NOT USED |
---|
| 261 | /* unsigned int searchLength = strlen(classNameBegin); |
---|
[7221] | 262 | std::list<const std::string&> retVal; |
---|
[4492] | 263 | |
---|
[5100] | 264 | tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator(); |
---|
[5115] | 265 | LoadClassDescription* enumClassDesc = iterator->firstElement(); |
---|
[5100] | 266 | while (enumClassDesc) |
---|
| 267 | { |
---|
| 268 | if (strlen(enumClassDesc->className)>searchLength+1 && |
---|
| 269 | !strncasecmp(enumClassDesc->className, classNameBegin, searchLength)) |
---|
| 270 | { |
---|
[5113] | 271 | retVal->add(enumClassDesc->className); |
---|
[5100] | 272 | } |
---|
| 273 | enumClassDesc = iterator->nextElement(); |
---|
| 274 | } |
---|
| 275 | delete iterator; |
---|
[4492] | 276 | |
---|
[7130] | 277 | return retVal;*/ |
---|
[8316] | 278 | std::list<std::string> a; |
---|
| 279 | return a; |
---|
[5100] | 280 | } |
---|