Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/load_param_class_description.cc @ 9780

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

some comments

File size: 5.6 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: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#include "load_param_class_description.h"
17
18#include "multi_type.h"
19#include "debug.h"
20
21/**
22 * @brief A list, that holds all the classes that are loadable (classes not objects!!)
23 */
24LoadParamClassDescription::ClassDescriptionMap LoadParamClassDescription::_classList;
25
26/**
27 * @brief if the description of Parameters should be executed
28 */
29bool LoadParamClassDescription::_captureDescriptions = false;
30
31/**
32 * @param className the name of the class to be loadable
33 */
34LoadParamClassDescription::LoadParamClassDescription(const std::string& className)
35    : _className(className)
36{ }
37
38
39/**
40 * @brief clears all LoadParamDescriptions.
41 */
42void LoadParamClassDescription::deleteAllDescriptions()
43{
44  LoadParamClassDescription::_classList.clear();
45}
46
47
48/**
49 * @brief describes a LoadParam-parameter.
50 * @param classID the ID of the class.
51 * @param paramName the Name of the Parameter.
52 * @param descriptionText the Test to set.
53 */
54void LoadParamClassDescription::describeClass(const ClassID& classID,
55    const std::string& paramName,
56    const std::string& descriptionText)
57{
58  ParamDescriptionMap::iterator it = LoadParamClassDescription::getParamDescription(classID, paramName);
59
60  (*it).second.setDescription(descriptionText);
61}
62
63/**
64 * @brief sets Values of the specified LoadParam-parameter.
65 * @param classID the ID of the class.
66 * @param paramName the name of the Parameter.
67 * @param paramCount the count of Parameters this LoadParam takes.
68 * @param defaultValues the default Values.
69 * @param retVal if the Parameter takes return Values.
70 */
71void LoadParamClassDescription::setValuesOf(const ClassID& classID,
72    const std::string& paramName,
73    unsigned int paramCount,
74    const MultiType* const defaultValues,
75    bool retVal)
76{
77  ParamDescriptionMap::iterator it = LoadParamClassDescription::getParamDescription(classID, paramName);
78  (*it).second.setValues(paramCount, defaultValues, retVal);
79}
80
81
82/**
83 * @brief finds the Iterator to the ParameterDescription paramName matching classID
84 * @param classID the ClassID to match.
85 * @param paramName the name of the parameter in the Class.
86 * @returns the iterator on match.
87 *
88 * @note this function creates the Element classID.name()::paramName on the go if it does not exist.
89 */
90LoadParamClassDescription::ParamDescriptionMap::iterator
91LoadParamClassDescription::getParamDescription(const ClassID& classID, const std::string& paramName)
92{
93  /// Locate the ClassDescription first
94  ClassDescriptionMap::iterator classIt = LoadParamClassDescription::_classList.find(classID);
95  if (classIt == LoadParamClassDescription::_classList.end())
96  {
97    LoadParamClassDescription::_classList[classID] = LoadParamClassDescription(classID.name());
98    classIt = LoadParamClassDescription::_classList.find(classID);
99  }
100  // At this position the class-iterator should point to a valid usefull position.
101  assert(classIt != LoadParamClassDescription::_classList.end());
102
103  /// Now locate the description with paramName.
104  ParamDescriptionMap::iterator paramIt = (*classIt).second._parameters.find(paramName);
105  if (paramIt == (*classIt).second._parameters.end())
106  {
107    (*classIt).second._parameters[paramName] = LoadParamDescription(paramName);
108    paramIt = (*classIt).second._parameters.find(paramName);
109  }
110  // at this position the param-iterator should
111  assert (paramIt != (*classIt).second._parameters.end());
112
113  return (paramIt);
114}
115
116/**
117 * @brief prints out a nice output about this Classes Loading, and their parameters
118 * @param stream the stream to write to.
119 * @param withComments if Comments should be included.
120 */
121void LoadParamClassDescription::print(FILE* stream, bool withComments) const
122{
123  fprintf(stream, "<%s>\n", this->_className.c_str());
124  for (ParamDescriptionMap::const_iterator param = this->_parameters.begin();
125       param != this->_parameters.end();
126       ++param)
127  {
128    (*param).second.print(stream, withComments);
129  }
130  fprintf(stream, "</%s>\n\n", this->_className.c_str());
131}
132
133
134/**
135 * @brief prints out all loadable Classes, and their parameters
136 * @param fileName prints the output to a File
137 * @param withComments if Comments should be included.
138 */
139void LoadParamClassDescription::printAll(const std::string& fileName, bool withComments)
140{
141  FILE* stream;
142  if( (stream = fopen (fileName.c_str(), "w")) == NULL)
143  {
144    PRINTF(2)("File '%s' could not be opened for writing\n Printing to stdout\n", fileName.c_str());
145    LoadParamClassDescription::printAllTo(stdout, withComments);
146    return;
147  }
148  else
149    LoadParamClassDescription::printAllTo(stream, withComments);
150
151  fclose (stream);
152}
153
154/**
155 * @brief prints out all loadable Classes, and their parameters to a stream
156 * @param stream the stream to print to.
157 * @param withComments if Comments should be included.
158 */
159void LoadParamClassDescription::printAllTo(FILE* stream, bool withComments)
160{
161  fprintf(stream, "===============================================================\n");
162  fprintf(stream, " Listing all the Loadable Options (loaded since Game started).\n\n");
163  for (ClassDescriptionMap::const_iterator classIt = LoadParamClassDescription::_classList.begin();
164       classIt != LoadParamClassDescription::_classList.end();
165       classIt ++)
166  {
167    (*classIt).second.print(stream, withComments);
168  }
169  fprintf(stream, "===============================================================\n");
170}
Note: See TracBrowser for help on using the repository browser.