Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 12, 2008, 10:42:15 PM (16 years ago)
Author:
rgrieder
Message:
  • removed conversion functions in String.h
  • you can use convertToString and convertFromString from Convert.h as shortcuts
  • added "true", "false", "on", "off", "yes" and "no" as boolean values to the Converter
  • Conversion bool —> string newly gives "true" or "false"
  • HUDOverlay can deal with the aspect ratio, e.g. circles stay circles when resizing
  • the rest isn't yet finished: svn save ;)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud/src/util/String.h

    r1505 r1595  
    7070_UtilExport unsigned int getNextCommentPosition(const std::string& str, unsigned int start = 0);
    7171
    72 //! The Convert class has some static member functions to convert strings to values and values to strings.
    73 class _UtilExport Convert
    74 {
    75     public:
    76         /**
    77             @brief Converts a value of any type to a string.
    78             @param output The string to write the result in
    79             @param input The variable to convert
    80             @return True if the conversion succeded
    81 
    82             @example
    83             float f = 3.14;
    84             std::string output;
    85             bool success = Convert::ToString(&output, f);
    86         */
    87         template <typename T>
    88         static bool ToString(std::string* output, T input)
    89         {
    90             std::ostringstream oss;
    91             if (oss << input)
    92             {
    93                 (*output) = oss.str();
    94                 return true;
    95             }
    96 
    97             return false;
    98         }
    99 
    100         /**
    101             @brief Converts a value of any type to a string and assigns a defaultvalue if the conversion fails.
    102             @param output The string to write the result in
    103             @param input The variable to convert
    104             @param fallbackString The assigned string if the conversion fails.
    105             @return True if the conversion succeeded
    106 
    107             @example
    108             float f = 3.14;
    109             std::string output;
    110             bool success = Convert::ToString(&output, f, "0.000000");
    111         */
    112         template <typename T>
    113         static bool ToString(std::string* output, T input, const std::string& fallbackString)
    114         {
    115             if (Convert::ToString(output, input))
    116                 return true;
    117 
    118             (*output) = fallbackString;
    119             return false;
    120         }
    121 
    122         /**
    123             @brief Converts a string to a value of any type.
    124             @param output The variable to assign the result to
    125             @param input The string to convert
    126             @return True if the conversion succeeded
    127 
    128             @example
    129             std::string input = "3.14";
    130             float f;
    131             bool success = string2Number(&f, input);
    132         */
    133         template <typename T>
    134         static bool FromString(T* output, const std::string& input)
    135         {
    136             std::istringstream iss(input);
    137             if (iss >> (*output))
    138                 return true;
    139 
    140             return false;
    141         }
    142 
    143         /**
    144             @brief Converts a string to a value of any type.
    145             @param output The variable to assign the result to
    146             @param input The string to convert
    147             @param fallbackValue The assigned value if the conversion fails
    148             @return True if the conversion succeeded
    149 
    150             @example
    151             std::string input = "3.14";
    152             float f;
    153             bool success = string2Number(&f, input, 0.000000);
    154         */
    155         template <typename T>
    156         static bool FromString(T* output, const std::string& input, T fallbackValue)
    157         {
    158             if (Convert::FromString(output, input))
    159                 return true;
    160 
    161             (*output) = fallbackValue;
    162             return false;
    163         }
    164 };
    165 
    16672#endif /* _Util_String_H__ */
Note: See TracChangeset for help on using the changeset viewer.