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