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 ...@@ -89,4 +89,4 @@ install(TARGETS ElementaryUtils
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static) ARCHIVE DESTINATION lib/static)
install(DIRECTORY include DESTINATION include) install(DIRECTORY include/ DESTINATION include)
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <cstddef> #include <cstddef>
#include <vector>
namespace ElemUtils { namespace ElemUtils {
...@@ -86,6 +87,10 @@ public: ...@@ -86,6 +87,10 @@ public:
size_t toSize_t() const; size_t toSize_t() const;
std::vector<double> toVectorDouble() const;
std::vector<int> toVectorInt() const;
/** /**
* Convert stream to string * Convert stream to string
* @return std::string * @return std::string
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <limits> #include <limits>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <clocale>
#include <iostream>
#include "StringUtils.h" #include "StringUtils.h"
...@@ -27,6 +29,15 @@ public: ...@@ -27,6 +29,15 @@ public:
Formatter() { Formatter() {
// use to print full precision double // use to print full precision double
m_stream << std::setprecision(std::numeric_limits<double>::digits10); 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() { ~Formatter() {
......
...@@ -86,6 +86,40 @@ unsigned short GenericType::toUShort() const { ...@@ -86,6 +86,40 @@ unsigned short GenericType::toUShort() const {
return us; 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 { std::string GenericType::getString() const {
return m_stream.str(); return m_stream.str();
} }
......
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h" #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/CustomException.h"
#include "../../../include/ElementaryUtils/logger/LoggerManager.h" #include "../../../include/ElementaryUtils/logger/LoggerManager.h"
#include "../../../include/ElementaryUtils/string_utils/Formatter.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