Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/std: less char*

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