Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/loading/load_param_description.cc @ 7201

Last change on this file since 7201 was 7130, checked in by bensch, 19 years ago

orxonox/trunk: removed some std::list

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