16#include <boost/io/ios_state.hpp>
41 if (
const auto *stored_value = std::get_if<int>(&
value))
45 if (
const auto *stored_value = std::get_if<unsigned int>(&
value))
49 if (
const auto *stored_value = std::get_if<std::uint64_t>(&
value))
53 if (
const auto *stored_value = std::get_if<double>(&
value))
57 ExcMessage(
"The entry stored by this element of the "
58 "table is not a number."));
66 std::ostringstream ss;
68 ss << std::setprecision(precision);
71 ss.setf(std::ios::scientific, std::ios::floatfield);
73 ss.setf(std::ios::fixed, std::ios::floatfield);
78 std::visit([&ss](
const auto &v) { ss << v; },
value);
99 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
109 : tex_caption(tex_caption)
138 while (entries.size() <
size)
140 entries.push_back(entries.back().get_default_constructed_copy());
155 for (
const auto &entry : entries)
157 entry.cache_string(this->scientific, this->precision);
160 static_cast<unsigned int>(entry.get_cached_string().size()));
179 ExcMessage(
"You are trying to declare a column with key <" + key +
180 "> but such a column already exists."));
192 unsigned int max_col_length = 0;
193 for (
const auto &column :
columns)
196 static_cast<unsigned int>(column.second.entries.size()));
201 while (column.second.entries.size() < max_col_length)
203 column.second.entries.emplace_back(
"");
205 entry.
cache_string(column.second.scientific, column.second.precision);
206 column.second.max_length =
223 const std::string &superkey)
229 std::pair<std::string, std::vector<std::string>> new_column(
230 superkey, std::vector<std::string>());
244 const auto order_iter =
255 std::pair<std::string, std::string> new_tex_supercaption(superkey,
268 for (
const auto &new_column : new_order)
281 const std::string &tex_caption)
284 columns[key].tex_caption = tex_caption;
307 const std::string &tex_supercaption)
318 const std::string &tex_format)
321 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
323 columns[key].tex_format = tex_format;
330 const unsigned int precision)
333 if (
columns[key].precision != precision)
335 columns[key].precision = precision;
336 columns[key].invalidate_cache();
345 if (
columns[key].scientific != scientific)
347 columns[key].scientific = scientific;
348 columns[key].invalidate_cache();
357 boost::io::ios_flags_saver restore_flags(out);
362 unsigned int max_rows = 0;
363 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
366 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
369 column.second.pad_column_below(max_rows);
372 std::vector<std::string> sel_columns;
375 const unsigned int nrows =
n_rows();
376 const unsigned int n_cols = sel_columns.size();
379 std::vector<const Column *> cols;
380 std::vector<unsigned int> column_widths(n_cols, 0);
381 for (
unsigned int j = 0; j < n_cols; ++j)
383 const std::string &key = sel_columns[j];
384 const std::map<std::string, Column>::const_iterator col_iter =
387 cols.push_back(&(col_iter->second));
389 column_widths[j] = col_iter->second.max_length;
397 out <<
"| " << std::left;
398 for (
unsigned int j = 0; j < n_cols; ++j)
400 const std::string &key = sel_columns[j];
403 static_cast<unsigned int>(key.size()));
404 out << std::setw(column_widths[j]);
410 for (
unsigned int i = 0; i < nrows; ++i)
413 for (
unsigned int j = 0; j < n_cols; ++j)
415 const Column &column = *(cols[j]);
417 out << std::setw(column_widths[j]);
418 out << column.
entries[i].get_cached_string();
431 for (
unsigned int j = 0; j < n_cols; ++j)
433 const std::string &key = sel_columns[j];
434 out <<
"# " << j + 1 <<
": " << key <<
'\n';
438 for (
unsigned int i = 0; i < nrows; ++i)
440 for (
unsigned int j = 0; j < n_cols; ++j)
442 const Column &column = *(cols[j]);
444 out << column.
entries[i].get_cached_string();
459 for (
unsigned int j = 0; j < n_cols; ++j)
461 const std::string &key = sel_columns[j];
462 out <<
"# " << j + 1 <<
": " << key <<
'\n';
473 unsigned int width = 0;
476 const std::map<std::string,
477 std::vector<std::string>>::const_iterator
481 const unsigned int n_subcolumns = super_iter->second.size();
482 for (
unsigned int k = 0; k < n_subcolumns; ++k)
484 const std::map<std::string, Column>::const_iterator
485 col_iter =
columns.find(super_iter->second[k]);
488 width += col_iter->second.max_length;
490 width += n_subcolumns - 1;
494 const std::map<std::string, Column>::const_iterator
497 width = col_iter->second.max_length;
502 if (width < key.size())
508 const std::map<std::string,
509 std::vector<std::string>>::const_iterator
512 colname = super_iter->second.back();
517 for (
unsigned int i = 0; i < n_cols; ++i)
519 if (sel_columns[i] == colname)
521 column_widths[i] += key.size() - width;
530 const unsigned int front_padding = (width - key.size()) / 2,
532 (width - key.size()) - front_padding;
533 for (
unsigned int i = 0; i < front_padding; ++i)
536 for (
unsigned int i = 0; i < rear_padding; ++i)
552 for (
unsigned int i = 0; i < nrows; ++i)
554 for (
unsigned int j = 0; j < n_cols; ++j)
556 const Column &column = *(cols[j]);
557 out << std::setw(column_widths[j]);
558 out << column.
entries[i].get_cached_string();
576 out <<
"\\documentclass[10pt]{report}" <<
'\n'
577 <<
"\\usepackage{float}" <<
'\n'
580 <<
"\\begin{document}" <<
'\n';
582 out <<
"\\begin{table}[H]" <<
'\n'
583 <<
"\\begin{center}" <<
'\n'
584 <<
"\\begin{tabular}{|";
589 unsigned int max_rows = 0;
590 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
593 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
596 column.second.pad_column_below(max_rows);
599 std::vector<std::string> sel_columns;
606 const std::map<std::string, std::vector<std::string>>::const_iterator
611 const unsigned int n_subcolumns = super_iter->second.size();
612 for (
unsigned int k = 0; k < n_subcolumns; ++k)
615 const std::map<std::string, Column>::const_iterator col_iter =
616 columns.find(super_iter->second[k]);
619 out << col_iter->second.tex_format <<
"|";
625 const std::map<std::string, Column>::const_iterator col_iter =
628 out << col_iter->second.tex_format <<
"|";
631 out <<
"} \\hline" <<
'\n';
638 const std::map<std::string, std::vector<std::string>>::const_iterator
643 const unsigned int n_subcolumns = super_iter->second.size();
645 std::map<std::string, std::string>::const_iterator
648 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
649 << tex_super_cap_iter->second <<
"}";
654 const std::map<std::string, Column>::const_iterator col_iter =
657 out << col_iter->second.tex_caption;
662 out <<
"\\\\ \\hline" <<
'\n';
665 const unsigned int nrows =
n_rows();
666 for (
unsigned int i = 0; i < nrows; ++i)
668 const unsigned int n_cols = sel_columns.size();
670 for (
unsigned int j = 0; j < n_cols; ++j)
672 const std::string &key = sel_columns[j];
674 const std::map<std::string, Column>::const_iterator col_iter =
678 const Column &column = col_iter->second;
680 out << std::setprecision(column.
precision);
682 if (col_iter->second.scientific)
683 out.setf(std::ios::scientific, std::ios::floatfield);
685 out.setf(std::ios::fixed, std::ios::floatfield);
687 std::visit([&out](
const auto &v) { out << v; },
693 out <<
"\\\\ \\hline" <<
'\n';
696 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
701 out <<
"\\end{table}" <<
'\n';
703 out <<
"\\end{document}" <<
'\n';
731 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
732 unsigned int n = col_iter->second.entries.size();
736 std::string first_name = col_iter->first;
737 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
738 Assert(col_iter->second.entries.size() == n,
740 col_iter->second.entries.size(),
756 const std::map<std::string, std::vector<std::string>>::const_iterator
762 const unsigned int n_subcolumns = super_iter->second.size();
763 for (
unsigned int k = 0; k < n_subcolumns; ++k)
765 const std::string subkey = super_iter->second[k];
767 sel_columns.push_back(subkey);
774 sel_columns.push_back(key);
785 std::vector<internal::TableEntry>::size_type n = 0;
786 for (
const auto &column :
columns)
787 n =
std::max(n, column.second.entries.size());
792 if (column.second.entries.size() == n)
793 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
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ASSERT_UNREACHABLE()
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