Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/loading/load_param_class_description.cc @ 10145

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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