17#include <boost/io/ios_state.hpp>
44 return std::get<int>(
value);
53 return std::get<unsigned int>(
value);
61 return std::get<std::uint64_t>(
value);
69 return std::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);
96 std::visit([&ss](
const auto &v) { ss << v; },
value);
117 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
129 : tex_caption(tex_caption)
158 while (entries.size() <
size)
160 entries.push_back(entries.back().get_default_constructed_copy());
175 for (
const auto &entry : entries)
177 entry.cache_string(this->scientific, this->precision);
180 static_cast<unsigned int>(entry.get_cached_string().size()));
199 ExcMessage(
"You are trying to declare a column with key <" + key +
200 "> but such a column already exists."));
212 unsigned int max_col_length = 0;
213 for (
const auto &column :
columns)
216 static_cast<unsigned int>(column.second.entries.size()));
221 while (column.second.entries.size() < max_col_length)
223 column.second.entries.emplace_back(
"");
225 entry.
cache_string(column.second.scientific, column.second.precision);
226 column.second.max_length =
243 const std::string &superkey)
249 std::pair<std::string, std::vector<std::string>> new_column(
250 superkey, std::vector<std::string>());
264 const auto order_iter =
275 std::pair<std::string, std::string> new_tex_supercaption(superkey,
288 for (
const auto &new_column : new_order)
301 const std::string &tex_caption)
304 columns[key].tex_caption = tex_caption;
327 const std::string &tex_supercaption)
338 const std::string &tex_format)
341 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
343 columns[key].tex_format = tex_format;
350 const unsigned int precision)
353 if (
columns[key].precision != precision)
355 columns[key].precision = precision;
356 columns[key].invalidate_cache();
365 if (
columns[key].scientific != scientific)
367 columns[key].scientific = scientific;
368 columns[key].invalidate_cache();
377 boost::io::ios_flags_saver restore_flags(out);
382 unsigned int max_rows = 0;
383 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
386 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
389 column.second.pad_column_below(max_rows);
392 std::vector<std::string> sel_columns;
395 const unsigned int nrows =
n_rows();
396 const unsigned int n_cols = sel_columns.size();
399 std::vector<const Column *> cols;
400 std::vector<unsigned int> column_widths(n_cols, 0);
401 for (
unsigned int j = 0; j < n_cols; ++j)
403 std::string key = sel_columns[j];
404 const std::map<std::string, Column>::const_iterator col_iter =
407 cols.push_back(&(col_iter->second));
409 column_widths[j] = col_iter->second.max_length;
417 out <<
"| " << std::left;
418 for (
unsigned int j = 0; j < n_cols; ++j)
420 const std::string &key = sel_columns[j];
423 static_cast<unsigned int>(key.size()));
424 out << std::setw(column_widths[j]);
430 for (
unsigned int i = 0; i < nrows; ++i)
433 for (
unsigned int j = 0; j < n_cols; ++j)
435 const Column &column = *(cols[j]);
437 out << std::setw(column_widths[j]);
438 out << column.
entries[i].get_cached_string();
451 for (
unsigned int j = 0; j < n_cols; ++j)
453 const std::string &key = sel_columns[j];
454 out <<
"# " << j + 1 <<
": " << key <<
'\n';
458 for (
unsigned int i = 0; i < nrows; ++i)
460 for (
unsigned int j = 0; j < n_cols; ++j)
462 const Column &column = *(cols[j]);
464 out << column.
entries[i].get_cached_string();
479 for (
unsigned int j = 0; j < n_cols; ++j)
481 std::string key = sel_columns[j];
482 out <<
"# " << j + 1 <<
": " << key <<
'\n';
493 unsigned int width = 0;
496 const std::map<std::string,
497 std::vector<std::string>>::const_iterator
501 const unsigned int n_subcolumns = super_iter->second.size();
502 for (
unsigned int k = 0; k < n_subcolumns; ++k)
504 const std::map<std::string, Column>::const_iterator
505 col_iter =
columns.find(super_iter->second[k]);
508 width += col_iter->second.max_length;
510 width += n_subcolumns - 1;
514 const std::map<std::string, Column>::const_iterator
517 width = col_iter->second.max_length;
522 if (width < key.size())
528 const std::map<std::string,
529 std::vector<std::string>>::const_iterator
532 colname = super_iter->second.back();
537 for (
unsigned int i = 0; i < n_cols; ++i)
539 if (sel_columns[i] == colname)
541 column_widths[i] += key.size() - width;
550 const unsigned int front_padding = (width - key.size()) / 2,
552 (width - key.size()) - front_padding;
553 for (
unsigned int i = 0; i < front_padding; ++i)
556 for (
unsigned int i = 0; i < rear_padding; ++i)
572 for (
unsigned int i = 0; i < nrows; ++i)
574 for (
unsigned int j = 0; j < n_cols; ++j)
576 const Column &column = *(cols[j]);
577 out << std::setw(column_widths[j]);
578 out << column.
entries[i].get_cached_string();
596 out <<
"\\documentclass[10pt]{report}" <<
'\n'
597 <<
"\\usepackage{float}" <<
'\n'
600 <<
"\\begin{document}" <<
'\n';
602 out <<
"\\begin{table}[H]" <<
'\n'
603 <<
"\\begin{center}" <<
'\n'
604 <<
"\\begin{tabular}{|";
609 unsigned int max_rows = 0;
610 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
613 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
616 column.second.pad_column_below(max_rows);
619 std::vector<std::string> sel_columns;
626 const std::map<std::string, std::vector<std::string>>::const_iterator
631 const unsigned int n_subcolumns = super_iter->second.size();
632 for (
unsigned int k = 0; k < n_subcolumns; ++k)
635 const std::map<std::string, Column>::const_iterator col_iter =
636 columns.find(super_iter->second[k]);
639 out << col_iter->second.tex_format <<
"|";
645 const std::map<std::string, Column>::const_iterator col_iter =
648 out << col_iter->second.tex_format <<
"|";
651 out <<
"} \\hline" <<
'\n';
658 const std::map<std::string, std::vector<std::string>>::const_iterator
663 const unsigned int n_subcolumns = super_iter->second.size();
665 std::map<std::string, std::string>::const_iterator
668 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
669 << tex_super_cap_iter->second <<
"}";
674 const std::map<std::string, Column>::const_iterator col_iter =
677 out << col_iter->second.tex_caption;
682 out <<
"\\\\ \\hline" <<
'\n';
685 const unsigned int nrows =
n_rows();
686 for (
unsigned int i = 0; i < nrows; ++i)
688 const unsigned int n_cols = sel_columns.size();
690 for (
unsigned int j = 0; j < n_cols; ++j)
692 std::string key = sel_columns[j];
694 const std::map<std::string, Column>::const_iterator col_iter =
698 const Column &column = col_iter->second;
700 out << std::setprecision(column.
precision);
702 if (col_iter->second.scientific)
703 out.setf(std::ios::scientific, std::ios::floatfield);
705 out.setf(std::ios::fixed, std::ios::floatfield);
707 std::visit([&out](
const auto &v) { out << v; },
713 out <<
"\\\\ \\hline" <<
'\n';
716 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
721 out <<
"\\end{table}" <<
'\n';
723 out <<
"\\end{document}" <<
'\n';
751 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
752 unsigned int n = col_iter->second.entries.size();
755 std::string first_name = col_iter->first;
756 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
757 Assert(col_iter->second.entries.size() == n,
759 col_iter->first, col_iter->second.entries.size(), first_name, n));
773 const std::map<std::string, std::vector<std::string>>::const_iterator
779 const unsigned int n_subcolumns = super_iter->second.size();
780 for (
unsigned int k = 0; k < n_subcolumns; ++k)
782 const std::string subkey = super_iter->second[k];
784 sel_columns.push_back(subkey);
791 sel_columns.push_back(key);
802 std::vector<internal::TableEntry>::size_type n = 0;
803 for (
const auto &column :
columns)
804 n =
std::max(n, column.second.entries.size());
809 if (column.second.entries.size() == n)
810 column.second.entries.pop_back();
void set_tex_format(const std::string &key, const std::string &format="c")
void set_tex_table_caption(const std::string &table_caption)
void set_tex_supercaption(const std::string &superkey, const std::string &tex_supercaption)
void declare_column(const std::string &key)
void write_text(std::ostream &out, const TextOutputFormat format=table_with_headers) const
void set_auto_fill_mode(const bool state)
unsigned int n_rows() const
void get_selected_columns(std::vector< std::string > &sel_columns) const
std::map< std::string, std::vector< std::string > > supercolumns
@ simple_table_with_separate_column_description
@ table_with_separate_column_description
std::map< std::string, std::string > tex_supercaptions
std::string tex_table_label
std::string tex_table_caption
void write_tex(std::ostream &file, const bool with_header=true) const
void add_column_to_supercolumn(const std::string &key, const std::string &superkey)
void set_column_order(const std::vector< std::string > &new_order)
void set_tex_caption(const std::string &key, const std::string &tex_caption)
void set_scientific(const std::string &key, const bool scientific)
std::vector< std::string > column_order
void set_tex_table_label(const std::string &table_label)
void set_precision(const std::string &key, const unsigned int precision)
std::map< std::string, Column > columns
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcSuperColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcWrongNumberOfDataEntries(std::string arg1, int arg2, std::string arg3, int arg4)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcColumnNotExistent(std::string arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcUndefinedTexFormat(std::string arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcColumnOrSuperColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define DEAL_II_ASSERT_UNREACHABLE()
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
void pad_column_below(const unsigned int length)
std::vector< internal::TableEntry > entries
TableEntry get_default_constructed_copy() const
const std::string & get_cached_string() const
double get_numeric_value() const
void cache_string(bool scientific, unsigned int precision) const