mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
global functions to read vectors
This commit is contained in:
parent
6a1031a8c0
commit
1d9769adbc
@ -28,6 +28,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#define BEGIN_NAMESPACE namespace Latan {
|
#define BEGIN_NAMESPACE namespace Latan {
|
||||||
@ -190,6 +191,43 @@ inline std::string strFrom(const T x)
|
|||||||
return stream.str();
|
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
|
END_NAMESPACE
|
||||||
|
|
||||||
#include <LatAnalyze/Exceptions.hpp>
|
#include <LatAnalyze/Exceptions.hpp>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user