Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: doxygen-tags

File size: 6.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: Christian Meyer
13   co-programmer: ...
14*/
15
16#include "load_param.h"
17
18#include "list.h"
19#include "base_object.h"
20
21#include <stdarg.h>
22
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*/
29BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...)
30{
31  this->paramDesc = NULL;
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    }
53}
54
55/**
56   \param descriptionText The text to set as a description for this Parameter
57*/
58void BaseLoadParam::describe(const char* descriptionText)
59{
60  if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())
61    {
62      this->paramDesc->setDescription(descriptionText);
63    }
64}
65
66/**
67   \param paramName the name of the parameter to load
68*/
69LoadParamDescription::LoadParamDescription(const char* paramName)
70{
71  this->types = NULL;
72  this->description = NULL;
73  this->paramName = new char[strlen(paramName)+1];
74  strcpy(this->paramName, paramName);
75}
76
77/**
78   \brief removes all the alocated memory
79*/
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;
88  delete []this->description;
89}
90
91/**
92   \param descriptionText The text to set as a description for this Parameter
93*/
94void LoadParamDescription::setDescription(const char* descriptionText)
95{
96  this->description = new char[strlen(descriptionText)+1];
97  strcpy(this->description, descriptionText);
98}
99
100/**
101   \brief prints out this parameter, its input method and the description (if availiable)
102*/
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
118/**
119   \brief A list, that holds all the classes that are loadable (classes not objects!!)
120*/
121tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>;
122
123/**
124   \brief if the description of Parameters should be executed
125*/
126bool LoadClassDescription::parametersDescription = true;
127
128/**
129   \param className the name of the class to be loadable
130*/
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
141/**
142   \brief deletes a classDescription (deletes all the parameterDescriptions as well
143*/
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
158/**
159   \brief adds a class to the list of loadable classes
160   \param className The name of the class to add
161
162   this function searches for the className string, and if found just returns the appropriate Class.
163   Otherwise it returns a new classDescription
164*/
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
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*/
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}
205
206/**
207   \brief prints out all loadable Classes, and their parameters
208*/
209void LoadClassDescription::printAll(void) 
210{
211  PRINT(3)("==============================================================\n");
212  PRINT(3)(" Listing all the Loadable Options (loaded since Game started.\n\n");
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;
231
232}
Note: See TracBrowser for help on using the repository browser.