Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: description works

File size: 5.0 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
23
24BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...)
[4251]25{
[4255]26  this->paramDesc = NULL;
[4254]27  if (LoadClassDescription::parametersDescription)
28    {
29      // locating the class
30      this->classDesc = LoadClassDescription::addClass(object->getClassName());
31      this->paramDesc = this->classDesc->addParam(paramName);
32
33      this->paramDesc->types = new char*[paramCount];
34      this->paramDesc->paramCount = paramCount;
35
36      va_list types;
37      va_start (types, paramCount);
38      for(int i = 0; i < paramCount; i++)
39        {
40          const char* tmpTypeName = va_arg (types, const char*);
41          this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1];
42          strcpy(this->paramDesc->types[i], tmpTypeName);
43        }
44      va_end(types); 
45
46      int argCount = 0;
47    }
[4251]48}
[4250]49
[4254]50
51void BaseLoadParam::describe(const char* descriptionText)
52{
[4255]53  if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())
[4254]54    {
[4255]55      this->paramDesc->setDescription(descriptionText);
[4254]56    }
57}
58
59LoadParamDescription::LoadParamDescription(const char* paramName)
60{
61  this->types = NULL;
[4255]62  this->description = NULL;
[4254]63  this->paramName = new char[strlen(paramName)+1];
64  strcpy(this->paramName, paramName);
65}
66
[4255]67
[4254]68LoadParamDescription::~LoadParamDescription(void)
69{
70  for(int i = 0; i < this->paramCount; i++)
71    {
72      delete this->types[i];
73    }
74  delete []this->types;
75  delete []this->paramName;
76}
77
[4255]78void LoadParamDescription::setDescription(const char* descriptionText)
79{
80  this->description = descriptionText;
81}
[4254]82
[4255]83void LoadParamDescription::print(void) const
84{
85  PRINT(3)(" <%s>", this->paramName);
86  for (int i = 0; i < this->paramCount; i++)
87    {
88      if (i > 0)
89        PRINT(3)(",");
90      PRINT(3)("%s", this->types[i]);
91    }
92  PRINT(3)("</%s>", this->paramName);
93  if (this->description)
94    PRINT(3)(" -- %s", this->description);
95  PRINT(3)("\n");
96}
97
98
[4254]99tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>;
100
[4251]101/**
102   \brief if the description of Parameters should be executed
103*/
[4254]104bool LoadClassDescription::parametersDescription = true;
105
106LoadClassDescription::LoadClassDescription(const char* className)
107{
108  this->className = new char[strlen(className)+1];
109  strcpy(this->className, className);
110
111  classList->add(this);
112
113  this->paramList = new tList<LoadParamDescription>;
114}
115
[4255]116
[4254]117LoadClassDescription::~LoadClassDescription(void)
118{
119  delete []this->className;
120
121  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
122  LoadParamDescription* enumParamDesc = iterator->nextElement();
123  while (enumParamDesc)
124    {
125      delete enumParamDesc;
126      enumParamDesc = iterator->nextElement();
127    }
128  delete iterator;
129}
130
131
132LoadClassDescription* LoadClassDescription::addClass(const char* className)
133{
134  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
135  LoadClassDescription* enumClassDesc = iterator->nextElement();
136  while (enumClassDesc)
137    {
138      if (!strcmp(enumClassDesc->className, className))
139        {
140          delete iterator;
141          return enumClassDesc;
142        }
143      enumClassDesc = iterator->nextElement();
144    }
145  delete iterator;
146
147  return new LoadClassDescription(className);
148}
149
150
151LoadParamDescription* LoadClassDescription::addParam(const char* paramName)
152{
153  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
154  LoadParamDescription* enumParamDesc = iterator->nextElement();
155  while (enumParamDesc)
156    {
157      if (!strcmp(enumParamDesc->paramName, paramName))
158        {
159          delete iterator;
160          return enumParamDesc;
161        }
162      enumParamDesc = iterator->nextElement();
163    }
164  delete iterator;
165
166  this->paramList->add(new LoadParamDescription(paramName));
167  return paramList->lastElement();
168}
[4255]169
170void LoadClassDescription::printAll(void) 
171{
172  PRINT(3)("==============================================================\n");
173  PRINT(3)(" Listing all the Loadable Options (loaded since Game started.\n\n");
174  tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator();
175  LoadClassDescription* enumClassDesc = classIT->nextElement();
176  while (enumClassDesc)
177    {
178      PRINT(3)("<%s>\n", enumClassDesc->className);
179      tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator();
180      LoadParamDescription* enumParamDesc = paramIT->nextElement();
181      while (enumParamDesc)
182        {
183          enumParamDesc->print();
184          enumParamDesc = paramIT->nextElement();
185        }
186      delete paramIT;
187
188      PRINT(3)("</%s>\n\n", enumClassDesc->className);
189      enumClassDesc = classIT->nextElement();
190    }
191  delete classIT;
192
193}
Note: See TracBrowser for help on using the repository browser.