Commit efc46172 authored by Valerio Bertone's avatar Valerio Bertone
Browse files

Merge branch 'InterfaceToApfel' into 'master'

Interface to apfel

See merge request !5
parents 2da06cf3 8a2074d6
......@@ -89,4 +89,4 @@ install(TARGETS ElementaryUtils
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
install(DIRECTORY include DESTINATION include)
install(DIRECTORY include/ DESTINATION include)
......@@ -13,6 +13,7 @@
#include <sstream>
#include <string>
#include <cstddef>
#include <vector>
namespace ElemUtils {
......@@ -86,6 +87,10 @@ public:
size_t toSize_t() const;
std::vector<double> toVectorDouble() const;
std::vector<int> toVectorInt() const;
/**
* Convert stream to string
* @return std::string
......
......@@ -13,6 +13,8 @@
#include <limits>
#include <sstream>
#include <string>
#include <clocale>
#include <iostream>
#include "StringUtils.h"
......@@ -27,6 +29,15 @@ public:
Formatter() {
// use to print full precision double
m_stream << std::setprecision(std::numeric_limits<double>::digits10);
//c
std::setlocale(LC_ALL, "en_US.UTF-8");
//c++ (global)
std::locale::global(std::locale("en_US.UTF-8"));
//c++ (cout)
std::cout.imbue(std::locale("en_US.UTF-8"));
}
~Formatter() {
......
......@@ -86,6 +86,40 @@ unsigned short GenericType::toUShort() const {
return us;
}
std::vector<double> GenericType::toVectorDouble() const {
//create a temporary object to avoid empty m_stream after use of >> operator ; for multiple use of the same GenericType object
std::stringstream sstream;
sstream << m_stream.str();
std::vector<double> vd{};
double d;
while(sstream >> d || !sstream.eof()) {
if(sstream.fail()) {
throw std::runtime_error("[GenericType::toVectorDouble] cast from std::string to std::vector<double> failed ! ");
}
vd.push_back(d);
}
return vd;
}
std::vector<int> GenericType::toVectorInt() const {
//create a temporary object to avoid empty m_stream after use of >> operator ; for multiple use of the same GenericType object
std::stringstream sstream;
sstream << m_stream.str();
std::vector<int> vi{};
int i;
while(sstream >> i || !sstream.eof()) {
if(sstream.fail()) {
throw std::runtime_error("[GenericType::toVectorInt] cast from std::string to std::vector<int> failed ! ");
}
vi.push_back(i);
}
return vi;
}
std::string GenericType::getString() const {
return m_stream.str();
}
......
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
#include <algorithm> // pour transform #include <cctype> #include <cstdlib> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include "../../../include/ElementaryUtils/logger/CustomException.h" #include <cctype> #include <iterator>
#include <algorithm> // pour transform
#include <cctype>
#include <cstdlib>
#include <iterator>
#include "../../../include/ElementaryUtils/logger/CustomException.h"
#include "../../../include/ElementaryUtils/logger/CustomException.h"
#include "../../../include/ElementaryUtils/logger/LoggerManager.h"
#include "../../../include/ElementaryUtils/string_utils/Formatter.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment