Changeset 871 for code/trunk/src/orxonox/core/ConfigValueContainer.cc
- Timestamp:
- Mar 9, 2008, 4:44:36 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/core/ConfigValueContainer.cc
r790 r871 26 26 */ 27 27 28 /** 29 @file ConfigValueContainer.cc 30 @brief Implementation of the ConfigValueContainer class. 31 */ 32 28 33 #include <fstream> 29 34 35 #include "ConfigValueContainer.h" 30 36 #include "util/Tokenizer.h" 31 37 #include "util/Convert.h" 32 #include " ConfigValueContainer.h"38 #include "Language.h" 33 39 34 40 #define CONFIGFILEPATH "orxonox.ini" … … 43 49 @param defvalue The default-value 44 50 */ 45 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, intdefvalue)51 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue) 46 52 { 47 53 this->bAddedDescription_ = false; 48 54 this->classname_ = classname; 49 55 this->varname_ = varname; 50 this->type_ = VT_Int; 51 52 ConvertValue(&this->defvalueString_, defvalue, std::string("0")); // Try to convert the default-value to a string 56 57 this->valueToString(&this->defvalueString_, defvalue); // Try to convert the default-value to a string 53 58 this->searchConfigFileLine(); // Search the entry in the config-file 54 59 55 std::string valueString = this->parseValueString( );// Parses the value string from the config-file-entry56 if (!this->parseSt ing(valueString, defvalue))// Try to convert the string to a value60 std::string valueString = this->parseValueString(!(defvalue.isA(MT_string) || defvalue.isA(MT_constchar))); // Parses the value string from the config-file-entry 61 if (!this->parseString(valueString, defvalue)) // Try to convert the string to a value 57 62 this->resetConfigFileEntry(); // The conversion failed 58 63 } 59 64 60 65 /** 61 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 62 @param value This is only needed to determine the right type. 63 @param classname The name of the class the variable belongs to 64 @param varname The name of the variable 65 @param defvalue The default-value 66 */ 67 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue) 68 { 69 this->bAddedDescription_ = false; 70 this->classname_ = classname; 71 this->varname_ = varname; 72 this->type_ = VT_uInt; 73 74 ConvertValue(&this->defvalueString_, defvalue, std::string("0")); // Try to convert the default-value to a string 75 this->searchConfigFileLine(); // Search the entry in the config-file 76 77 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 78 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 79 this->resetConfigFileEntry(); // The conversion failed 80 } 81 82 /** 83 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 84 @param value This is only needed to determine the right type. 85 @param classname The name of the class the variable belongs to 86 @param varname The name of the variable 87 @param defvalue The default-value 88 */ 89 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue) 90 { 91 this->bAddedDescription_ = false; 92 this->classname_ = classname; 93 this->varname_ = varname; 94 this->type_ = VT_Char; 95 96 ConvertValue(&this->defvalueString_, (int)defvalue, std::string("0")); // Try to convert the default-value to a string 97 this->searchConfigFileLine(); // Search the entry in the config-file 98 99 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 100 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 101 this->resetConfigFileEntry(); // The conversion failed 102 } 103 104 /** 105 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 106 @param value This is only needed to determine the right type. 107 @param classname The name of the class the variable belongs to 108 @param varname The name of the variable 109 @param defvalue The default-value 110 */ 111 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue) 112 { 113 this->bAddedDescription_ = false; 114 this->classname_ = classname; 115 this->varname_ = varname; 116 this->type_ = VT_uChar; 117 118 ConvertValue(&this->defvalueString_, (unsigned int)defvalue, std::string("0")); // Try to convert the default-value to a string 119 this->searchConfigFileLine(); // Search the entry in the config-file 120 121 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 122 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 123 this->resetConfigFileEntry(); // The conversion failed 124 } 125 126 /** 127 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 128 @param value This is only needed to determine the right type. 129 @param classname The name of the class the variable belongs to 130 @param varname The name of the variable 131 @param defvalue The default-value 132 */ 133 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue) 134 { 135 this->bAddedDescription_ = false; 136 this->classname_ = classname; 137 this->varname_ = varname; 138 this->type_ = VT_Float; 139 140 ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000")); // Try to convert the default-value to a string 141 this->searchConfigFileLine(); // Search the entry in the config-file 142 143 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 144 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 145 this->resetConfigFileEntry(); // The conversion failed 146 } 147 148 /** 149 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 150 @param value This is only needed to determine the right type. 151 @param classname The name of the class the variable belongs to 152 @param varname The name of the variable 153 @param defvalue The default-value 154 */ 155 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue) 156 { 157 this->bAddedDescription_ = false; 158 this->classname_ = classname; 159 this->varname_ = varname; 160 this->type_ = VT_Double; 161 162 ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000")); // Try to convert the default-value to a string 163 this->searchConfigFileLine(); // Search the entry in the config-file 164 165 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 166 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 167 this->resetConfigFileEntry(); // The conversion failed 168 } 169 170 /** 171 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 172 @param value This is only needed to determine the right type. 173 @param classname The name of the class the variable belongs to 174 @param varname The name of the variable 175 @param defvalue The default-value 176 */ 177 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue) 178 { 179 this->bAddedDescription_ = false; 180 this->classname_ = classname; 181 this->varname_ = varname; 182 this->type_ = VT_LongDouble; 183 184 ConvertValue(&this->defvalueString_, defvalue, std::string("0.000000")); // Try to convert the default-value to a string 185 this->searchConfigFileLine(); // Search the entry in the config-file 186 187 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 188 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 189 this->resetConfigFileEntry(); // The conversion failed 190 } 191 192 /** 193 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 194 @param value This is only needed to determine the right type. 195 @param classname The name of the class the variable belongs to 196 @param varname The name of the variable 197 @param defvalue The default-value 198 */ 199 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue) 200 { 201 this->bAddedDescription_ = false; 202 this->classname_ = classname; 203 this->varname_ = varname; 204 this->type_ = VT_Bool; 205 206 // Convert the default-value from bool to string 207 if (defvalue) 208 this->defvalueString_ = "true"; 209 else 210 this->defvalueString_ = "false"; 211 212 this->searchConfigFileLine(); // Search the entry in the config-file 213 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 214 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 215 this->resetConfigFileEntry(); // The conversion failed 216 } 217 218 /** 219 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 220 @param value This is only needed to determine the right type. 221 @param classname The name of the class the variable belongs to 222 @param varname The name of the variable 223 @param defvalue The default-value 224 */ 225 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue) 226 { 227 this->bAddedDescription_ = false; 228 this->classname_ = classname; 229 this->varname_ = varname; 230 this->type_ = VT_String; 231 232 this->defvalueString_ = "\"" + defvalue + "\""; // Convert the string to a "config-file-string" with quotes 233 this->searchConfigFileLine(); // Search the entry in the config-file 234 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 235 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 236 this->resetConfigFileEntry(); // The conversion failed 237 } 238 239 /** 240 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 241 @param value This is only needed to determine the right type. 242 @param classname The name of the class the variable belongs to 243 @param varname The name of the variable 244 @param defvalue The default-value 245 */ 246 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue) 247 { 248 this->bAddedDescription_ = false; 249 this->classname_ = classname; 250 this->varname_ = varname; 251 this->type_ = VT_ConstChar; 252 253 this->defvalueString_ = "\"" + std::string(defvalue) + "\""; // Convert the string to a "config-file-string" with quotes 254 this->searchConfigFileLine(); // Search the entry in the config-file 255 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 256 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 257 this->resetConfigFileEntry(); // The conversion failed 258 } 259 260 /** 261 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 262 @param value This is only needed to determine the right type. 263 @param classname The name of the class the variable belongs to 264 @param varname The name of the variable 265 @param defvalue The default-value 266 */ 267 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Vector2 defvalue) 268 { 269 this->bAddedDescription_ = false; 270 this->classname_ = classname; 271 this->varname_ = varname; 272 this->type_ = VT_Vector2; 273 274 // Try to convert the default-value from Vector2 to string 275 std::ostringstream ostream; 276 if (ostream << "(" << defvalue.x << "," << defvalue.y << ")") 277 this->defvalueString_ = ostream.str(); 278 else 279 this->defvalueString_ = "(0,0)"; 280 281 this->searchConfigFileLine(); // Search the entry in the config-file 282 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 283 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 284 this->resetConfigFileEntry(); // The conversion failed 285 } 286 287 /** 288 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 289 @param value This is only needed to determine the right type. 290 @param classname The name of the class the variable belongs to 291 @param varname The name of the variable 292 @param defvalue The default-value 293 */ 294 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Vector3 defvalue) 295 { 296 this->bAddedDescription_ = false; 297 this->classname_ = classname; 298 this->varname_ = varname; 299 this->type_ = VT_Vector3; 300 301 // Try to convert the default-value from Vector3 to string 302 std::ostringstream ostream; 303 if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")") 304 this->defvalueString_ = ostream.str(); 305 else 306 this->defvalueString_ = "(0,0,0)"; 307 308 this->searchConfigFileLine(); // Search the entry in the config-file 309 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 310 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 311 this->resetConfigFileEntry(); // The conversion failed 312 } 313 314 /** 315 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 316 @param value This is only needed to determine the right type. 317 @param classname The name of the class the variable belongs to 318 @param varname The name of the variable 319 @param defvalue The default-value 320 */ 321 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, ColourValue defvalue) 322 { 323 this->bAddedDescription_ = false; 324 this->classname_ = classname; 325 this->varname_ = varname; 326 this->type_ = VT_ColourValue; 327 328 // Try to convert the default-value from ColourValue to string 329 std::ostringstream ostream; 330 if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")") 331 this->defvalueString_ = ostream.str(); 332 else 333 this->defvalueString_ = "(0,0,0,0)"; 334 335 this->searchConfigFileLine(); // Search the entry in the config-file 336 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 337 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 338 this->resetConfigFileEntry(); // The conversion failed 66 @brief Converts a value to a string. 67 @param output The string to write to 68 @param input The value to convert 69 @return True if the converson was successful 70 */ 71 bool ConfigValueContainer::valueToString(std::string* output, MultiTypeMath& input) 72 { 73 if (input.getType() == MT_int) 74 return ConvertValue(output, input.getInt(), std::string("0")); 75 else if (input.getType() == MT_uint) 76 return ConvertValue(output, input.getUnsignedInt(), std::string("0")); 77 else if (input.getType() == MT_char) 78 return ConvertValue(output, (int)input.getChar(), std::string("0")); 79 else if (input.getType() == MT_uchar) 80 return ConvertValue(output, (unsigned int)input.getUnsignedChar(), std::string("0")); 81 else if (input.getType() == MT_short) 82 return ConvertValue(output, input.getShort(), std::string("0")); 83 else if (input.getType() == MT_ushort) 84 return ConvertValue(output, input.getUnsignedShort(), std::string("0")); 85 else if (input.getType() == MT_long) 86 return ConvertValue(output, input.getLong(), std::string("0")); 87 else if (input.getType() == MT_ulong) 88 return ConvertValue(output, input.getUnsignedLong(), std::string("0")); 89 else if (input.getType() == MT_float) 90 return ConvertValue(output, input.getFloat(), std::string("0.000000")); 91 else if (input.getType() == MT_double) 92 return ConvertValue(output, input.getDouble(), std::string("0.000000")); 93 else if (input.getType() == MT_longdouble) 94 return ConvertValue(output, input.getChar(), std::string("0.000000")); 95 else if (input.getType() == MT_bool) 96 { 97 if (input.getBool()) 98 (*output) = "true"; 99 else 100 (*output) = "false"; 101 102 return true; 103 } 104 else if (input.getType() == MT_constchar) 105 { 106 (*output) = "\"" + input.getString() + "\""; 107 return true; 108 } 109 else if (input.getType() == MT_string) 110 { 111 (*output) = "\"" + input.getString() + "\""; 112 return true; 113 } 114 else if (input.getType() == MT_vector2) 115 { 116 std::ostringstream ostream; 117 if (ostream << "(" << input.getVector2().x << "," << input.getVector2().y << ")") 118 { 119 (*output) = ostream.str(); 120 return true; 121 } 122 else 123 { 124 (*output) = "(0,0)"; 125 return false; 126 } 127 } 128 else if (input.getType() == MT_vector3) 129 { 130 std::ostringstream ostream; 131 if (ostream << "(" << input.getVector3().x << "," << input.getVector3().y << "," << input.getVector3().z << ")") 132 { 133 (*output) = ostream.str(); 134 return true; 135 } 136 else 137 { 138 (*output) = "(0,0,0)"; 139 return false; 140 } 141 } 142 else if (input.getType() == MT_colourvalue) 143 { 144 std::ostringstream ostream; 145 if (ostream << "(" << input.getColourValue().r << "," << input.getColourValue().g << "," << input.getColourValue().b << "," << input.getColourValue().a << ")") 146 { 147 (*output) = ostream.str(); 148 return true; 149 } 150 else 151 { 152 (*output) = "(0,0,0,0)"; 153 return false; 154 } 155 } 156 else if (input.getType() == MT_quaternion) 157 { 158 std::ostringstream ostream; 159 if (ostream << "(" << input.getQuaternion().w << "," << input.getQuaternion().x << "," << input.getQuaternion().y << "," << input.getQuaternion().z << ")") 160 { 161 (*output) = ostream.str(); 162 return true; 163 } 164 else 165 { 166 (*output) = "(0,0,0,0)"; 167 return false; 168 } 169 } 170 else if (input.getType() == MT_radian) 171 return ConvertValue(output, input.getRadian(), std::string("0.000000")); 172 else if (input.getType() == MT_degree) 173 return ConvertValue(output, input.getDegree(), std::string("0.000000")); 174 175 return false; 339 176 } 340 177 … … 344 181 @return True if the string was successfully parsed 345 182 */ 346 bool ConfigValueContainer::parseSting(const std::string& input) 347 { 348 if (this->type_ == ConfigValueContainer::VT_Int) 349 return this->parseSting(input, this->value_.value_int_); 350 else if (this->type_ == ConfigValueContainer::VT_uInt) 351 return this->parseSting(input, this->value_.value_uint_); 352 else if (this->type_ == ConfigValueContainer::VT_Char) 353 return this->parseSting(input, this->value_.value_char_); 354 else if (this->type_ == ConfigValueContainer::VT_uChar) 355 return this->parseSting(input, this->value_.value_uchar_); 356 else if (this->type_ == ConfigValueContainer::VT_Float) 357 return this->parseSting(input, this->value_.value_float_); 358 else if (this->type_ == ConfigValueContainer::VT_Double) 359 return this->parseSting(input, this->value_.value_double_); 360 else if (this->type_ == ConfigValueContainer::VT_LongDouble) 361 return this->parseSting(input, this->value_.value_long_double_); 362 else if (this->type_ == ConfigValueContainer::VT_Bool) 363 return this->parseSting(input, this->value_.value_bool_); 364 else if (this->type_ == ConfigValueContainer::VT_String) 365 return this->parseSting(input, this->value_string_); 366 else if (this->type_ == ConfigValueContainer::VT_ConstChar) 367 return this->parseSting(input, this->value_string_); 368 else if (this->type_ == ConfigValueContainer::VT_Vector2) 369 return this->parseSting(input, this->value_vector2_); 370 else if (this->type_ == ConfigValueContainer::VT_Vector3) 371 return this->parseSting(input, this->value_vector3_); 372 else if (this->type_ == ConfigValueContainer::VT_ColourValue) 373 return this->parseSting(input, this->value_colourvalue_); 183 bool ConfigValueContainer::parseString(const std::string& input, MultiTypeMath& defvalue) 184 { 185 if (defvalue.getType() == MT_int) 186 return this->parseString(input, defvalue.getInt()); 187 else if (defvalue.getType() == MT_uint) 188 return this->parseString(input, defvalue.getUnsignedInt()); 189 else if (defvalue.getType() == MT_char) 190 return this->parseString(input, defvalue.getChar()); 191 else if (defvalue.getType() == MT_uchar) 192 return this->parseString(input, defvalue.getUnsignedChar()); 193 else if (defvalue.getType() == MT_short) 194 return this->parseString(input, defvalue.getShort()); 195 else if (defvalue.getType() == MT_ushort) 196 return this->parseString(input, defvalue.getUnsignedShort()); 197 else if (defvalue.getType() == MT_long) 198 return this->parseString(input, defvalue.getLong()); 199 else if (defvalue.getType() == MT_ulong) 200 return this->parseString(input, defvalue.getUnsignedLong()); 201 else if (defvalue.getType() == MT_float) 202 return this->parseString(input, defvalue.getFloat()); 203 else if (defvalue.getType() == MT_double) 204 return this->parseString(input, defvalue.getDouble()); 205 else if (defvalue.getType() == MT_longdouble) 206 return this->parseString(input, defvalue.getLongDouble()); 207 else if (defvalue.getType() == MT_bool) 208 return this->parseString(input, defvalue.getBool()); 209 else if (defvalue.getType() == MT_constchar) 210 return this->parseString(input, defvalue.getString()); 211 else if (defvalue.getType() == MT_string) 212 return this->parseString(input, defvalue.getString()); 213 else if (defvalue.getType() == MT_vector2) 214 return this->parseString(input, defvalue.getVector2()); 215 else if (defvalue.getType() == MT_vector3) 216 return this->parseString(input, defvalue.getVector3()); 217 else if (defvalue.getType() == MT_colourvalue) 218 return this->parseString(input, defvalue.getColourValue()); 219 else if (defvalue.getType() == MT_quaternion) 220 return this->parseString(input, defvalue.getQuaternion()); 221 else if (defvalue.getType() == MT_radian) 222 return this->parseString(input, defvalue.getRadian()); 223 else if (defvalue.getType() == MT_degree) 224 return this->parseString(input, defvalue.getDegree()); 374 225 375 226 return false; … … 382 233 @return True if the string was successfully parsed 383 234 */ 384 bool ConfigValueContainer::parseSting(const std::string& input, int defvalue) 385 { 386 return ConvertValue(&this->value_.value_int_, input, defvalue); 235 bool ConfigValueContainer::parseString(const std::string& input, int defvalue) 236 { 237 int temp; 238 bool success = ConvertValue(&temp, input, defvalue); 239 this->value_.setValue(temp); 240 return success; 387 241 } 388 242 … … 393 247 @return True if the string was successfully parsed 394 248 */ 395 bool ConfigValueContainer::parseSting(const std::string& input, unsigned int defvalue) 396 { 397 return ConvertValue(&this->value_.value_uint_, input, defvalue); 249 bool ConfigValueContainer::parseString(const std::string& input, unsigned int defvalue) 250 { 251 unsigned int temp; 252 bool success = ConvertValue(&temp, input, defvalue); 253 this->value_.setValue(temp); 254 return success; 398 255 } 399 256 … … 404 261 @return True if the string was successfully parsed 405 262 */ 406 bool ConfigValueContainer::parseSt ing(const std::string& input, char defvalue)263 bool ConfigValueContainer::parseString(const std::string& input, char defvalue) 407 264 { 408 265 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 409 return ConvertValue(&this->value_.value_int_, input, (int)defvalue); 266 int temp; 267 bool success = ConvertValue(&temp, input, (int)defvalue); 268 this->value_.setValue((char)temp); 269 return success; 410 270 } 411 271 … … 416 276 @return True if the string was successfully parsed 417 277 */ 418 bool ConfigValueContainer::parseSt ing(const std::string& input, unsigned char defvalue)278 bool ConfigValueContainer::parseString(const std::string& input, unsigned char defvalue) 419 279 { 420 280 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 421 return ConvertValue(&this->value_.value_uint_, input, (unsigned int)defvalue); 281 unsigned int temp; 282 bool success = ConvertValue(&temp, input, (unsigned int)defvalue); 283 this->value_.setValue((unsigned char)temp); 284 return success; 285 } 286 287 /** 288 @brief Parses a given std::string into a value of the type short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 289 @param input The string to convert 290 @param defvalue The default-value 291 @return True if the string was successfully parsed 292 */ 293 bool ConfigValueContainer::parseString(const std::string& input, short defvalue) 294 { 295 short temp; 296 bool success = ConvertValue(&temp, input, defvalue); 297 this->value_.setValue(temp); 298 return success; 299 } 300 301 /** 302 @brief Parses a given std::string into a value of the type unsigned short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 303 @param input The string to convert 304 @param defvalue The default-value 305 @return True if the string was successfully parsed 306 */ 307 bool ConfigValueContainer::parseString(const std::string& input, unsigned short defvalue) 308 { 309 unsigned short temp; 310 bool success = ConvertValue(&temp, input, defvalue); 311 this->value_.setValue(temp); 312 return success; 313 } 314 315 /** 316 @brief Parses a given std::string into a value of the type long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 317 @param input The string to convert 318 @param defvalue The default-value 319 @return True if the string was successfully parsed 320 */ 321 bool ConfigValueContainer::parseString(const std::string& input, long defvalue) 322 { 323 long temp; 324 bool success = ConvertValue(&temp, input, defvalue); 325 this->value_.setValue(temp); 326 return success; 327 } 328 329 /** 330 @brief Parses a given std::string into a value of the type unsigned long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 331 @param input The string to convert 332 @param defvalue The default-value 333 @return True if the string was successfully parsed 334 */ 335 bool ConfigValueContainer::parseString(const std::string& input, unsigned long defvalue) 336 { 337 unsigned long temp; 338 bool success = ConvertValue(&temp, input, defvalue); 339 this->value_.setValue(temp); 340 return success; 422 341 } 423 342 … … 428 347 @return True if the string was successfully parsed 429 348 */ 430 bool ConfigValueContainer::parseSting(const std::string& input, float defvalue) 431 { 432 return ConvertValue(&this->value_.value_float_, input, defvalue); 349 bool ConfigValueContainer::parseString(const std::string& input, float defvalue) 350 { 351 float temp; 352 bool success = ConvertValue(&temp, input, defvalue); 353 this->value_.setValue(temp); 354 return success; 433 355 } 434 356 … … 439 361 @return True if the string was successfully parsed 440 362 */ 441 bool ConfigValueContainer::parseSting(const std::string& input, double defvalue) 442 { 443 return ConvertValue(&this->value_.value_double_, input, defvalue); 363 bool ConfigValueContainer::parseString(const std::string& input, double defvalue) 364 { 365 double temp; 366 bool success = ConvertValue(&temp, input, defvalue); 367 this->value_.setValue(temp); 368 return success; 444 369 } 445 370 … … 450 375 @return True if the string was successfully parsed 451 376 */ 452 bool ConfigValueContainer::parseSting(const std::string& input, long double defvalue) 453 { 454 return ConvertValue(&this->value_.value_long_double_, input, defvalue); 377 bool ConfigValueContainer::parseString(const std::string& input, long double defvalue) 378 { 379 long double temp; 380 bool success = ConvertValue(&temp, input, defvalue); 381 this->value_.setValue(temp); 382 return success; 455 383 } 456 384 … … 461 389 @return True if the string was successfully parsed 462 390 */ 463 bool ConfigValueContainer::parseSt ing(const std::string& input, bool defvalue)391 bool ConfigValueContainer::parseString(const std::string& input, bool defvalue) 464 392 { 465 393 // Try to parse the value-string - is it a word? … … 468 396 || input.find("yes") < input.size() 469 397 || input.find("Yes") < input.size()) 470 this->value_. value_bool_ = true;398 this->value_.setValue(true); 471 399 else if (input.find("false") < input.size() 472 400 || input.find("False") < input.size() 473 401 || input.find("no") < input.size() 474 402 || input.find("No") < input.size()) 475 this->value_. value_bool_ = false;403 this->value_.setValue(false); 476 404 else 477 405 { 478 406 // Its not a known word - is it a number? 479 return ConvertValue(&this->value_.value_bool_, input, defvalue); 407 bool temp; 408 bool success = ConvertValue(&temp, input, defvalue); 409 this->value_.setValue(temp); 410 return success; 480 411 } 481 412 … … 489 420 @return True if the string was successfully parsed 490 421 */ 491 bool ConfigValueContainer::parseSt ing(const std::string& input, const std::string& defvalue)422 bool ConfigValueContainer::parseString(const std::string& input, const std::string& defvalue) 492 423 { 493 424 // Strip the quotes … … 499 430 { 500 431 // It was - get the string between the quotes 501 this->value_ string_ = input.substr(pos1, pos2 - pos1);432 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 502 433 return true; 503 434 } 504 435 505 436 // It wasn't - use the default-value and restore the entry in the config-file. 506 this->value_ string_ = defvalue;437 this->value_.setValue(defvalue); 507 438 return false; 508 439 } … … 514 445 @return True if the string was successfully parsed 515 446 */ 516 bool ConfigValueContainer::parseSt ing(const std::string& input, const char* defvalue)447 bool ConfigValueContainer::parseString(const std::string& input, const char* defvalue) 517 448 { 518 449 // Strip the quotes … … 524 455 { 525 456 // It was - get the string between the quotes 526 this->value_ string_ = input.substr(pos1, pos2 - pos1);457 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 527 458 return true; 528 459 } 529 460 530 461 // It wasn't - use the default-value and restore the entry in the config-file. 531 this->value_ string_ = defvalue;462 this->value_.setValue(defvalue); 532 463 return false; 533 464 } … … 539 470 @return True if the string was successfully parsed 540 471 */ 541 bool ConfigValueContainer::parseSt ing(const std::string& input, const Vector2& defvalue)472 bool ConfigValueContainer::parseString(const std::string& input, const Vector2& defvalue) 542 473 { 543 474 // Strip the value-string … … 549 480 { 550 481 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 551 if (!ConvertValue(&this->value_ vector2_.x, tokens[0]))552 { 553 this->value_ vector2_ = defvalue;554 return false; 555 } 556 if (!ConvertValue(&this->value_ vector2_.y, tokens[1]))557 { 558 this->value_ vector2_ = defvalue;482 if (!ConvertValue(&this->value_.getVector2().x, tokens[0])) 483 { 484 this->value_.setValue(defvalue); 485 return false; 486 } 487 if (!ConvertValue(&this->value_.getVector2().y, tokens[1])) 488 { 489 this->value_.setValue(defvalue); 559 490 return false; 560 491 } … … 563 494 } 564 495 565 this->value_ vector2_ = defvalue;496 this->value_.setValue(defvalue); 566 497 return false; 567 498 } … … 573 504 @return True if the string was successfully parsed 574 505 */ 575 bool ConfigValueContainer::parseSt ing(const std::string& input, const Vector3& defvalue)506 bool ConfigValueContainer::parseString(const std::string& input, const Vector3& defvalue) 576 507 { 577 508 // Strip the value-string … … 583 514 { 584 515 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 585 if (!ConvertValue(&this->value_ vector3_.x, tokens[0]))586 { 587 this->value_ vector3_ = defvalue;588 return false; 589 } 590 if (!ConvertValue(&this->value_ vector3_.y, tokens[1]))591 { 592 this->value_ vector3_ = defvalue;593 return false; 594 } 595 if (!ConvertValue(&this->value_ vector3_.z, tokens[2]))596 { 597 this->value_ vector3_ = defvalue;516 if (!ConvertValue(&this->value_.getVector3().x, tokens[0])) 517 { 518 this->value_.setValue(defvalue); 519 return false; 520 } 521 if (!ConvertValue(&this->value_.getVector3().y, tokens[1])) 522 { 523 this->value_.setValue(defvalue); 524 return false; 525 } 526 if (!ConvertValue(&this->value_.getVector3().z, tokens[2])) 527 { 528 this->value_.setValue(defvalue); 598 529 return false; 599 530 } … … 602 533 } 603 534 604 this->value_ vector3_ = defvalue;535 this->value_.setValue(defvalue); 605 536 return false; 606 537 } … … 612 543 @return True if the string was successfully parsed 613 544 */ 614 bool ConfigValueContainer::parseSt ing(const std::string& input, const ColourValue& defvalue)545 bool ConfigValueContainer::parseString(const std::string& input, const ColourValue& defvalue) 615 546 { 616 547 // Strip the value-string … … 622 553 { 623 554 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 624 if (!ConvertValue(&this->value_ colourvalue_.r, tokens[0]))625 { 626 this->value_ colourvalue_ = defvalue;627 return false; 628 } 629 if (!ConvertValue(&this->value_ colourvalue_.g, tokens[1]))630 { 631 this->value_ colourvalue_ = defvalue;632 return false; 633 } 634 if (!ConvertValue(&this->value_ colourvalue_.b, tokens[2]))635 { 636 this->value_ colourvalue_ = defvalue;637 return false; 638 } 639 if (!ConvertValue(&this->value_ colourvalue_.a, tokens[3]))640 { 641 this->value_ colourvalue_ = defvalue;555 if (!ConvertValue(&this->value_.getColourValue().r, tokens[0])) 556 { 557 this->value_.setValue(defvalue); 558 return false; 559 } 560 if (!ConvertValue(&this->value_.getColourValue().g, tokens[1])) 561 { 562 this->value_.setValue(defvalue); 563 return false; 564 } 565 if (!ConvertValue(&this->value_.getColourValue().b, tokens[2])) 566 { 567 this->value_.setValue(defvalue); 568 return false; 569 } 570 if (!ConvertValue(&this->value_.getColourValue().a, tokens[3])) 571 { 572 this->value_.setValue(defvalue); 642 573 return false; 643 574 } … … 646 577 } 647 578 648 this->value_ colourvalue_ = defvalue;579 this->value_.setValue(defvalue); 649 580 return false; 581 } 582 583 /** 584 @brief Parses a given std::string into a value of the type Quaternion and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 585 @param input The string to convert 586 @param defvalue The default-value 587 @return True if the string was successfully parsed 588 */ 589 bool ConfigValueContainer::parseString(const std::string& input, const Quaternion& defvalue) 590 { 591 // Strip the value-string 592 unsigned int pos1 = input.find("(") + 1; 593 unsigned int pos2 = input.find(")", pos1); 594 595 // Try to convert the stripped value-string to Vector3 596 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 597 { 598 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 599 if (!ConvertValue(&this->value_.getQuaternion().w, tokens[0])) 600 { 601 this->value_.setValue(defvalue); 602 return false; 603 } 604 if (!ConvertValue(&this->value_.getQuaternion().x, tokens[1])) 605 { 606 this->value_.setValue(defvalue); 607 return false; 608 } 609 if (!ConvertValue(&this->value_.getQuaternion().y, tokens[2])) 610 { 611 this->value_.setValue(defvalue); 612 return false; 613 } 614 if (!ConvertValue(&this->value_.getQuaternion().z, tokens[3])) 615 { 616 this->value_.setValue(defvalue); 617 return false; 618 } 619 620 return true; 621 } 622 623 this->value_.setValue(defvalue); 624 return false; 625 } 626 627 /** 628 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 629 @param input The string to convert 630 @param defvalue The default-value 631 @return True if the string was successfully parsed 632 */ 633 bool ConfigValueContainer::parseString(const std::string& input, const Radian& defvalue) 634 { 635 return ConvertValue(&this->value_.getRadian(), input, defvalue); 636 } 637 638 /** 639 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 640 @param input The string to convert 641 @param defvalue The default-value 642 @return True if the string was successfully parsed 643 */ 644 bool ConfigValueContainer::parseString(const std::string& input, const Degree& defvalue) 645 { 646 return ConvertValue(&this->value_.getDegree(), input, defvalue); 650 647 } 651 648 … … 664 661 void ConfigValueContainer::resetConfigValue() 665 662 { 666 this->parseSt ing(this->defvalueString_);663 this->parseString(this->defvalueString_, this->value_); 667 664 this->resetConfigFileEntry(); 668 665 } … … 837 834 838 835 /** 839 @returns a list, containing all entrys in the config-file. 836 @brief Rreturns a list, containing all entrys in the config-file. 837 @return The list 840 838 */ 841 839 std::list<std::string>& ConfigValueContainer::getConfigFileLines() … … 879 877 if (!file.is_open()) 880 878 { 879 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 881 880 COUT(1) << "Error: Couldn't open config-file " << filename << " to read the config values!" << std::endl; 882 881 return; … … 925 924 if (!file.is_open()) 926 925 { 926 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 927 927 COUT(1) << "Error: Couldn't open config-file " << filename << " to write the config values!" << std::endl; 928 928 return; … … 948 948 { 949 949 this->description_ = std::string("ConfigValueDescription::" + this->classname_ + "::" + this->varname_); 950 Language::getLanguage().addEntry(this->description_, description);950 AddLanguageEntry(this->description_, description); 951 951 this->bAddedDescription_ = true; 952 952 } 953 953 } 954 955 /** 956 @brief Returns the description of the config-value. 957 @return The description 958 */ 959 const std::string& ConfigValueContainer::getDescription() const 960 { 961 return GetLocalisation(this->description_); 962 } 954 963 }
Note: See TracChangeset
for help on using the changeset viewer.