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/Convert.h

    r1588 r1595  
    4343#include "SubString.h"
    4444#include "MultiTypeMath.h"
     45#include "String.h"
    4546
    4647// disable annoying warning about forcing value to boolean
     
    320321    }
    321322};
     323
     324// convert from string Shortcut
     325template <class ToType>
     326ToType convertFromString(std::string str)
     327{
     328  return getConvertedValue<std::string, ToType>(str);
     329}
    322330
    323331
     
    411419////////////////////
    412420
     421// bool to std::string
     422template <>
     423struct 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
    413436// Vector2 to std::string
    414437template <>
     
    501524////////////////////
    502525
     526// std::string to bool
     527template <>
     528struct 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
    503553// std::string to Vector2
    504554template <>
Note: See TracChangeset for help on using the changeset viewer.