From 7caf1947bab4ee5472221e7acc8cfc5c1d6f3b4a Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 24 Jul 2012 20:18:21 -0700 Subject: [PATCH] fixed copy-paste code. --- platform/settings.cpp | 64 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/platform/settings.cpp b/platform/settings.cpp index 38334e36e5..c416555322 100644 --- a/platform/settings.cpp +++ b/platform/settings.cpp @@ -181,60 +181,58 @@ namespace Settings return true; } + namespace impl + { + template + string ToStringScalar(T const & v) + { + ostringstream stream; + stream.precision(12); + stream << v; + return stream.str(); + } + + template + bool FromStringScalar(string const & str, T & v) + { + istringstream stream(str); + if (stream.good()) + { + stream >> v; + return !stream.fail(); + } + else return false; + } + } + template <> string ToString(double const & v) { - ostringstream stream; - stream.precision(12); - stream << v; - return stream.str(); + return impl::ToStringScalar(v); } + template <> bool FromString(string const & str, double & v) { - istringstream stream(str); - if (stream.good()) - { - stream >> v; - return !stream.fail(); - } - else return false; + return impl::FromStringScalar(str, v); } template <> string ToString(int const & v) { - ostringstream stream; - stream << v; - return stream.str(); + return impl::ToStringScalar(v); } template <> bool FromString(string const & str, int & v) { - istringstream stream(str); - if (stream.good()) - { - stream >> v; - return !stream.fail(); - } - else - return false; + return impl::FromStringScalar(str, v); } template <> string ToString(unsigned const & v) { - ostringstream stream; - stream << v; - return stream.str(); + return impl::ToStringScalar(v); } template <> bool FromString(string const & str, unsigned & v) { - istringstream stream(str); - if (stream.good()) - { - stream >> v; - return !stream.fail(); - } - else - return false; + return impl::FromStringScalar(str, v); } namespace impl