Changeset 1595 for code/branches/hud/src/util/Convert.h
- Timestamp:
- Jun 12, 2008, 10:42:15 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/util/Convert.h
r1588 r1595 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 … … 320 321 } 321 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 } 322 330 323 331 … … 411 419 //////////////////// 412 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 413 436 // Vector2 to std::string 414 437 template <> … … 501 524 //////////////////// 502 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 503 553 // std::string to Vector2 504 554 template <>
Note: See TracChangeset
for help on using the changeset viewer.