Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: removed some std::list

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