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
119 template <
typename T>
133#ifndef DEAL_II_HAVE_CXX17
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."));
237 for (
const auto &column :
columns)
240 static_cast<unsigned int>(column.second.entries.size()));
247 column.second.entries.emplace_back(
"");
249 entry.
cache_string(column.second.scientific, column.second.precision);
250 column.second.max_length =
273 std::pair<std::string, std::vector<std::string>>
new_column(
274 superkey, std::vector<std::string>());
325 const std::string &tex_caption)
362 const std::string &tex_format)
365 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
374 const unsigned int precision)
407 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
413 column.second.pad_column_below(
max_rows);
423 std::vector<const Column *> cols;
425 for (
unsigned int j = 0;
j < n_cols; ++
j)
428 const std::map<std::string, Column>::const_iterator
col_iter =
431 cols.push_back(&(
col_iter->second));
441 out <<
"| " << std::left;
442 for (
unsigned int j = 0;
j < n_cols; ++
j)
447 static_cast<unsigned int>(
key.
size()));
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]);
462 out << column.
entries[i].get_cached_string();
475 for (
unsigned int j = 0;
j < n_cols; ++
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)
506 out <<
"# " <<
j + 1 <<
": " <<
key <<
'\n';
517 unsigned int width = 0;
520 const std::map<std::string,
521 std::vector<std::string>>::const_iterator
528 const std::map<std::string, Column>::const_iterator
532 width +=
col_iter->second.max_length;
538 const std::map<std::string, Column>::const_iterator
541 width =
col_iter->second.max_length;
552 const std::map<std::string,
553 std::vector<std::string>>::const_iterator
561 for (
unsigned int i = 0; i < n_cols; ++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]);
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}{|";
634 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
640 column.second.pad_column_below(
max_rows);
650 const std::map<std::string, std::vector<std::string>>::const_iterator
659 const std::map<std::string, Column>::const_iterator
col_iter =
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
689 std::map<std::string, std::string>::const_iterator
698 const std::map<std::string, Column>::const_iterator
col_iter =
701 out <<
col_iter->second.tex_caption;
706 out <<
"\\\\ \\hline" <<
'\n';
710 for (
unsigned int i = 0; i <
nrows; ++i)
714 for (
unsigned int j = 0;
j < n_cols; ++
j)
718 const std::map<std::string, Column>::const_iterator
col_iter =
724 out << std::setprecision(column.
precision);
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';
800 const std::map<std::string, std::vector<std::string>>::const_iterator
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