new function to split string into a float-vector

pull/1/head
Thorsten Liebig 2012-02-02 11:40:42 +01:00
parent fe35f550af
commit 5d0f08aaec
2 changed files with 22 additions and 0 deletions

View File

@ -22,6 +22,9 @@
#include <climits> #include <climits>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <iomanip>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <iostream> #include <iostream>
unsigned int CalcNyquistNum(double fmax, double dT) unsigned int CalcNyquistNum(double fmax, double dT)
@ -70,3 +73,19 @@ std::vector<unsigned int> AssignJobs2Threads(unsigned int jobs, unsigned int nrT
return jpt; return jpt;
} }
std::vector<float> SplitString2Float(std::string str, std::string delimiter)
{
std::vector<float> v_f;
std::vector<std::string> results;
boost::split(results, str, boost::is_any_of(delimiter));
for (size_t n=0;n<results.size();++n)
{
std::istringstream is(results.at(n));
float num;
if (is >> num)
v_f.push_back(num);
}
return v_f;
}

View File

@ -19,6 +19,7 @@
#define USEFUL_H #define USEFUL_H
#include <vector> #include <vector>
#include <string>
//! Calc the nyquist number of timesteps for a given frequency and timestep //! Calc the nyquist number of timesteps for a given frequency and timestep
unsigned int CalcNyquistNum(double fmax, double dT); 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. //! Calculate an optimal job distribution to a given number of threads. Will return a vector with the jobs for each thread.
std::vector<unsigned int> AssignJobs2Threads(unsigned int jobs, unsigned int nrThreads, bool RemoveEmpty=false); std::vector<unsigned int> AssignJobs2Threads(unsigned int jobs, unsigned int nrThreads, bool RemoveEmpty=false);
std::vector<float> SplitString2Float(std::string str, std::string delimiter=",");
#endif // USEFUL_H #endif // USEFUL_H