From 5d0f08aaec6bebc2e7dd065a71cb2dae62ac7904 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Thu, 2 Feb 2012 11:40:42 +0100 Subject: [PATCH] new function to split string into a float-vector --- tools/useful.cpp | 19 +++++++++++++++++++ tools/useful.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/tools/useful.cpp b/tools/useful.cpp index 6ddd589..601c97a 100644 --- a/tools/useful.cpp +++ b/tools/useful.cpp @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include #include unsigned int CalcNyquistNum(double fmax, double dT) @@ -70,3 +73,19 @@ std::vector AssignJobs2Threads(unsigned int jobs, unsigned int nrT return jpt; } + +std::vector SplitString2Float(std::string str, std::string delimiter) +{ + std::vector v_f; + std::vector results; + boost::split(results, str, boost::is_any_of(delimiter)); + + for (size_t n=0;n> num) + v_f.push_back(num); + } + return v_f; +} diff --git a/tools/useful.h b/tools/useful.h index c81bd96..770f2e9 100644 --- a/tools/useful.h +++ b/tools/useful.h @@ -19,6 +19,7 @@ #define USEFUL_H #include +#include //! Calc the nyquist number of timesteps for a given frequency and timestep unsigned int CalcNyquistNum(double fmax, double dT); @@ -29,4 +30,6 @@ double CalcNyquistFrequency(unsigned int nyquist, double dT); //! Calculate an optimal job distribution to a given number of threads. Will return a vector with the jobs for each thread. std::vector AssignJobs2Threads(unsigned int jobs, unsigned int nrThreads, bool RemoveEmpty=false); +std::vector SplitString2Float(std::string str, std::string delimiter=","); + #endif // USEFUL_H