[4250] | 1 | /* |
---|
| 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: |
---|
| 12 | main-programmer: Christian Meyer |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "load_param.h" |
---|
| 17 | |
---|
[4254] | 18 | #include "list.h" |
---|
| 19 | #include "base_object.h" |
---|
[4250] | 20 | |
---|
[4254] | 21 | #include <stdarg.h> |
---|
| 22 | |
---|
[4256] | 23 | /** |
---|
| 24 | \param object The object this Parameter is loaded too. |
---|
| 25 | \param paramName The name of the parameter loaded. |
---|
| 26 | \param paramCount how many parameters this loading-function takes |
---|
| 27 | \param ... the parameter information |
---|
| 28 | */ |
---|
[4254] | 29 | BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...) |
---|
[4251] | 30 | { |
---|
[4255] | 31 | this->paramDesc = NULL; |
---|
[4254] | 32 | if (LoadClassDescription::parametersDescription) |
---|
| 33 | { |
---|
| 34 | // locating the class |
---|
| 35 | this->classDesc = LoadClassDescription::addClass(object->getClassName()); |
---|
| 36 | this->paramDesc = this->classDesc->addParam(paramName); |
---|
| 37 | |
---|
| 38 | this->paramDesc->types = new char*[paramCount]; |
---|
| 39 | this->paramDesc->paramCount = paramCount; |
---|
| 40 | |
---|
| 41 | va_list types; |
---|
| 42 | va_start (types, paramCount); |
---|
| 43 | for(int i = 0; i < paramCount; i++) |
---|
| 44 | { |
---|
| 45 | const char* tmpTypeName = va_arg (types, const char*); |
---|
| 46 | this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; |
---|
| 47 | strcpy(this->paramDesc->types[i], tmpTypeName); |
---|
| 48 | } |
---|
| 49 | va_end(types); |
---|
| 50 | |
---|
| 51 | int argCount = 0; |
---|
| 52 | } |
---|
[4251] | 53 | } |
---|
[4250] | 54 | |
---|
[4256] | 55 | /** |
---|
| 56 | \param descriptionText The text to set as a description for this Parameter |
---|
[4260] | 57 | \returns a pointer to itself. |
---|
[4256] | 58 | */ |
---|
[4260] | 59 | BaseLoadParam* BaseLoadParam::describe(const char* descriptionText) |
---|
[4254] | 60 | { |
---|
[4255] | 61 | if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription()) |
---|
[4254] | 62 | { |
---|
[4255] | 63 | this->paramDesc->setDescription(descriptionText); |
---|
[4254] | 64 | } |
---|
[4260] | 65 | return this; |
---|
[4254] | 66 | } |
---|
| 67 | |
---|
[4256] | 68 | /** |
---|
| 69 | \param paramName the name of the parameter to load |
---|
| 70 | */ |
---|
[4254] | 71 | LoadParamDescription::LoadParamDescription(const char* paramName) |
---|
| 72 | { |
---|
| 73 | this->types = NULL; |
---|
[4255] | 74 | this->description = NULL; |
---|
[4254] | 75 | this->paramName = new char[strlen(paramName)+1]; |
---|
| 76 | strcpy(this->paramName, paramName); |
---|
| 77 | } |
---|
| 78 | |
---|
[4256] | 79 | /** |
---|
| 80 | \brief removes all the alocated memory |
---|
| 81 | */ |
---|
[4254] | 82 | LoadParamDescription::~LoadParamDescription(void) |
---|
| 83 | { |
---|
| 84 | for(int i = 0; i < this->paramCount; i++) |
---|
| 85 | { |
---|
| 86 | delete this->types[i]; |
---|
| 87 | } |
---|
| 88 | delete []this->types; |
---|
| 89 | delete []this->paramName; |
---|
[4256] | 90 | delete []this->description; |
---|
[4254] | 91 | } |
---|
| 92 | |
---|
[4256] | 93 | /** |
---|
| 94 | \param descriptionText The text to set as a description for this Parameter |
---|
| 95 | */ |
---|
[4255] | 96 | void LoadParamDescription::setDescription(const char* descriptionText) |
---|
| 97 | { |
---|
[4256] | 98 | this->description = new char[strlen(descriptionText)+1]; |
---|
| 99 | strcpy(this->description, descriptionText); |
---|
[4255] | 100 | } |
---|
[4254] | 101 | |
---|
[4256] | 102 | /** |
---|
| 103 | \brief prints out this parameter, its input method and the description (if availiable) |
---|
| 104 | */ |
---|
[4255] | 105 | void LoadParamDescription::print(void) const |
---|
| 106 | { |
---|
| 107 | PRINT(3)(" <%s>", this->paramName); |
---|
| 108 | for (int i = 0; i < this->paramCount; i++) |
---|
| 109 | { |
---|
| 110 | if (i > 0) |
---|
| 111 | PRINT(3)(","); |
---|
| 112 | PRINT(3)("%s", this->types[i]); |
---|
| 113 | } |
---|
| 114 | PRINT(3)("</%s>", this->paramName); |
---|
| 115 | if (this->description) |
---|
| 116 | PRINT(3)(" -- %s", this->description); |
---|
| 117 | PRINT(3)("\n"); |
---|
| 118 | } |
---|
| 119 | |
---|
[4256] | 120 | /** |
---|
| 121 | \brief A list, that holds all the classes that are loadable (classes not objects!!) |
---|
| 122 | */ |
---|
[4254] | 123 | tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>; |
---|
| 124 | |
---|
[4251] | 125 | /** |
---|
| 126 | \brief if the description of Parameters should be executed |
---|
| 127 | */ |
---|
[4254] | 128 | bool LoadClassDescription::parametersDescription = true; |
---|
| 129 | |
---|
[4256] | 130 | /** |
---|
| 131 | \param className the name of the class to be loadable |
---|
| 132 | */ |
---|
[4254] | 133 | LoadClassDescription::LoadClassDescription(const char* className) |
---|
| 134 | { |
---|
| 135 | this->className = new char[strlen(className)+1]; |
---|
| 136 | strcpy(this->className, className); |
---|
| 137 | |
---|
| 138 | classList->add(this); |
---|
| 139 | |
---|
| 140 | this->paramList = new tList<LoadParamDescription>; |
---|
| 141 | } |
---|
| 142 | |
---|
[4256] | 143 | /** |
---|
| 144 | \brief deletes a classDescription (deletes all the parameterDescriptions as well |
---|
| 145 | */ |
---|
[4254] | 146 | LoadClassDescription::~LoadClassDescription(void) |
---|
| 147 | { |
---|
| 148 | delete []this->className; |
---|
| 149 | |
---|
| 150 | tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); |
---|
| 151 | LoadParamDescription* enumParamDesc = iterator->nextElement(); |
---|
| 152 | while (enumParamDesc) |
---|
| 153 | { |
---|
| 154 | delete enumParamDesc; |
---|
| 155 | enumParamDesc = iterator->nextElement(); |
---|
| 156 | } |
---|
| 157 | delete iterator; |
---|
| 158 | } |
---|
| 159 | |
---|
[4256] | 160 | /** |
---|
| 161 | \brief adds a class to the list of loadable classes |
---|
| 162 | \param className The name of the class to add |
---|
[4254] | 163 | |
---|
[4256] | 164 | this function searches for the className string, and if found just returns the appropriate Class. |
---|
| 165 | Otherwise it returns a new classDescription |
---|
| 166 | */ |
---|
[4254] | 167 | LoadClassDescription* LoadClassDescription::addClass(const char* className) |
---|
| 168 | { |
---|
| 169 | tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator(); |
---|
| 170 | LoadClassDescription* enumClassDesc = iterator->nextElement(); |
---|
| 171 | while (enumClassDesc) |
---|
| 172 | { |
---|
| 173 | if (!strcmp(enumClassDesc->className, className)) |
---|
| 174 | { |
---|
| 175 | delete iterator; |
---|
| 176 | return enumClassDesc; |
---|
| 177 | } |
---|
| 178 | enumClassDesc = iterator->nextElement(); |
---|
| 179 | } |
---|
| 180 | delete iterator; |
---|
| 181 | |
---|
| 182 | return new LoadClassDescription(className); |
---|
| 183 | } |
---|
| 184 | |
---|
[4256] | 185 | /** |
---|
| 186 | \brief does the same as addClass(const char* className), but with params |
---|
| 187 | \param paramName the name of the parameter to add. |
---|
| 188 | */ |
---|
[4254] | 189 | LoadParamDescription* LoadClassDescription::addParam(const char* paramName) |
---|
| 190 | { |
---|
| 191 | tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); |
---|
| 192 | LoadParamDescription* enumParamDesc = iterator->nextElement(); |
---|
| 193 | while (enumParamDesc) |
---|
| 194 | { |
---|
| 195 | if (!strcmp(enumParamDesc->paramName, paramName)) |
---|
| 196 | { |
---|
| 197 | delete iterator; |
---|
| 198 | return enumParamDesc; |
---|
| 199 | } |
---|
| 200 | enumParamDesc = iterator->nextElement(); |
---|
| 201 | } |
---|
| 202 | delete iterator; |
---|
| 203 | |
---|
| 204 | this->paramList->add(new LoadParamDescription(paramName)); |
---|
| 205 | return paramList->lastElement(); |
---|
| 206 | } |
---|
[4255] | 207 | |
---|
[4256] | 208 | /** |
---|
| 209 | \brief prints out all loadable Classes, and their parameters |
---|
| 210 | */ |
---|
[4260] | 211 | void LoadClassDescription::printAll(const char* fileName) |
---|
[4255] | 212 | { |
---|
[4259] | 213 | PRINT(3)("===============================================================\n"); |
---|
| 214 | PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n"); |
---|
[4255] | 215 | tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator(); |
---|
| 216 | LoadClassDescription* enumClassDesc = classIT->nextElement(); |
---|
| 217 | while (enumClassDesc) |
---|
| 218 | { |
---|
| 219 | PRINT(3)("<%s>\n", enumClassDesc->className); |
---|
| 220 | tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator(); |
---|
| 221 | LoadParamDescription* enumParamDesc = paramIT->nextElement(); |
---|
| 222 | while (enumParamDesc) |
---|
| 223 | { |
---|
| 224 | enumParamDesc->print(); |
---|
| 225 | enumParamDesc = paramIT->nextElement(); |
---|
| 226 | } |
---|
| 227 | delete paramIT; |
---|
| 228 | |
---|
| 229 | PRINT(3)("</%s>\n\n", enumClassDesc->className); |
---|
| 230 | enumClassDesc = classIT->nextElement(); |
---|
| 231 | } |
---|
| 232 | delete classIT; |
---|
[4259] | 233 | PRINT(3)("===============================================================\n"); |
---|
[4255] | 234 | } |
---|