summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <wjp@usecode.org>2017-10-17 22:06:13 +0200
committerWillem Jan Palenstijn <wjp@usecode.org>2017-10-17 22:06:29 +0200
commitd1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c (patch)
tree1a670088a70271de69ebe6e0368599b64098ab2e
parent08fbd5bb090eba2d207eceb520351eabcfc389fe (diff)
downloadastra-d1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c.tar.gz
astra-d1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c.tar.bz2
astra-d1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c.tar.xz
astra-d1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c.zip
Improve stringToFloatVector to match stringToDoubleVector
-rw-r--r--src/Utilities.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/Utilities.cpp b/src/Utilities.cpp
index c90e67b..2ae1b66 100644
--- a/src/Utilities.cpp
+++ b/src/Utilities.cpp
@@ -66,14 +66,10 @@ double stringToDouble(const std::string& s)
template<> float stringTo(const std::string& s) { return stringToFloat(s); }
template<> double stringTo(const std::string& s) { return stringToDouble(s); }
-std::vector<float> stringToFloatVector(const std::string &s)
-{
- return stringToVector<float>(s);
-}
-
-std::vector<double> stringToDoubleVector(const std::string &s)
+template<typename T>
+std::vector<T> stringToNumericVector(const std::string &s)
{
- std::vector<double> out;
+ std::vector<T> out;
out.reserve(100);
std::istringstream iss;
iss.imbue(std::locale::classic());
@@ -85,7 +81,7 @@ std::vector<double> stringToDoubleVector(const std::string &s)
std::string t = s.substr(current, next - current);
iss.str(t);
iss.clear();
- double f;
+ T f;
iss >> f;
out.push_back(f);
current = next + 1;
@@ -94,6 +90,15 @@ std::vector<double> stringToDoubleVector(const std::string &s)
return out;
}
+std::vector<float> stringToFloatVector(const std::string &s)
+{
+ return stringToNumericVector<float>(s);
+}
+std::vector<double> stringToDoubleVector(const std::string &s)
+{
+ return stringToNumericVector<double>(s);
+}
+
template<typename T>
std::vector<T> stringToVector(const std::string& s)
{