Changeset 7155 for code/branches/presentation3/src/libraries/util/Convert.h
- Timestamp:
- Jul 20, 2010, 2:08:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/libraries/util/Convert.h
r6417 r7155 64 64 65 65 Defining your own functions: 66 There are obviously 4 ways to specif iy a user defined conversion. What should Iuse?66 There are obviously 4 ways to specify a user defined conversion. What should you use? 67 67 68 68 Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from … … 70 70 71 71 However if you want to overwrite an implicit conversion or an iostream operator, you really need to 72 make use of ConverterExplicit. 72 make use of ConverterExplicit. We have to do this for the Ogre classes for instance because they 73 define stream operators we don't particulary like. 73 74 */ 74 75 … … 388 389 }; 389 390 390 // Declarations to avoid StringUtils.h include391 _UtilExport std::string removeTrailingWhitespaces(const std::string& str);392 _UtilExport std::string getLowercase(const std::string& str);393 394 391 // std::string to bool 395 392 template <> 396 struct ConverterExplicit<std::string, bool> 397 { 398 static bool convert(bool* output, const std::string& input) 399 { 400 const std::string& stripped = getLowercase(removeTrailingWhitespaces(input)); 401 if (stripped == "true" || stripped == "on" || stripped == "yes") 402 { 403 *output = true; 404 return true; 405 } 406 else if (stripped == "false" || stripped == "off" || stripped == "no") 407 { 408 *output = false; 409 return true; 410 } 411 412 std::istringstream iss(input); 413 if (iss >> (*output)) 414 return true; 415 else 416 return false; 417 } 393 struct _UtilExport ConverterExplicit<std::string, bool> 394 { 395 static bool convert(bool* output, const std::string& input); 418 396 }; 419 397 }
Note: See TracChangeset
for help on using the changeset viewer.