26 #include <boost/lexical_cast.hpp> 27 #include <boost/regex.hpp> 28 #include <boost/io/detail/quoted_manip.hpp> 37 using boost::regex_match;
40 if (type ==
typeid(
bool)) {
42 }
if (type ==
typeid(int32_t)) {
44 }
if (type ==
typeid(int64_t)) {
46 }
if (type ==
typeid(
float)) {
48 }
if (type ==
typeid(
double)) {
50 }
if (type ==
typeid(std::string)) {
52 }
if (type ==
typeid(std::vector<bool>)) {
54 }
if (type ==
typeid(std::vector<int32_t>)) {
56 }
if (type ==
typeid(std::vector<int64_t>)) {
58 }
if (type ==
typeid(std::vector<float>)) {
60 }
if (type ==
typeid(std::vector<double>)) {
74 <<
" is not supported";
78 std::vector<size_t> sizes {};
80 auto column_info = table.getColumnInfo();
81 for (
size_t i=0; i<column_info->size(); ++i) {
82 sizes.push_back(
quoted(column_info->getDescription(i).name).size());
84 for (
auto row : table) {
85 for (
size_t i=0; i<sizes.size(); ++i) {
86 sizes[i] = std::max(sizes[i], boost::apply_visitor(
ToStringVisitor{}, row[i]).size());
89 for (
auto&
s : sizes) {
95 std::string
quoted(
const std::string& str) {
96 regex whitespace_quotes{
".*[\\s\"].*"};
97 if (!regex_match(str, whitespace_quotes))
NdArray(const std::vector< size_t > &shape)
std::string typeToKeyword(std::type_index type)
Converts a type to its string representation.
std::string quoted(const std::string &str)
std::vector< size_t > calculateColumnLengths(const Table &table)
Calculates the sizes in characters each column of the table needs.