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