18#include <boost/io/ios_state.hpp>
45 return std_cxx17::get<int>(
value);
54 return std_cxx17::get<unsigned int>(
value);
62 return std_cxx17::get<std::uint64_t>(
value);
70 return std_cxx17::get<double>(
value);
75 ExcMessage(
"The number stored by this element of the "
76 "table is not a number."))
85 std::ostringstream ss;
87 ss << std::setprecision(precision);
90 ss.setf(std::ios::scientific, std::ios::floatfield);
92 ss.setf(std::ios::fixed, std::ios::floatfield);
94#ifdef DEAL_II_HAVE_CXX17
95 std::visit([&ss](
auto &v) { ss << v; },
value);
112#ifndef DEAL_II_HAVE_CXX17
117 struct SetValueToDefault :
public boost::static_visitor<>
119 template <
typename T>
121 operator()(T &operand)
const
133#ifndef DEAL_II_HAVE_CXX17
134 boost::apply_visitor(Local::SetValueToDefault(), new_entry.
value);
140 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
153 : tex_caption(tex_caption)
182 while (entries.size() < size)
184 entries.push_back(entries.back().get_default_constructed_copy());
199 for (
const auto &entry : entries)
201 entry.cache_string(this->scientific, this->precision);
204 static_cast<unsigned int>(entry.get_cached_string().size()));
223 ExcMessage(
"You are trying to declare a column with key <" + key +
224 "> but such a column already exists."));
236 unsigned int max_col_length = 0;
237 for (
const auto &column :
columns)
240 static_cast<unsigned int>(column.second.entries.size()));
245 while (column.second.entries.size() < max_col_length)
247 column.second.entries.emplace_back(
"");
249 entry.
cache_string(column.second.scientific, column.second.precision);
250 column.second.max_length =
267 const std::string &superkey)
273 std::pair<std::string, std::vector<std::string>> new_column(
274 superkey, std::vector<std::string>());
288 const auto order_iter =
299 std::pair<std::string, std::string> new_tex_supercaption(superkey,
312 for (
const auto &new_column : new_order)
325 const std::string &tex_caption)
328 columns[key].tex_caption = tex_caption;
351 const std::string &tex_supercaption)
362 const std::string &tex_format)
365 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
367 columns[key].tex_format = tex_format;
374 const unsigned int precision)
377 if (
columns[key].precision != precision)
379 columns[key].precision = precision;
380 columns[key].invalidate_cache();
389 if (
columns[key].scientific != scientific)
391 columns[key].scientific = scientific;
392 columns[key].invalidate_cache();
401 boost::io::ios_flags_saver restore_flags(out);
406 unsigned int max_rows = 0;
407 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
410 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
413 column.second.pad_column_below(max_rows);
416 std::vector<std::string> sel_columns;
419 const unsigned int nrows =
n_rows();
420 const unsigned int n_cols = sel_columns.size();
423 std::vector<const Column *> cols;
424 std::vector<unsigned int> column_widths(n_cols, 0);
425 for (
unsigned int j = 0; j < n_cols; ++j)
427 std::string key = sel_columns[j];
428 const std::map<std::string, Column>::const_iterator col_iter =
431 cols.push_back(&(col_iter->second));
433 column_widths[j] = col_iter->second.max_length;
441 out <<
"| " << std::left;
442 for (
unsigned int j = 0; j < n_cols; ++j)
444 const std::string &key = sel_columns[j];
447 static_cast<unsigned int>(key.size()));
448 out << std::setw(column_widths[j]);
454 for (
unsigned int i = 0; i < nrows; ++i)
457 for (
unsigned int j = 0; j < n_cols; ++j)
459 const Column &column = *(cols[j]);
461 out << std::setw(column_widths[j]);
462 out << column.
entries[i].get_cached_string();
475 for (
unsigned int j = 0; j < n_cols; ++j)
477 const std::string &key = sel_columns[j];
478 out <<
"# " << j + 1 <<
": " << key <<
'\n';
482 for (
unsigned int i = 0; i < nrows; ++i)
484 for (
unsigned int j = 0; j < n_cols; ++j)
486 const Column &column = *(cols[j]);
488 out << column.
entries[i].get_cached_string();
503 for (
unsigned int j = 0; j < n_cols; ++j)
505 std::string key = sel_columns[j];
506 out <<
"# " << j + 1 <<
": " << key <<
'\n';
517 unsigned int width = 0;
520 const std::map<std::string,
521 std::vector<std::string>>::const_iterator
525 const unsigned int n_subcolumns = super_iter->second.size();
526 for (
unsigned int k = 0; k < n_subcolumns; ++k)
528 const std::map<std::string, Column>::const_iterator
529 col_iter =
columns.find(super_iter->second[k]);
532 width += col_iter->second.max_length;
534 width += n_subcolumns - 1;
538 const std::map<std::string, Column>::const_iterator
541 width = col_iter->second.max_length;
546 if (width < key.size())
552 const std::map<std::string,
553 std::vector<std::string>>::const_iterator
556 colname = super_iter->second.back();
561 for (
unsigned int i = 0; i < n_cols; ++i)
563 if (sel_columns[i] == colname)
565 column_widths[i] += key.size() - width;
574 const unsigned int front_padding = (width - key.size()) / 2,
576 (width - key.size()) - front_padding;
577 for (
unsigned int i = 0; i < front_padding; ++i)
580 for (
unsigned int i = 0; i < rear_padding; ++i)
596 for (
unsigned int i = 0; i < nrows; ++i)
598 for (
unsigned int j = 0; j < n_cols; ++j)
600 const Column &column = *(cols[j]);
601 out << std::setw(column_widths[j]);
602 out << column.
entries[i].get_cached_string();
620 out <<
"\\documentclass[10pt]{report}" <<
'\n'
621 <<
"\\usepackage{float}" <<
'\n'
624 <<
"\\begin{document}" <<
'\n';
626 out <<
"\\begin{table}[H]" <<
'\n'
627 <<
"\\begin{center}" <<
'\n'
628 <<
"\\begin{tabular}{|";
633 unsigned int max_rows = 0;
634 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
637 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
640 column.second.pad_column_below(max_rows);
643 std::vector<std::string> sel_columns;
650 const std::map<std::string, std::vector<std::string>>::const_iterator
655 const unsigned int n_subcolumns = super_iter->second.size();
656 for (
unsigned int k = 0; k < n_subcolumns; ++k)
659 const std::map<std::string, Column>::const_iterator col_iter =
660 columns.find(super_iter->second[k]);
663 out << col_iter->second.tex_format <<
"|";
669 const std::map<std::string, Column>::const_iterator col_iter =
672 out << col_iter->second.tex_format <<
"|";
675 out <<
"} \\hline" <<
'\n';
682 const std::map<std::string, std::vector<std::string>>::const_iterator
687 const unsigned int n_subcolumns = super_iter->second.size();
689 std::map<std::string, std::string>::const_iterator
692 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
693 << tex_super_cap_iter->second <<
"}";
698 const std::map<std::string, Column>::const_iterator col_iter =
701 out << col_iter->second.tex_caption;
706 out <<
"\\\\ \\hline" <<
'\n';
709 const unsigned int nrows =
n_rows();
710 for (
unsigned int i = 0; i < nrows; ++i)
712 const unsigned int n_cols = sel_columns.size();
714 for (
unsigned int j = 0; j < n_cols; ++j)
716 std::string key = sel_columns[j];
718 const std::map<std::string, Column>::const_iterator col_iter =
722 const Column &column = col_iter->second;
724 out << std::setprecision(column.
precision);
726 if (col_iter->second.scientific)
727 out.setf(std::ios::scientific, std::ios::floatfield);
729 out.setf(std::ios::fixed, std::ios::floatfield);
731#ifdef DEAL_II_HAVE_CXX17
732 std::visit([&out](
auto &v) { out << v; }, column.
entries[i].value);
734 out << column.
entries[i].value;
740 out <<
"\\\\ \\hline" <<
'\n';
743 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
748 out <<
"\\end{table}" <<
'\n';
750 out <<
"\\end{document}" <<
'\n';
778 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
779 unsigned int n = col_iter->second.entries.size();
782 std::string first_name = col_iter->first;
783 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
784 Assert(col_iter->second.entries.size() == n,
786 col_iter->first, col_iter->second.entries.size(), first_name, n));
800 const std::map<std::string, std::vector<std::string>>::const_iterator
806 const unsigned int n_subcolumns = super_iter->second.size();
807 for (
unsigned int k = 0; k < n_subcolumns; ++k)
809 const std::string subkey = super_iter->second[k];
811 sel_columns.push_back(subkey);
818 sel_columns.push_back(key);
829 std::vector<internal::TableEntry>::size_type n = 0;
830 for (
const auto &column :
columns)
831 n =
std::max(n, column.second.entries.size());
836 if (column.second.entries.size() == n)
837 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)
::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