Changeset 1625 for code/trunk/src/util/Convert.h
- Timestamp:
- Jun 26, 2008, 2:13:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/util/Convert.h
r1505 r1625 43 43 #include "SubString.h" 44 44 #include "MultiTypeMath.h" 45 #include "String.h" 45 46 46 47 // disable annoying warning about forcing value to boolean … … 299 300 }; 300 301 302 // convert to string Shortcut 303 template <class FromType> 304 std::string convertToString(FromType value) 305 { 306 return getConvertedValue<FromType, std::string>(value); 307 } 308 301 309 // convert from string 302 310 template <class ToType> … … 313 321 } 314 322 }; 323 324 // convert from string Shortcut 325 template <class ToType> 326 ToType convertFromString(std::string str) 327 { 328 return getConvertedValue<std::string, ToType>(str); 329 } 315 330 316 331 … … 404 419 //////////////////// 405 420 421 // bool to std::string 422 template <> 423 struct ConverterSpecialized<bool, std::string, _Explicit_> 424 { 425 enum { specialized = true }; 426 static bool convert(std::string* output, const bool& input) 427 { 428 if (input) 429 *output = "true"; 430 else 431 *output = "false"; 432 return false; 433 } 434 }; 435 406 436 // Vector2 to std::string 407 437 template <> … … 494 524 //////////////////// 495 525 526 // std::string to bool 527 template <> 528 struct ConverterSpecialized<std::string, bool, _Explicit_> 529 { 530 enum { specialized = true }; 531 static bool convert(bool* output, const std::string& input) 532 { 533 std::string stripped = getLowercase(removeTrailingWhitespaces(input)); 534 if (stripped == "true" || stripped == "on" || stripped == "yes") 535 { 536 *output = true; 537 return true; 538 } 539 else if (stripped == "false" || stripped == "off" || stripped == "no") 540 { 541 *output = false; 542 return true; 543 } 544 545 std::istringstream iss(input); 546 if (iss >> (*output)) 547 return true; 548 else 549 return false; 550 } 551 }; 552 496 553 // std::string to Vector2 497 554 template <> … … 611 668 612 669 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 613 if (tokens.size() >= 4)670 if (tokens.size() >= 3) 614 671 { 615 672 if (!ConvertValue(&(output->r), tokens[0])) … … 619 676 if (!ConvertValue(&(output->b), tokens[2])) 620 677 return false; 621 if (!ConvertValue(&(output->a), tokens[3])) 622 return false; 678 if (tokens.size() >= 4) 679 { 680 if (!ConvertValue(&(output->a), tokens[3])) 681 return false; 682 } 683 else 684 output->a = 1.0; 623 685 624 686 return true;
Note: See TracChangeset
for help on using the changeset viewer.