Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader/src/util/loading/load_param.cc @ 4259

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

orxonox/branches/levelLoader: nicer comments

File size: 6.4 KB
RevLine 
[4250]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: Christian Meyer
13   co-programmer: ...
14*/
15
16#include "load_param.h"
17
[4254]18#include "list.h"
19#include "base_object.h"
[4250]20
[4254]21#include <stdarg.h>
22
[4256]23/**
24   \param object The object this Parameter is loaded too.
25   \param paramName The name of the parameter loaded.
26   \param paramCount how many parameters this loading-function takes
27   \param ... the parameter information
28*/
[4254]29BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...)
[4251]30{
[4255]31  this->paramDesc = NULL;
[4254]32  if (LoadClassDescription::parametersDescription)
33    {
34      // locating the class
35      this->classDesc = LoadClassDescription::addClass(object->getClassName());
36      this->paramDesc = this->classDesc->addParam(paramName);
37
38      this->paramDesc->types = new char*[paramCount];
39      this->paramDesc->paramCount = paramCount;
40
41      va_list types;
42      va_start (types, paramCount);
43      for(int i = 0; i < paramCount; i++)
44        {
45          const char* tmpTypeName = va_arg (types, const char*);
46          this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1];
47          strcpy(this->paramDesc->types[i], tmpTypeName);
48        }
49      va_end(types); 
50
51      int argCount = 0;
52    }
[4251]53}
[4250]54
[4256]55/**
56   \param descriptionText The text to set as a description for this Parameter
57*/
[4254]58void BaseLoadParam::describe(const char* descriptionText)
59{
[4255]60  if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())
[4254]61    {
[4255]62      this->paramDesc->setDescription(descriptionText);
[4254]63    }
64}
65
[4256]66/**
67   \param paramName the name of the parameter to load
68*/
[4254]69LoadParamDescription::LoadParamDescription(const char* paramName)
70{
71  this->types = NULL;
[4255]72  this->description = NULL;
[4254]73  this->paramName = new char[strlen(paramName)+1];
74  strcpy(this->paramName, paramName);
75}
76
[4256]77/**
78   \brief removes all the alocated memory
79*/
[4254]80LoadParamDescription::~LoadParamDescription(void)
81{
82  for(int i = 0; i < this->paramCount; i++)
83    {
84      delete this->types[i];
85    }
86  delete []this->types;
87  delete []this->paramName;
[4256]88  delete []this->description;
[4254]89}
90
[4256]91/**
92   \param descriptionText The text to set as a description for this Parameter
93*/
[4255]94void LoadParamDescription::setDescription(const char* descriptionText)
95{
[4256]96  this->description = new char[strlen(descriptionText)+1];
97  strcpy(this->description, descriptionText);
[4255]98}
[4254]99
[4256]100/**
101   \brief prints out this parameter, its input method and the description (if availiable)
102*/
[4255]103void LoadParamDescription::print(void) const
104{
105  PRINT(3)(" <%s>", this->paramName);
106  for (int i = 0; i < this->paramCount; i++)
107    {
108      if (i > 0)
109        PRINT(3)(",");
110      PRINT(3)("%s", this->types[i]);
111    }
112  PRINT(3)("</%s>", this->paramName);
113  if (this->description)
114    PRINT(3)(" -- %s", this->description);
115  PRINT(3)("\n");
116}
117
[4256]118/**
119   \brief A list, that holds all the classes that are loadable (classes not objects!!)
120*/
[4254]121tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>;
122
[4251]123/**
124   \brief if the description of Parameters should be executed
125*/
[4254]126bool LoadClassDescription::parametersDescription = true;
127
[4256]128/**
129   \param className the name of the class to be loadable
130*/
[4254]131LoadClassDescription::LoadClassDescription(const char* className)
132{
133  this->className = new char[strlen(className)+1];
134  strcpy(this->className, className);
135
136  classList->add(this);
137
138  this->paramList = new tList<LoadParamDescription>;
139}
140
[4256]141/**
142   \brief deletes a classDescription (deletes all the parameterDescriptions as well
143*/
[4254]144LoadClassDescription::~LoadClassDescription(void)
145{
146  delete []this->className;
147
148  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
149  LoadParamDescription* enumParamDesc = iterator->nextElement();
150  while (enumParamDesc)
151    {
152      delete enumParamDesc;
153      enumParamDesc = iterator->nextElement();
154    }
155  delete iterator;
156}
157
[4256]158/**
159   \brief adds a class to the list of loadable classes
160   \param className The name of the class to add
[4254]161
[4256]162   this function searches for the className string, and if found just returns the appropriate Class.
163   Otherwise it returns a new classDescription
164*/
[4254]165LoadClassDescription* LoadClassDescription::addClass(const char* className)
166{
167  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
168  LoadClassDescription* enumClassDesc = iterator->nextElement();
169  while (enumClassDesc)
170    {
171      if (!strcmp(enumClassDesc->className, className))
172        {
173          delete iterator;
174          return enumClassDesc;
175        }
176      enumClassDesc = iterator->nextElement();
177    }
178  delete iterator;
179
180  return new LoadClassDescription(className);
181}
182
[4256]183/**
184   \brief does the same as addClass(const char* className), but with params
185   \param paramName the name of the parameter to add.
186*/
[4254]187LoadParamDescription* LoadClassDescription::addParam(const char* paramName)
188{
189  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
190  LoadParamDescription* enumParamDesc = iterator->nextElement();
191  while (enumParamDesc)
192    {
193      if (!strcmp(enumParamDesc->paramName, paramName))
194        {
195          delete iterator;
196          return enumParamDesc;
197        }
198      enumParamDesc = iterator->nextElement();
199    }
200  delete iterator;
201
202  this->paramList->add(new LoadParamDescription(paramName));
203  return paramList->lastElement();
204}
[4255]205
[4256]206/**
207   \brief prints out all loadable Classes, and their parameters
208*/
[4255]209void LoadClassDescription::printAll(void) 
210{
[4259]211  PRINT(3)("===============================================================\n");
212  PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");
[4255]213  tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator();
214  LoadClassDescription* enumClassDesc = classIT->nextElement();
215  while (enumClassDesc)
216    {
217      PRINT(3)("<%s>\n", enumClassDesc->className);
218      tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator();
219      LoadParamDescription* enumParamDesc = paramIT->nextElement();
220      while (enumParamDesc)
221        {
222          enumParamDesc->print();
223          enumParamDesc = paramIT->nextElement();
224        }
225      delete paramIT;
226
227      PRINT(3)("</%s>\n\n", enumClassDesc->className);
228      enumClassDesc = classIT->nextElement();
229    }
230  delete classIT;
[4259]231  PRINT(3)("===============================================================\n");
[4255]232}
Note: See TracBrowser for help on using the repository browser.