Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2010, 2:08:28 PM (14 years ago)
Author:
rgrieder
Message:

Reduced a dependency in util.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/libraries/util/Convert.h

    r6417 r7155  
    6464
    6565    Defining your own functions:
    66     There are obviously 4 ways to specifiy a user defined conversion. What should I use?
     66    There are obviously 4 ways to specify a user defined conversion. What should you use?
    6767
    6868    Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from
     
    7070
    7171    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.
    7374*/
    7475
     
    388389    };
    389390
    390     // Declarations to avoid StringUtils.h include
    391     _UtilExport std::string removeTrailingWhitespaces(const std::string& str);
    392     _UtilExport std::string getLowercase(const std::string& str);
    393 
    394391    // std::string to bool
    395392    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);
    418396    };
    419397}
Note: See TracChangeset for help on using the changeset viewer.