[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 | |
---|
[9765] | 16 | #include "load_param_class_description.h" |
---|
[5556] | 17 | |
---|
[5691] | 18 | #include "multi_type.h" |
---|
[8362] | 19 | #include "debug.h" |
---|
[9856] | 20 | #include <cassert> |
---|
[8362] | 21 | |
---|
[4860] | 22 | /** |
---|
[9775] | 23 | * @brief A list, that holds all the classes that are loadable (classes not objects!!) |
---|
[5546] | 24 | */ |
---|
[9771] | 25 | LoadParamClassDescription::ClassDescriptionMap LoadParamClassDescription::_classList; |
---|
[4254] | 26 | |
---|
[4251] | 27 | /** |
---|
[9775] | 28 | * @brief if the description of Parameters should be executed |
---|
[5546] | 29 | */ |
---|
[9779] | 30 | bool LoadParamClassDescription::_captureDescriptions = false; |
---|
[4254] | 31 | |
---|
[4256] | 32 | /** |
---|
[4836] | 33 | * @param className the name of the class to be loadable |
---|
[5546] | 34 | */ |
---|
[9765] | 35 | LoadParamClassDescription::LoadParamClassDescription(const std::string& className) |
---|
[9768] | 36 | : _className(className) |
---|
| 37 | { } |
---|
[4254] | 38 | |
---|
[9776] | 39 | |
---|
[4256] | 40 | /** |
---|
[9776] | 41 | * @brief clears all LoadParamDescriptions. |
---|
[5546] | 42 | */ |
---|
[9765] | 43 | void LoadParamClassDescription::deleteAllDescriptions() |
---|
[5226] | 44 | { |
---|
[9768] | 45 | LoadParamClassDescription::_classList.clear(); |
---|
[5226] | 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
[9776] | 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 | */ |
---|
[9771] | 55 | void 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 | |
---|
[9772] | 61 | (*it).second.setDescription(descriptionText); |
---|
[9771] | 62 | } |
---|
| 63 | |
---|
[9776] | 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 | */ |
---|
[9771] | 72 | void 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); |
---|
[9772] | 79 | (*it).second.setValues(paramCount, defaultValues, retVal); |
---|
[9771] | 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
[4256] | 83 | /** |
---|
[9771] | 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 | */ |
---|
| 91 | LoadParamClassDescription::ParamDescriptionMap::iterator |
---|
| 92 | LoadParamClassDescription::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 | |
---|
[9780] | 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 | */ |
---|
[9779] | 122 | void 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 | |
---|
[9777] | 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 | */ |
---|
| 140 | void 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); |
---|
[9771] | 151 | |
---|
[9777] | 152 | fclose (stream); |
---|
| 153 | } |
---|
[9771] | 154 | |
---|
| 155 | /** |
---|
[9777] | 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. |
---|
[5546] | 159 | */ |
---|
[9777] | 160 | void LoadParamClassDescription::printAllTo(FILE* stream, bool withComments) |
---|
[4255] | 161 | { |
---|
[9777] | 162 | fprintf(stream, "===============================================================\n"); |
---|
| 163 | fprintf(stream, " Listing all the Loadable Options (loaded since Game started).\n\n"); |
---|
[9771] | 164 | for (ClassDescriptionMap::const_iterator classIt = LoadParamClassDescription::_classList.begin(); |
---|
| 165 | classIt != LoadParamClassDescription::_classList.end(); |
---|
[9768] | 166 | classIt ++) |
---|
[5226] | 167 | { |
---|
[9779] | 168 | (*classIt).second.print(stream, withComments); |
---|
[5226] | 169 | } |
---|
[9777] | 170 | fprintf(stream, "===============================================================\n"); |
---|
[4255] | 171 | } |
---|