[4597] | 1 | /* |
---|
[4250] | 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: |
---|
[4285] | 12 | main-programmer: Benjamin Grauer |
---|
[4250] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[5546] | 16 | #include "load_param_description.h" |
---|
[5556] | 17 | |
---|
[5691] | 18 | #include "multi_type.h" |
---|
[8362] | 19 | #include "debug.h" |
---|
| 20 | |
---|
[4860] | 21 | /** |
---|
[9776] | 22 | * @brief Creates a Description of a LoadParam |
---|
[4836] | 23 | * @param paramName the name of the parameter to load |
---|
[5546] | 24 | */ |
---|
[7221] | 25 | LoadParamDescription::LoadParamDescription(const std::string& paramName) |
---|
[9772] | 26 | : _name(paramName), _parameterCount(0) |
---|
[9765] | 27 | { } |
---|
[4254] | 28 | |
---|
[4256] | 29 | /** |
---|
[4836] | 30 | * @param descriptionText The text to set as a description for this Parameter |
---|
[5546] | 31 | */ |
---|
[7221] | 32 | void LoadParamDescription::setDescription(const std::string& descriptionText) |
---|
[4255] | 33 | { |
---|
[9767] | 34 | this->_description = descriptionText; |
---|
[4255] | 35 | } |
---|
[4254] | 36 | |
---|
[9776] | 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 | */ |
---|
[9772] | 43 | void 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 | |
---|
[4256] | 57 | /** |
---|
[9777] | 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. |
---|
[5546] | 61 | */ |
---|
[9777] | 62 | void LoadParamDescription::print(FILE* stream, bool withComments) const |
---|
[4255] | 63 | { |
---|
[9777] | 64 | fprintf(stream, " <%s>", this->_name.c_str()); |
---|
[9767] | 65 | for (unsigned int i = 0; i < this->_parameterCount; i++) |
---|
[5546] | 66 | { |
---|
| 67 | if (i > 0) |
---|
[9777] | 68 | fprintf(stream, ","); |
---|
| 69 | fprintf(stream, "%s", this->_types[i].c_str()); |
---|
[5546] | 70 | } |
---|
[9777] | 71 | fprintf(stream, "</%s>", this->_name.c_str()); |
---|
[9778] | 72 | // here the comments are printed out. |
---|
| 73 | if (withComments) |
---|
[4623] | 74 | { |
---|
[9778] | 75 | if (!this->_description.empty()) |
---|
| 76 | fprintf(stream, " <!-- %s", this->_description.c_str()); |
---|
| 77 | // default values |
---|
| 78 | if (this->_parameterCount > 0) |
---|
[4623] | 79 | { |
---|
[9778] | 80 | fprintf(stream, " (Default: "); |
---|
| 81 | for (unsigned int i = 0; i < this->_parameterCount; i++) |
---|
[4625] | 82 | { |
---|
[9778] | 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 | } |
---|
[4625] | 93 | } |
---|
[9778] | 94 | fprintf(stream, ")"); |
---|
[4623] | 95 | } |
---|
[9778] | 96 | if (!this->_description.empty() || this->_parameterCount > 0) |
---|
| 97 | fprintf(stream, " -->"); |
---|
[4623] | 98 | } |
---|
[9777] | 99 | fprintf(stream, "\n"); |
---|
[4255] | 100 | } |
---|
[9768] | 101 | |
---|
| 102 | |
---|