Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/std/src/lib/util/loading/load_param_description.cc @ 7203

Last change on this file since 7203 was 7203, checked in by bensch, 18 years ago

orxonox/trunk: compiles again, BUT well…. i do not expect it to run anymore

File size: 7.3 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 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 */
34LoadParamDescription::~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 */
51void 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 */
59void 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 */
126std::list<LoadClassDescription*>* LoadClassDescription::classList = NULL;
127
128/**
129 *  if the description of Parameters should be executed
130 */
131bool LoadClassDescription::parametersDescription = false;
132
133/**
134 * @param className the name of the class to be loadable
135 */
136LoadClassDescription::LoadClassDescription(const char* className)
137{
138  this->className = new char[strlen(className)+1];
139  strcpy(this->className, className);
140
141  if (LoadClassDescription::classList == NULL)
142    LoadClassDescription::classList = new std::list<LoadClassDescription*>;
143
144  LoadClassDescription::classList->push_back(this);
145}
146
147/**
148 *  deletes a classDescription (deletes all the parameterDescriptions as well
149 */
150LoadClassDescription::~LoadClassDescription()
151{
152  std::list<LoadParamDescription*>::iterator it = this->paramList.begin();
153  while (!this->paramList.empty())
154  {
155    delete this->paramList.front();
156    this->paramList.pop_front();
157  }
158
159  delete[] this->className;
160}
161
162void LoadClassDescription::deleteAllDescriptions()
163{
164  if (LoadClassDescription::classList != NULL)
165  {
166    while (!LoadClassDescription::classList->empty())
167    {
168      delete LoadClassDescription::classList->front();
169      LoadClassDescription::classList->pop_front();
170    }
171    delete LoadClassDescription::classList;
172  }
173  LoadClassDescription::classList = NULL;
174}
175
176
177/**
178 *  adds a class to the list of loadable classes
179 * @param className The name of the class to add
180
181   this function searches for the className string, and if found just returns the appropriate Class.
182   Otherwise it returns a new classDescription
183 */
184LoadClassDescription* LoadClassDescription::addClass(const char* className)
185{
186  if (LoadClassDescription::classList != NULL)
187  {
188    std::list<LoadClassDescription*>::iterator it = LoadClassDescription::classList->begin();
189    while (it != LoadClassDescription::classList->end())
190    {
191      if (!strcmp((*it)->className, className))
192      {
193        return (*it);
194      }
195      it++;
196    }
197  }
198  return new LoadClassDescription(className);
199}
200
201/**
202 *  does the same as addClass(const char* className), but with params
203 * @param paramName the name of the parameter to add.
204 */
205LoadParamDescription* LoadClassDescription::addParam(const char* paramName)
206{
207  std::list<LoadParamDescription*>::iterator it = this->paramList.begin();
208  while (it != this->paramList.end())
209  {
210    if ((*it)->paramName == paramName)
211    {
212      return NULL;
213    }
214    it++;
215  }
216
217  LoadParamDescription* newParam = new LoadParamDescription(paramName);
218
219  this->paramList.push_back(newParam);
220  return newParam;
221}
222
223/**
224 *  prints out all loadable Classes, and their parameters
225 * @param fileName prints the output to a File
226 * @todo implement it
227 */
228void LoadClassDescription::printAll(const char* fileName)
229{
230  PRINT(3)("===============================================================\n");
231  PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");
232  if (LoadClassDescription::classList != NULL)
233  {
234    std::list<LoadClassDescription*>::iterator classDesc = LoadClassDescription::classList->begin();
235    while (classDesc != LoadClassDescription::classList->end())
236    {
237      PRINT(3)("<%s>\n", (*classDesc)->className);
238      std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin();
239      while (param != (*classDesc)->paramList.end())
240      {
241        (*param)->print();
242        param++;
243      }
244      PRINT(3)("</%s>\n\n", (*classDesc)->className);
245      classDesc++;
246    }
247  }
248  else
249    PRINT(3)("no Classes defined so far\n");
250  PRINT(3)("===============================================================\n");
251}
252
253/**
254 * searches for classes, which beginn with classNameBegin
255 * @param classNameBegin the beginning string of a Class
256 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
257 * !! The strings MUST NOT be deleted !!
258 */
259std::list<const char*> LoadClassDescription::searchClassWithShort(const char* classNameBegin)
260{
261  /// FIXME
262  // NOT USED
263/*  unsigned int searchLength = strlen(classNameBegin);
264  std::list<const char*> retVal;
265
266  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
267  LoadClassDescription* enumClassDesc = iterator->firstElement();
268  while (enumClassDesc)
269  {
270    if (strlen(enumClassDesc->className)>searchLength+1 &&
271        !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))
272    {
273      retVal->add(enumClassDesc->className);
274    }
275    enumClassDesc = iterator->nextElement();
276  }
277  delete iterator;
278
279  return retVal;*/
280}
Note: See TracBrowser for help on using the repository browser.