Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/lib/util/loading/load_param_description.cc

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

some movements

File size: 2.9 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_description.h"
17
18#include "multi_type.h"
19#include "debug.h"
20
21/**
22 * @brief Creates a Description of a LoadParam
23 * @param paramName the name of the parameter to load
24 */
25LoadParamDescription::LoadParamDescription(const std::string& paramName)
26    : _name(paramName), _parameterCount(0)
27{ }
28
29/**
30 * @param descriptionText The text to set as a description for this Parameter
31 */
32void LoadParamDescription::setDescription(const std::string& descriptionText)
33{
34  this->_description = descriptionText;
35}
36
37/**
38 * @brief sets the Values of the LoadParam in the Description.
39 * @param paramCount the count of arguments the underlying paramDescription takes.
40 * @param defaultValues the default Values the underlying parameter takes.
41 * @param retVal if the underlying parameter has a return value
42 */
43void LoadParamDescription::setValues(unsigned int paramCount,
44                                     const MultiType* const defaultValues,
45                                     bool retVal)
46{
47  this->_parameterCount = paramCount;
48  for (unsigned int i = 0; i < paramCount; ++i)
49  {
50    this->_defaultValues.push_back(defaultValues[i].getString());
51    this->_types.push_back(MultiType::MultiTypeToString(defaultValues[i].getType()));
52  }
53
54}
55
56
57/**
58 * @brief prints out this parameter, its input method and the description (if availiable)
59 * @param stream the stream to print to.
60 * @param withComments if the comments should be appended.
61 */
62void LoadParamDescription::print(FILE* stream, bool withComments) const
63{
64  fprintf(stream, " <%s>", this->_name.c_str());
65  for (unsigned int i = 0; i < this->_parameterCount; i++)
66  {
67    if (i > 0)
68      fprintf(stream, ",");
69    fprintf(stream, "%s", this->_types[i].c_str());
70  }
71  fprintf(stream, "</%s>", this->_name.c_str());
72  // here the comments are printed out.
73  if (withComments)
74  {
75    if (!this->_description.empty())
76      fprintf(stream, " <!-- %s", this->_description.c_str());
77    // default values
78    if (this->_parameterCount > 0)
79    {
80      fprintf(stream, " (Default: ");
81      for (unsigned int i = 0; i < this->_parameterCount; i++)
82      {
83        if (i > 0)
84          fprintf(stream, ", ");
85        if (this->_types[i] == "string")
86        { // leave brackets !!
87          fprintf(stream, "\"%s\"", this->_defaultValues[i].c_str());
88        }
89        else
90        {
91          fprintf(stream, "%s", this->_defaultValues[i].c_str());
92        }
93      }
94      fprintf(stream, ")");
95    }
96    if (!this->_description.empty() || this->_parameterCount > 0)
97      fprintf(stream, " -->");
98  }
99  fprintf(stream, "\n");
100}
Note: See TracBrowser for help on using the repository browser.