From 8405106cba190ee6e086c52ef1634d07572c3d2b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 18 Jan 2010 02:53:09 +0100 Subject: added string constructor and operator= to locale independent float class --- src/utils/locale_independent_float.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/utils/locale_independent_float.cpp') diff --git a/src/utils/locale_independent_float.cpp b/src/utils/locale_independent_float.cpp index 1f747776..e0015cee 100644 --- a/src/utils/locale_independent_float.cpp +++ b/src/utils/locale_independent_float.cpp @@ -38,6 +38,11 @@ namespace usdx { } + LocaleIndependentFloat::LocaleIndependentFloat(std::string& value) + { + this->operator=(value); + } + const float LocaleIndependentFloat::get_value() { return this->value; @@ -60,6 +65,19 @@ namespace usdx return *this; } + LocaleIndependentFloat& LocaleIndependentFloat::operator= (std::string& value) + { + std::size_t found = value.find(','); + if (found != std::string::npos) { + value[found] = '.'; + } + + std::istringstream str(value); + str >> this->value; + + return *this; + } + std::istream& operator>> (std::istream& is, LocaleIndependentFloat& float_value) { return is >> &float_value; @@ -70,17 +88,7 @@ namespace usdx std::string str_value; is >> str_value; - std::size_t found = str_value.find(','); - if (found != std::string::npos) { - str_value[found] = '.'; - } - - std::istringstream str(str_value); - float value; - str >> value; - - float_value->set_value(value); - + *float_value = str_value; return is; } }; -- cgit v1.2.3