Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

nice description again for the load_params

File size: 4.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: 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 *  A list, that holds all the classes that are loadable (classes not objects!!)
23 */
24LoadParamClassDescription::ClassDescriptionMap LoadParamClassDescription::_classList;
25
26/**
27 *  if the description of Parameters should be executed
28 */
29bool LoadParamClassDescription::_parametersDescription = 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 *  deletes a classDescription (deletes all the parameterDescriptions as well
40 */
41LoadParamClassDescription::~LoadParamClassDescription()
42{}
43
44void LoadParamClassDescription::deleteAllDescriptions()
45{
46  LoadParamClassDescription::_classList.clear();
47}
48
49
50
51void LoadParamClassDescription::describeClass(const ClassID& classID,
52    const std::string& paramName,
53    const std::string& descriptionText)
54{
55  ParamDescriptionMap::iterator it = LoadParamClassDescription::getParamDescription(classID, paramName);
56
57  (*it).second.setDescription(descriptionText);
58}
59
60
61void LoadParamClassDescription::setValuesOf(const ClassID& classID,
62    const std::string& paramName,
63    unsigned int paramCount,
64    const MultiType* const defaultValues,
65    bool retVal)
66{
67  ParamDescriptionMap::iterator it = LoadParamClassDescription::getParamDescription(classID, paramName);
68  (*it).second.setValues(paramCount, defaultValues, retVal);
69}
70
71
72/**
73 * @brief finds the Iterator to the ParameterDescription paramName matching classID
74 * @param classID the ClassID to match.
75 * @param paramName the name of the parameter in the Class.
76 * @returns the iterator on match.
77 *
78 * @note this function creates the Element classID.name()::paramName on the go if it does not exist.
79 */
80LoadParamClassDescription::ParamDescriptionMap::iterator
81LoadParamClassDescription::getParamDescription(const ClassID& classID, const std::string& paramName)
82{
83  /// Locate the ClassDescription first
84  ClassDescriptionMap::iterator classIt = LoadParamClassDescription::_classList.find(classID);
85  if (classIt == LoadParamClassDescription::_classList.end())
86  {
87    LoadParamClassDescription::_classList[classID] = LoadParamClassDescription(classID.name());
88    classIt = LoadParamClassDescription::_classList.find(classID);
89    printf("Inserted %s\n", classID.name().c_str());
90    printAll("");
91  }
92  // At this position the class-iterator should point to a valid usefull position.
93  assert(classIt != LoadParamClassDescription::_classList.end());
94
95  /// Now locate the description with paramName.
96  ParamDescriptionMap::iterator paramIt = (*classIt).second._parameters.find(paramName);
97  if (paramIt == (*classIt).second._parameters.end())
98  {
99    (*classIt).second._parameters[paramName] = LoadParamDescription(paramName);
100    paramIt = (*classIt).second._parameters.find(paramName);
101  }
102  // at this position the param-iterator should
103  assert (paramIt != (*classIt).second._parameters.end());
104
105  return (paramIt);
106}
107
108
109
110
111/**
112 * @brief prints out all loadable Classes, and their parameters
113 * @param fileName prints the output to a File
114 * @todo implement it
115 */
116void LoadParamClassDescription::printAll(const std::string& fileName)
117{
118  PRINT(0)("===============================================================\n");
119  PRINT(0)(" Listing all the Loadable Options (loaded since Game started).\n\n");
120  for (ClassDescriptionMap::const_iterator classIt = LoadParamClassDescription::_classList.begin();
121       classIt != LoadParamClassDescription::_classList.end();
122       classIt ++)
123  {
124    PRINT(0)("<%s>\n", (*classIt).second._className.c_str());
125    for (ParamDescriptionMap::const_iterator param = (*classIt).second._parameters.begin();
126         param != (*classIt).second._parameters.end();
127         ++param)
128    {
129      (*param).second.print();
130    }
131    PRINT(0)("</%s>\n\n", (*classIt).second._className.c_str());
132  }
133  PRINT(0)("===============================================================\n");
134}
Note: See TracBrowser for help on using the repository browser.