mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
global functions to read vectors
This commit is contained in:
parent
6a1031a8c0
commit
1d9769adbc
@ -28,6 +28,7 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
#define BEGIN_NAMESPACE namespace Latan {
|
||||
@ -190,6 +191,43 @@ inline std::string strFrom(const T x)
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
// specialization for vectors
|
||||
template<>
|
||||
inline DVec strTo<DVec>(const std::string &str)
|
||||
{
|
||||
DVec res;
|
||||
std::vector<double> vbuf;
|
||||
double buf;
|
||||
std::istringstream stream(str);
|
||||
|
||||
while (!stream.eof())
|
||||
{
|
||||
stream >> buf;
|
||||
vbuf.push_back(buf);
|
||||
}
|
||||
res = Map<DVec>(vbuf.data(), static_cast<Index>(vbuf.size()));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline IVec strTo<IVec>(const std::string &str)
|
||||
{
|
||||
IVec res;
|
||||
std::vector<int> vbuf;
|
||||
int buf;
|
||||
std::istringstream stream(str);
|
||||
|
||||
while (!stream.eof())
|
||||
{
|
||||
stream >> buf;
|
||||
vbuf.push_back(buf);
|
||||
}
|
||||
res = Map<IVec>(vbuf.data(), static_cast<Index>(vbuf.size()));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
#include <LatAnalyze/Exceptions.hpp>
|
||||
|
Loading…
Reference in New Issue
Block a user