Alexandria  2.27.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsciiWriterHelper.h
Go to the documentation of this file.
1 
25 #ifndef TABLE_ASCIIWRITERHELPER_H
26 #define TABLE_ASCIIWRITERHELPER_H
27 
28 #include "ElementsKernel/Export.h"
29 #include "ReaderHelper.h"
30 #include "Table/Table.h"
31 #include <sstream>
32 #include <typeindex>
33 #include <vector>
34 
35 namespace Euclid {
36 namespace Table {
37 
48 
60 
71 std::string quoted(const std::string& str);
72 
77 struct ToStringVisitor : public boost::static_visitor<std::string> {
78  std::string operator()(const std::string& from) const {
80  q << quoted(from);
81  return q.str();
82  }
83 
84  std::string operator()(const double from) const {
86  q << std::setprecision(std::numeric_limits<double>::digits10) << from;
87  return q.str();
88  }
89 
90  template <typename T>
93  auto it = v.begin();
94  if (it != v.end()) {
95  q << *it;
96  ++it;
97  }
98  while (it != v.end()) {
99  q << ',' << *it;
100  ++it;
101  }
102  return q.str();
103  }
104 
105  template <typename T>
106  std::string operator()(const T& from) const {
108  q << from;
109  return q.str();
110  }
111 };
112 
113 } // namespace Table
114 } // end of namespace Euclid
115 
116 #endif /* TABLE_ASCIIWRITERHELPER_H */
T end(T...args)
std::string operator()(const std::string &from) const
STL class.
T str(T...args)
#define ELEMENTS_API
std::string typeToKeyword(std::type_index type)
Converts a type to its string representation.
std::string operator()(const double from) const
std::string quoted(const std::string &str)
std::string operator()(const std::vector< T > &v) const
T begin(T...args)
std::string operator()(const T &from) const
std::vector< size_t > calculateColumnLengths(const Table &table)
Calculates the sizes in characters each column of the table needs.