Changeset 703 for code/branches/FICN
- Timestamp:
- Dec 27, 2007, 9:38:55 PM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox/core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/core/ConfigValueContainer.cc
r698 r703 49 49 this->type_ = Int; 50 50 51 this->defvalueString_ = number2String(defvalue, "0"); // Try to convert the default-value to a string52 this->searchConfigFileLine(); // Search the entry in the config-file53 54 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry55 if (! string2Number(this->value_.value_int_, valueString, defvalue))// Try to convert the string to a value56 this-> setConfigFileEntyToDefault();// The conversion failed51 this->defvalueString_ = number2String(defvalue, "0"); // Try to convert the default-value to a string 52 this->searchConfigFileLine(); // Search the entry in the config-file 53 54 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 55 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 56 this->resetConfigFileEntry(); // The conversion failed 57 57 } 58 58 … … 70 70 this->type_ = uInt; 71 71 72 this->defvalueString_ = number2String(defvalue, "0"); // Try to convert the default-value to a string73 this->searchConfigFileLine(); // Search the entry in the config-file74 75 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry76 if (! string2Number(this->value_.value_uint_, valueString, defvalue))// Try to convert the string to a value77 this-> setConfigFileEntyToDefault();// The conversion failed72 this->defvalueString_ = number2String(defvalue, "0"); // Try to convert the default-value to a string 73 this->searchConfigFileLine(); // Search the entry in the config-file 74 75 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 76 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 77 this->resetConfigFileEntry(); // The conversion failed 78 78 } 79 79 … … 91 91 this->type_ = Char; 92 92 93 this->defvalueString_ = number2String((int)defvalue, "0"); // Try to convert the default-value to a string 94 this->searchConfigFileLine(); // Search the entry in the config-file 95 96 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 97 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 98 if (!string2Number(this->value_.value_int_, valueString, (int)defvalue))// Try to convert the string to a value 99 this->setConfigFileEntyToDefault(); // The conversion failed 93 this->defvalueString_ = number2String((int)defvalue, "0"); // Try to convert the default-value to a string 94 this->searchConfigFileLine(); // Search the entry in the config-file 95 96 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 97 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 98 this->resetConfigFileEntry(); // The conversion failed 100 99 } 101 100 … … 113 112 this->type_ = uChar; 114 113 115 this->defvalueString_ = number2String((unsigned int)defvalue, "0"); // Try to convert the default-value to a string 116 this->searchConfigFileLine(); // Search the entry in the config-file 117 118 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 119 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 120 if (!string2Number(this->value_.value_uint_, valueString, (unsigned int)defvalue)) // Try to convert the string to a value 121 this->setConfigFileEntyToDefault(); // The conversion failed 114 this->defvalueString_ = number2String((unsigned int)defvalue, "0"); // Try to convert the default-value to a string 115 this->searchConfigFileLine(); // Search the entry in the config-file 116 117 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 118 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 119 this->resetConfigFileEntry(); // The conversion failed 122 120 } 123 121 … … 135 133 this->type_ = Float; 136 134 137 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string138 this->searchConfigFileLine(); // Search the entry in the config-file139 140 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry141 if (! string2Number(this->value_.value_float_, valueString, defvalue))// Try to convert the string to a value142 this-> setConfigFileEntyToDefault();// The conversion failed135 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string 136 this->searchConfigFileLine(); // Search the entry in the config-file 137 138 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 139 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 140 this->resetConfigFileEntry(); // The conversion failed 143 141 } 144 142 … … 156 154 this->type_ = Double; 157 155 158 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string 159 this->searchConfigFileLine(); // Search the entry in the config-file 160 161 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 162 if (!string2Number(this->value_.value_double_, valueString, defvalue)) // Try to convert the string to a value 163 this->setConfigFileEntyToDefault(); // The conversion failed 156 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string 157 this->searchConfigFileLine(); // Search the entry in the config-file 158 159 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 160 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 161 this->resetConfigFileEntry(); // The conversion failed 162 } 163 164 /** 165 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 166 @param value This is only needed to determine the right type. 167 @param classname The name of the class the variable belongs to 168 @param varname The name of the variable 169 @param defvalue The default-value 170 */ 171 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue) 172 { 173 this->classname_ = classname; 174 this->varname_ = varname; 175 this->type_ = LongDouble; 176 177 this->defvalueString_ = number2String(defvalue, "0.000000"); // Try to convert the default-value to a string 178 this->searchConfigFileLine(); // Search the entry in the config-file 179 180 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 181 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 182 this->resetConfigFileEntry(); // The conversion failed 164 183 } 165 184 … … 183 202 this->defvalueString_ = "false"; 184 203 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 189 // Try to parse the value-string - is it a word? 190 if (valueString.find("true") < valueString.size() 191 || valueString.find("True") < valueString.size() 192 || valueString.find("yes") < valueString.size() 193 || valueString.find("Yes") < valueString.size()) 194 this->value_.value_bool_ = true; 195 else if (valueString.find("false") < valueString.size() 196 || valueString.find("False") < valueString.size() 197 || valueString.find("no") < valueString.size() 198 || valueString.find("No") < valueString.size()) 199 this->value_.value_bool_ = false; 200 else 201 { 202 // Its not a known word - is it a number? 203 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 204 if (!string2Number(this->value_.value_bool_, valueString, defvalue)) // Try to convert the string to a value 205 this->setConfigFileEntyToDefault(); // The conversion failed 206 } 204 this->searchConfigFileLine(); // Search the entry in the config-file 205 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 206 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 207 this->resetConfigFileEntry(); // The conversion failed 207 208 } 208 209 … … 220 221 this->type_ = String; 221 222 222 this->defvalueString_ = "\"" + defvalue + "\""; // Convert the string to a "config-file-string" with quotes 223 224 this->searchConfigFileLine(); // Search the entry in the config-file 225 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 226 227 // Strip the quotes 228 unsigned int pos1 = valueString.find("\"") + 1; 229 unsigned int pos2 = valueString.find("\"", pos1); 230 231 // Check if the entry was correctly quoted 232 if (pos1 < valueString.length() && pos2 < valueString.length() && !(valueString.find("\"", pos2 + 1) < valueString.length())) 233 { 234 // It was - get the string between the quotes 235 valueString = valueString.substr(pos1, pos2 - pos1); 236 this->value_string_ = valueString; 237 } 238 else 239 { 240 // It wasn't - use the default-value and restore the entry in the config-file. 241 this->value_string_ = defvalue; 242 this->setConfigFileEntyToDefault(); 243 } 223 this->defvalueString_ = "\"" + defvalue + "\""; // Convert the string to a "config-file-string" with quotes 224 this->searchConfigFileLine(); // Search the entry in the config-file 225 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 226 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 227 this->resetConfigFileEntry(); // The conversion failed 244 228 } 245 229 … … 257 241 this->type_ = ConstChar; 258 242 259 this->defvalueString_ = "\"" + std::string(defvalue) + "\""; // Convert the string to a "config-file-string" with quotes 260 261 this->searchConfigFileLine(); // Search the entry in the config-file 262 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 263 264 // Strip the quotes 265 unsigned int pos1 = valueString.find("\"") + 1; 266 unsigned int pos2 = valueString.find("\"", pos1); 267 268 // Check if the entry was correctly quoted 269 if (pos1 < valueString.length() && pos2 < valueString.length() && !(valueString.find("\"", pos2 + 1) < valueString.length())) 270 { 271 // It was - get the string between the quotes 272 valueString = valueString.substr(pos1, pos2 - pos1); 273 this->value_string_ = valueString; 274 } 275 else 276 { 277 // It wasn't - use the default-value and restore the entry in the config-file. 278 this->value_string_ = defvalue; 279 this->setConfigFileEntyToDefault(); 280 } 243 this->defvalueString_ = "\"" + std::string(defvalue) + "\""; // Convert the string to a "config-file-string" with quotes 244 this->searchConfigFileLine(); // Search the entry in the config-file 245 std::string valueString = this->parseValueString(false); // Parses the value string from the config-file-entry 246 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 247 this->resetConfigFileEntry(); // The conversion failed 281 248 } 282 249 … … 301 268 this->defvalueString_ = "(0,0)"; 302 269 303 this->searchConfigFileLine(); // Search the entry in the config-file 304 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 305 306 // Strip the value-string 307 unsigned int pos1 = valueString.find("(") + 1; 308 unsigned int pos2 = valueString.find(")", pos1); 309 310 // Try to convert the stripped value-string to Vector2 311 if (pos1 < valueString.length() && pos2 < valueString.length() && pos1 < pos2) 312 { 313 valueString = valueString.substr(pos1, pos2 - pos1); 314 std::vector<std::string> tokens = tokenize(valueString, ","); 315 if (!string2Number(this->value_vector2_.x, tokens[0], defvalue.x)) 316 this->setConfigFileEntyToDefault(); 317 if (!string2Number(this->value_vector2_.y, tokens[1], defvalue.y)) 318 this->setConfigFileEntyToDefault(); 319 } 320 else 321 { 322 this->value_vector2_ = defvalue; 323 this->setConfigFileEntyToDefault(); 324 } 270 this->searchConfigFileLine(); // Search the entry in the config-file 271 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 272 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 273 this->resetConfigFileEntry(); // The conversion failed 325 274 } 326 275 … … 345 294 this->defvalueString_ = "(0,0,0)"; 346 295 347 this->searchConfigFileLine(); // Search the entry in the config-file 348 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 349 350 // Strip the value-string 351 unsigned int pos1 = valueString.find("(") + 1; 352 unsigned int pos2 = valueString.find(")", pos1); 353 354 // Try to convert the stripped value-string to Vector3 355 if (pos1 < valueString.length() && pos2 < valueString.length() && pos1 < pos2) 356 { 357 valueString = valueString.substr(pos1, pos2 - pos1); 358 std::vector<std::string> tokens = tokenize(valueString, ","); 359 if (!string2Number(this->value_vector3_.x, tokens[0], defvalue.x)) 360 this->setConfigFileEntyToDefault(); 361 if (!string2Number(this->value_vector3_.y, tokens[1], defvalue.y)) 362 this->setConfigFileEntyToDefault(); 363 if (!string2Number(this->value_vector3_.z, tokens[2], defvalue.z)) 364 this->setConfigFileEntyToDefault(); 365 } 366 else 367 { 368 this->value_vector3_ = defvalue; 369 this->setConfigFileEntyToDefault(); 370 } 296 this->searchConfigFileLine(); // Search the entry in the config-file 297 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 298 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 299 this->resetConfigFileEntry(); // The conversion failed 371 300 } 372 301 … … 391 320 this->defvalueString_ = "(0,0,0,0)"; 392 321 393 this->searchConfigFileLine(); // Search the entry in the config-file 394 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 395 322 this->searchConfigFileLine(); // Search the entry in the config-file 323 std::string valueString = this->parseValueString(); // Parses the value string from the config-file-entry 324 if (!this->parseSting(valueString, defvalue)) // Try to convert the string to a value 325 this->resetConfigFileEntry(); // The conversion failed 326 } 327 328 /** 329 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 330 @param input The string to convert 331 @return True if the string was successfully parsed 332 */ 333 bool ConfigValueContainer::parseSting(const std::string& input) 334 { 335 if (this->type_ == ConfigValueContainer::Int) 336 return this->parseSting(input, this->value_.value_int_); 337 else if (this->type_ == ConfigValueContainer::uInt) 338 return this->parseSting(input, this->value_.value_uint_); 339 else if (this->type_ == ConfigValueContainer::Char) 340 return this->parseSting(input, this->value_.value_char_); 341 else if (this->type_ == ConfigValueContainer::uChar) 342 return this->parseSting(input, this->value_.value_uchar_); 343 else if (this->type_ == ConfigValueContainer::Float) 344 return this->parseSting(input, this->value_.value_float_); 345 else if (this->type_ == ConfigValueContainer::Double) 346 return this->parseSting(input, this->value_.value_double_); 347 else if (this->type_ == ConfigValueContainer::LongDouble) 348 return this->parseSting(input, this->value_.value_long_double_); 349 else if (this->type_ == ConfigValueContainer::Bool) 350 return this->parseSting(input, this->value_.value_bool_); 351 else if (this->type_ == ConfigValueContainer::String) 352 return this->parseSting(input, this->value_string_); 353 else if (this->type_ == ConfigValueContainer::ConstChar) 354 return this->parseSting(input, this->value_string_); 355 else if (this->type_ == ConfigValueContainer::Vector2) 356 return this->parseSting(input, this->value_vector2_); 357 else if (this->type_ == ConfigValueContainer::Vector3) 358 return this->parseSting(input, this->value_vector3_); 359 else if (this->type_ == ConfigValueContainer::ColourValue) 360 return this->parseSting(input, this->value_colourvalue_); 361 362 return false; 363 } 364 365 /** 366 @brief Parses a given std::string into a value of the type int and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 367 @param input The string to convert 368 @param defvalue The default-value 369 @return True if the string was successfully parsed 370 */ 371 bool ConfigValueContainer::parseSting(const std::string& input, int defvalue) 372 { 373 return string2Number(this->value_.value_int_, input, defvalue); 374 } 375 376 /** 377 @brief Parses a given std::string into a value of the type unsigned int and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 378 @param input The string to convert 379 @param defvalue The default-value 380 @return True if the string was successfully parsed 381 */ 382 bool ConfigValueContainer::parseSting(const std::string& input, unsigned int defvalue) 383 { 384 return string2Number(this->value_.value_uint_, input, defvalue); 385 } 386 387 /** 388 @brief Parses a given std::string into a value of the type char and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 389 @param input The string to convert 390 @param defvalue The default-value 391 @return True if the string was successfully parsed 392 */ 393 bool ConfigValueContainer::parseSting(const std::string& input, char defvalue) 394 { 395 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 396 return string2Number(this->value_.value_int_, input, (int)defvalue); 397 } 398 399 /** 400 @brief Parses a given std::string into a value of the type unsigned char and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 401 @param input The string to convert 402 @param defvalue The default-value 403 @return True if the string was successfully parsed 404 */ 405 bool ConfigValueContainer::parseSting(const std::string& input, unsigned char defvalue) 406 { 407 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 408 return string2Number(this->value_.value_uint_, input, (unsigned int)defvalue); 409 } 410 411 /** 412 @brief Parses a given std::string into a value of the type float and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 413 @param input The string to convert 414 @param defvalue The default-value 415 @return True if the string was successfully parsed 416 */ 417 bool ConfigValueContainer::parseSting(const std::string& input, float defvalue) 418 { 419 return string2Number(this->value_.value_float_, input, defvalue); 420 } 421 422 /** 423 @brief Parses a given std::string into a value of the type double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 424 @param input The string to convert 425 @param defvalue The default-value 426 @return True if the string was successfully parsed 427 */ 428 bool ConfigValueContainer::parseSting(const std::string& input, double defvalue) 429 { 430 return string2Number(this->value_.value_double_, input, defvalue); 431 } 432 433 /** 434 @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. 435 @param input The string to convert 436 @param defvalue The default-value 437 @return True if the string was successfully parsed 438 */ 439 bool ConfigValueContainer::parseSting(const std::string& input, long double defvalue) 440 { 441 return string2Number(this->value_.value_long_double_, input, defvalue); 442 } 443 444 /** 445 @brief Parses a given std::string into a value of the type bool and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 446 @param input The string to convert 447 @param defvalue The default-value 448 @return True if the string was successfully parsed 449 */ 450 bool ConfigValueContainer::parseSting(const std::string& input, bool defvalue) 451 { 452 // Try to parse the value-string - is it a word? 453 if (input.find("true") < input.size() 454 || input.find("True") < input.size() 455 || input.find("yes") < input.size() 456 || input.find("Yes") < input.size()) 457 this->value_.value_bool_ = true; 458 else if (input.find("false") < input.size() 459 || input.find("False") < input.size() 460 || input.find("no") < input.size() 461 || input.find("No") < input.size()) 462 this->value_.value_bool_ = false; 463 else 464 { 465 // Its not a known word - is it a number? 466 return string2Number(this->value_.value_bool_, input, defvalue); 467 } 468 469 return true; 470 } 471 472 /** 473 @brief Parses a given std::string into a value of the type std::string and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 474 @param input The string to convert 475 @param defvalue The default-value 476 @return True if the string was successfully parsed 477 */ 478 bool ConfigValueContainer::parseSting(const std::string& input, const std::string& defvalue) 479 { 480 // Strip the quotes 481 unsigned int pos1 = input.find("\"") + 1; 482 unsigned int pos2 = input.find("\"", pos1); 483 484 // Check if the entry was correctly quoted 485 if (pos1 < input.length() && pos2 < input.length() && !(input.find("\"", pos2 + 1) < input.length())) 486 { 487 // It was - get the string between the quotes 488 this->value_string_ = input.substr(pos1, pos2 - pos1); 489 return true; 490 } 491 492 // It wasn't - use the default-value and restore the entry in the config-file. 493 this->value_string_ = defvalue; 494 return false; 495 } 496 497 /** 498 @brief Parses a given std::string into a value of the type const char* and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 499 @param input The string to convert 500 @param defvalue The default-value 501 @return True if the string was successfully parsed 502 */ 503 bool ConfigValueContainer::parseSting(const std::string& input, const char* defvalue) 504 { 505 // Strip the quotes 506 unsigned int pos1 = input.find("\"") + 1; 507 unsigned int pos2 = input.find("\"", pos1); 508 509 // Check if the entry was correctly quoted 510 if (pos1 < input.length() && pos2 < input.length() && !(input.find("\"", pos2 + 1) < input.length())) 511 { 512 // It was - get the string between the quotes 513 this->value_string_ = input.substr(pos1, pos2 - pos1); 514 return true; 515 } 516 517 // It wasn't - use the default-value and restore the entry in the config-file. 518 this->value_string_ = defvalue; 519 return false; 520 } 521 522 /** 523 @brief Parses a given std::string into a value of the type Ogre::Vector2 and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 524 @param input The string to convert 525 @param defvalue The default-value 526 @return True if the string was successfully parsed 527 */ 528 bool ConfigValueContainer::parseSting(const std::string& input, const Ogre::Vector2& defvalue) 529 { 396 530 // Strip the value-string 397 unsigned int pos1 = valueString.find("(") + 1; 398 unsigned int pos2 = valueString.find(")", pos1); 531 unsigned int pos1 = input.find("(") + 1; 532 unsigned int pos2 = input.find(")", pos1); 533 534 // Try to convert the stripped value-string to Vector2 535 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 536 { 537 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 538 if (!string2Number(this->value_vector2_.x, tokens[0], defvalue.x)) 539 { 540 this->value_vector2_ = defvalue; 541 return false; 542 } 543 if (!string2Number(this->value_vector2_.y, tokens[1], defvalue.y)) 544 { 545 this->value_vector2_ = defvalue; 546 return false; 547 } 548 549 return true; 550 } 551 552 this->value_vector2_ = defvalue; 553 return false; 554 } 555 556 /** 557 @brief Parses a given std::string into a value of the type Ogre::Vector3 and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 558 @param input The string to convert 559 @param defvalue The default-value 560 @return True if the string was successfully parsed 561 */ 562 bool ConfigValueContainer::parseSting(const std::string& input, const Ogre::Vector3& defvalue) 563 { 564 // Strip the value-string 565 unsigned int pos1 = input.find("(") + 1; 566 unsigned int pos2 = input.find(")", pos1); 399 567 400 568 // Try to convert the stripped value-string to Vector3 401 if (pos1 < valueString.length() && pos2 < valueString.length() && pos1 < pos2) 402 { 403 valueString = valueString.substr(pos1, pos2 - pos1); 404 std::vector<std::string> tokens = tokenize(valueString, ","); 569 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 570 { 571 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 572 if (!string2Number(this->value_vector3_.x, tokens[0], defvalue.x)) 573 { 574 this->value_vector3_ = defvalue; 575 return false; 576 } 577 if (!string2Number(this->value_vector3_.y, tokens[1], defvalue.y)) 578 { 579 this->value_vector3_ = defvalue; 580 return false; 581 } 582 if (!string2Number(this->value_vector3_.z, tokens[2], defvalue.z)) 583 { 584 this->value_vector3_ = defvalue; 585 return false; 586 } 587 588 return true; 589 } 590 591 this->value_vector3_ = defvalue; 592 return false; 593 } 594 595 /** 596 @brief Parses a given std::string into a value of the type Ogre::ColourValue and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 597 @param input The string to convert 598 @param defvalue The default-value 599 @return True if the string was successfully parsed 600 */ 601 bool ConfigValueContainer::parseSting(const std::string& input, const Ogre::ColourValue& defvalue) 602 { 603 // Strip the value-string 604 unsigned int pos1 = input.find("(") + 1; 605 unsigned int pos2 = input.find(")", pos1); 606 607 // Try to convert the stripped value-string to Vector3 608 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 609 { 610 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 405 611 if (!string2Number(this->value_colourvalue_.r, tokens[0], defvalue.r)) 406 this->setConfigFileEntyToDefault(); 612 { 613 this->value_colourvalue_ = defvalue; 614 return false; 615 } 407 616 if (!string2Number(this->value_colourvalue_.g, tokens[1], defvalue.g)) 408 this->setConfigFileEntyToDefault(); 617 { 618 this->value_colourvalue_ = defvalue; 619 return false; 620 } 409 621 if (!string2Number(this->value_colourvalue_.b, tokens[2], defvalue.b)) 410 this->setConfigFileEntyToDefault(); 622 { 623 this->value_colourvalue_ = defvalue; 624 return false; 625 } 411 626 if (!string2Number(this->value_colourvalue_.a, tokens[3], defvalue.a)) 412 this->setConfigFileEntyToDefault(); 413 } 414 else 415 { 416 this->value_colourvalue_ = defvalue; 417 this->setConfigFileEntyToDefault(); 418 } 419 } 420 421 /** 422 @brief Sets the corresponding enty in the config-file back to the default value. 423 */ 424 void ConfigValueContainer::setConfigFileEntyToDefault() 627 { 628 this->value_colourvalue_ = defvalue; 629 return false; 630 } 631 632 return true; 633 } 634 635 this->value_colourvalue_ = defvalue; 636 return false; 637 } 638 639 /** 640 @brief Sets the corresponding entry in the config-file back to the default value. 641 */ 642 void ConfigValueContainer::resetConfigFileEntry() 425 643 { 426 644 (*this->configFileLine_) = this->varname_ + "=" + this->defvalueString_; … … 428 646 } 429 647 648 /** 649 @brief Sets the value of the variable back to the default value. 650 */ 651 void ConfigValueContainer::resetConfigValue() 652 { 653 parseSting(this->defvalueString_); 654 } 430 655 431 656 /** -
code/branches/FICN/src/orxonox/core/ConfigValueContainer.h
r698 r703 73 73 { 74 74 public: 75 enum VariableType 76 { 77 Int, 78 uInt, 79 Char, 80 uChar, 81 Float, 82 Double, 83 LongDouble, 84 Bool, 85 ConstChar, 86 String, 87 Vector2, 88 Vector3, 89 ColourValue 90 }; 91 75 92 ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue); 76 93 ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue); … … 79 96 ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue); 80 97 ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue); 98 ConfigValueContainer(const std::string& classname, const std::string& varname, long double defvalue); 81 99 ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue); 82 100 ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue); … … 85 103 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue); 86 104 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue); 87 88 static std::list<std::string>& getConfigFileLines();89 static bool finishedReadingConfigFile(bool finished = false);90 void setConfigFileEntyToDefault();91 void searchConfigFileLine();92 std::string parseValueString(bool bStripped = true);93 94 static std::string getStrippedLine(const std::string& line);95 static bool isEmpty(const std::string& line);96 static bool isComment(const std::string& line);97 static void readConfigFile(const std::string& filename);98 static void writeConfigFile(const std::string& filename);99 105 100 106 /** @returns the value. @param value This is only needed to determine the right type. */ … … 111 117 inline double getValue(double value) { return this->value_.value_double_; } 112 118 /** @returns the value. @param value This is only needed to determine the right type. */ 119 inline double getValue(long double value) { return this->value_.value_long_double_; } 120 /** @returns the value. @param value This is only needed to determine the right type. */ 113 121 inline bool getValue(bool value) { return this->value_.value_bool_; } 114 122 /** @returns the value. @param value This is only needed to determine the right type. */ … … 123 131 inline Ogre::ColourValue getValue(const Ogre::ColourValue& value) { return this->value_colourvalue_; } 124 132 133 bool parseSting(const std::string& input); 134 void resetConfigFileEntry(); 135 void resetConfigValue(); 136 125 137 private: 138 bool parseSting(const std::string& input, int defvalue); 139 bool parseSting(const std::string& input, unsigned int defvalue); 140 bool parseSting(const std::string& input, char defvalue); 141 bool parseSting(const std::string& input, unsigned char defvalue); 142 bool parseSting(const std::string& input, float defvalue); 143 bool parseSting(const std::string& input, double defvalue); 144 bool parseSting(const std::string& input, long double defvalue); 145 bool parseSting(const std::string& input, bool defvalue); 146 bool parseSting(const std::string& input, const std::string& defvalue); 147 bool parseSting(const std::string& input, const char* defvalue); 148 bool parseSting(const std::string& input, const Ogre::Vector2& defvalue); 149 bool parseSting(const std::string& input, const Ogre::Vector3& defvalue); 150 bool parseSting(const std::string& input, const Ogre::ColourValue& defvalue); 151 152 static std::list<std::string>& getConfigFileLines(); 153 static bool finishedReadingConfigFile(bool finished = false); 154 void searchConfigFileLine(); 155 std::string parseValueString(bool bStripped = true); 156 157 static std::string getStrippedLine(const std::string& line); 158 static bool isEmpty(const std::string& line); 159 static bool isComment(const std::string& line); 160 static void readConfigFile(const std::string& filename); 161 static void writeConfigFile(const std::string& filename); 162 126 163 std::string classname_; //!< The name of the class the variable belongs to 127 164 std::string varname_; //!< The name of the variable … … 136 173 float value_float_; //!< The value, if the variable is of the type float 137 174 double value_double_; //!< The value, if the variable is of the type double 175 long double value_long_double_; //!< The value, if the variable is of the type long double 138 176 bool value_bool_; //!< The value, if the variable is of the type bool 139 177 } value_; //!< The value of the variable … … 146 184 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 147 185 148 enum VariableType 149 { 150 Int, 151 uInt, 152 Char, 153 uChar, 154 Float, 155 Double, 156 Bool, 157 ConstChar, 158 String, 159 Vector2, 160 Vector3, 161 ColourValue 162 } type_; //!< The type of the variable 186 VariableType type_; //!< The type of the variable 163 187 }; 164 188 } -
code/branches/FICN/src/orxonox/core/CoreIncludes.h
r682 r703 143 143 varname = container##varname->getValue(varname) 144 144 145 /** 146 @brief Sets the variable back to the previously defined default-value. 147 @param varname The name of the variable 148 */ 149 #define ResetConfigValue(varname) \ 150 orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \ 151 if (container##varname##reset) \ 152 { \ 153 container##varname##reset->resetConfigValue(); \ 154 varname = container##varname->getValue(varname); \ 155 } \ 156 else \ 157 COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl 158 145 159 #endif /* _CoreIncludes_H__ */
Note: See TracChangeset
for help on using the changeset viewer.