Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 26, 2008, 2:13:17 PM (16 years ago)
Author:
rgrieder
Message:

merged hud branch back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/util/Convert.h

    r1505 r1625  
    4343#include "SubString.h"
    4444#include "MultiTypeMath.h"
     45#include "String.h"
    4546
    4647// disable annoying warning about forcing value to boolean
     
    299300};
    300301
     302// convert to string Shortcut
     303template <class FromType>
     304std::string convertToString(FromType value)
     305{
     306  return getConvertedValue<FromType, std::string>(value);
     307}
     308
    301309// convert from string
    302310template <class ToType>
     
    313321    }
    314322};
     323
     324// convert from string Shortcut
     325template <class ToType>
     326ToType convertFromString(std::string str)
     327{
     328  return getConvertedValue<std::string, ToType>(str);
     329}
    315330
    316331
     
    404419////////////////////
    405420
     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
    406436// Vector2 to std::string
    407437template <>
     
    494524////////////////////
    495525
     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
    496553// std::string to Vector2
    497554template <>
     
    611668
    612669        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    613         if (tokens.size() >= 4)
     670        if (tokens.size() >= 3)
    614671        {
    615672            if (!ConvertValue(&(output->r), tokens[0]))
     
    619676            if (!ConvertValue(&(output->b), tokens[2]))
    620677                return false;
    621             if (!ConvertValue(&(output->a), tokens[3]))
    622                 return false;
     678            if (tokens.size() >= 4)
     679            {
     680                if (!ConvertValue(&(output->a), tokens[3]))
     681                    return false;
     682            }
     683            else
     684                output->a = 1.0;
    623685
    624686            return true;
Note: See TracChangeset for help on using the changeset viewer.