18 #include <boost/io/ios_state.hpp>
44 return boost::get<int>(
value);
53 return boost::get<unsigned int>(
value);
61 return boost::get<std::uint64_t>(
value);
69 return boost::get<double>(
value);
74 ExcMessage(
"The number stored by this element of the "
75 "table is not a number."))
84 std::ostringstream ss;
86 ss << std::setprecision(precision);
89 ss.setf(std::ios::scientific, std::ios::floatfield);
91 ss.setf(std::ios::fixed, std::ios::floatfield);
113 template <
typename T>
137 : tex_caption(tex_caption)
166 while (entries.size() < size)
168 entries.push_back(entries.back().get_default_constructed_copy());
183 for (
const auto &entry : entries)
185 entry.cache_string(this->scientific, this->precision);
188 static_cast<unsigned int>(entry.get_cached_string().length()));
207 ExcMessage(
"You are trying to declare a column with key <" + key +
208 "> but such a column already exists."));
220 unsigned int max_col_length = 0;
221 for (
const auto &column :
columns)
224 static_cast<unsigned int>(column.second.entries.size()));
229 while (column.second.entries.size() < max_col_length)
231 column.second.entries.emplace_back(
"");
233 entry.
cache_string(column.second.scientific, column.second.precision);
234 column.second.max_length =
236 static_cast<unsigned int>(
252 const std::string &superkey)
258 std::pair<std::string, std::vector<std::string>> new_column(
259 superkey, std::vector<std::string>());
273 const auto order_iter =
284 std::pair<std::string, std::string> new_tex_supercaption(superkey,
297 for (
const auto &new_column : new_order)
310 const std::string &tex_caption)
313 columns[key].tex_caption = tex_caption;
336 const std::string &tex_supercaption)
347 const std::string &tex_format)
350 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
352 columns[key].tex_format = tex_format;
359 const unsigned int precision)
362 if (
columns[key].precision != precision)
364 columns[key].precision = precision;
365 columns[key].invalidate_cache();
374 if (
columns[key].scientific != scientific)
376 columns[key].scientific = scientific;
377 columns[key].invalidate_cache();
386 boost::io::ios_flags_saver restore_flags(out);
391 unsigned int max_rows = 0;
392 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
395 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
398 column.second.pad_column_below(max_rows);
401 std::vector<std::string> sel_columns;
404 const unsigned int nrows =
n_rows();
405 const unsigned int n_cols = sel_columns.size();
408 std::vector<const Column *> cols;
409 std::vector<unsigned int> column_widths(n_cols, 0);
410 for (
unsigned int j = 0; j < n_cols; ++j)
412 std::string key = sel_columns[j];
413 const std::map<std::string, Column>::const_iterator col_iter =
416 cols.push_back(&(col_iter->second));
418 column_widths[j] = col_iter->second.max_length;
426 out <<
"| " << std::left;
427 for (
unsigned int j = 0; j < n_cols; ++j)
429 const std::string &key = sel_columns[j];
432 static_cast<unsigned int>(key.length()));
433 out << std::setw(column_widths[j]);
439 for (
unsigned int i = 0; i < nrows; ++i)
442 for (
unsigned int j = 0; j < n_cols; ++j)
444 const Column &column = *(cols[j]);
446 out << std::setw(column_widths[j]);
447 out << column.
entries[i].get_cached_string();
460 for (
unsigned int j = 0; j < n_cols; ++j)
462 const std::string &key = sel_columns[j];
463 out <<
"# " << j + 1 <<
": " << key <<
'\n';
467 for (
unsigned int i = 0; i < nrows; ++i)
469 for (
unsigned int j = 0; j < n_cols; ++j)
471 const Column &column = *(cols[j]);
473 out << column.
entries[i].get_cached_string();
488 for (
unsigned int j = 0; j < n_cols; ++j)
490 std::string key = sel_columns[j];
491 out <<
"# " << j + 1 <<
": " << key <<
'\n';
502 unsigned int width = 0;
505 const std::map<std::string,
506 std::vector<std::string>>::const_iterator
510 const unsigned int n_subcolumns = super_iter->second.size();
511 for (
unsigned int k = 0; k < n_subcolumns; ++k)
513 const std::map<std::string, Column>::const_iterator
514 col_iter =
columns.find(super_iter->second[k]);
517 width += col_iter->second.max_length;
519 width += n_subcolumns - 1;
523 const std::map<std::string, Column>::const_iterator
526 width = col_iter->second.max_length;
531 if (width < key.length())
537 const std::map<std::string,
538 std::vector<std::string>>::const_iterator
541 colname = super_iter->second.back();
546 for (
unsigned int i = 0; i < n_cols; ++i)
548 if (sel_columns[i] == colname)
550 column_widths[i] += key.length() - width;
555 width = key.length();
559 const unsigned int front_padding = (width - key.length()) / 2,
561 (width - key.length()) - front_padding;
562 for (
unsigned int i = 0; i < front_padding; ++i)
565 for (
unsigned int i = 0; i < rear_padding; ++i)
581 for (
unsigned int i = 0; i < nrows; ++i)
583 for (
unsigned int j = 0; j < n_cols; ++j)
585 const Column &column = *(cols[j]);
586 out << std::setw(column_widths[j]);
587 out << column.
entries[i].get_cached_string();
605 out <<
"\\documentclass[10pt]{report}" <<
'\n'
606 <<
"\\usepackage{float}" <<
'\n'
609 <<
"\\begin{document}" <<
'\n';
611 out <<
"\\begin{table}[H]" <<
'\n'
612 <<
"\\begin{center}" <<
'\n'
613 <<
"\\begin{tabular}{|";
618 unsigned int max_rows = 0;
619 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
622 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
625 column.second.pad_column_below(max_rows);
628 std::vector<std::string> sel_columns;
635 const std::map<std::string, std::vector<std::string>>::const_iterator
640 const unsigned int n_subcolumns = super_iter->second.size();
641 for (
unsigned int k = 0; k < n_subcolumns; ++k)
644 const std::map<std::string, Column>::const_iterator col_iter =
645 columns.find(super_iter->second[k]);
648 out << col_iter->second.tex_format <<
"|";
654 const std::map<std::string, Column>::const_iterator col_iter =
657 out << col_iter->second.tex_format <<
"|";
660 out <<
"} \\hline" <<
'\n';
667 const std::map<std::string, std::vector<std::string>>::const_iterator
672 const unsigned int n_subcolumns = super_iter->second.size();
674 std::map<std::string, std::string>::const_iterator
677 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
678 << tex_super_cap_iter->second <<
"}";
683 const std::map<std::string, Column>::const_iterator col_iter =
686 out << col_iter->second.tex_caption;
691 out <<
"\\\\ \\hline" <<
'\n';
694 const unsigned int nrows =
n_rows();
695 for (
unsigned int i = 0; i < nrows; ++i)
697 const unsigned int n_cols = sel_columns.size();
699 for (
unsigned int j = 0; j < n_cols; ++j)
701 std::string key = sel_columns[j];
703 const std::map<std::string, Column>::const_iterator col_iter =
707 const Column &column = col_iter->second;
709 out << std::setprecision(column.
precision);
711 if (col_iter->second.scientific)
712 out.setf(std::ios::scientific, std::ios::floatfield);
714 out.setf(std::ios::fixed, std::ios::floatfield);
716 out << column.
entries[i].value;
721 out <<
"\\\\ \\hline" <<
'\n';
724 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
729 out <<
"\\end{table}" <<
'\n';
731 out <<
"\\end{document}" <<
'\n';
759 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
760 unsigned int n = col_iter->second.entries.size();
763 std::string first_name = col_iter->first;
764 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
765 Assert(col_iter->second.entries.size() == n,
767 col_iter->first, col_iter->second.entries.size(), first_name, n));
781 const std::map<std::string, std::vector<std::string>>::const_iterator
787 const unsigned int n_subcolumns = super_iter->second.size();
788 for (
unsigned int k = 0; k < n_subcolumns; ++k)
790 const std::string subkey = super_iter->second[k];
792 sel_columns.push_back(subkey);
799 sel_columns.push_back(key);
811 for (
const auto &column :
columns)
812 n =
std::max(n, column.second.entries.size());
817 if (column.second.entries.size() == n)
818 column.second.entries.pop_back();