18#include <boost/io/ios_state.hpp>
45 return std::get<int>(
value);
54 return std::get<unsigned int>(
value);
62 return std::get<std::uint64_t>(
value);
70 return std::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);
97 std::visit([&ss](
const auto &v) { ss << v; },
value);
118 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
130 : tex_caption(tex_caption)
159 while (entries.size() <
size)
161 entries.push_back(entries.back().get_default_constructed_copy());
176 for (
const auto &entry : entries)
178 entry.cache_string(this->scientific, this->precision);
181 static_cast<unsigned int>(entry.get_cached_string().size()));
200 ExcMessage(
"You are trying to declare a column with key <" + key +
201 "> but such a column already exists."));
213 unsigned int max_col_length = 0;
214 for (
const auto &column :
columns)
217 static_cast<unsigned int>(column.second.entries.size()));
222 while (column.second.entries.size() < max_col_length)
224 column.second.entries.emplace_back(
"");
226 entry.
cache_string(column.second.scientific, column.second.precision);
227 column.second.max_length =
244 const std::string &superkey)
250 std::pair<std::string, std::vector<std::string>> new_column(
251 superkey, std::vector<std::string>());
265 const auto order_iter =
276 std::pair<std::string, std::string> new_tex_supercaption(superkey,
289 for (
const auto &new_column : new_order)
302 const std::string &tex_caption)
305 columns[key].tex_caption = tex_caption;
328 const std::string &tex_supercaption)
339 const std::string &tex_format)
342 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
344 columns[key].tex_format = tex_format;
351 const unsigned int precision)
354 if (
columns[key].precision != precision)
356 columns[key].precision = precision;
357 columns[key].invalidate_cache();
366 if (
columns[key].scientific != scientific)
368 columns[key].scientific = scientific;
369 columns[key].invalidate_cache();
378 boost::io::ios_flags_saver restore_flags(out);
383 unsigned int max_rows = 0;
384 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
387 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
390 column.second.pad_column_below(max_rows);
393 std::vector<std::string> sel_columns;
396 const unsigned int nrows =
n_rows();
397 const unsigned int n_cols = sel_columns.size();
400 std::vector<const Column *> cols;
401 std::vector<unsigned int> column_widths(n_cols, 0);
402 for (
unsigned int j = 0; j < n_cols; ++j)
404 std::string key = sel_columns[j];
405 const std::map<std::string, Column>::const_iterator col_iter =
408 cols.push_back(&(col_iter->second));
410 column_widths[j] = col_iter->second.max_length;
418 out <<
"| " << std::left;
419 for (
unsigned int j = 0; j < n_cols; ++j)
421 const std::string &key = sel_columns[j];
424 static_cast<unsigned int>(key.size()));
425 out << std::setw(column_widths[j]);
431 for (
unsigned int i = 0; i < nrows; ++i)
434 for (
unsigned int j = 0; j < n_cols; ++j)
436 const Column &column = *(cols[j]);
438 out << std::setw(column_widths[j]);
439 out << column.
entries[i].get_cached_string();
452 for (
unsigned int j = 0; j < n_cols; ++j)
454 const std::string &key = sel_columns[j];
455 out <<
"# " << j + 1 <<
": " << key <<
'\n';
459 for (
unsigned int i = 0; i < nrows; ++i)
461 for (
unsigned int j = 0; j < n_cols; ++j)
463 const Column &column = *(cols[j]);
465 out << column.
entries[i].get_cached_string();
480 for (
unsigned int j = 0; j < n_cols; ++j)
482 std::string key = sel_columns[j];
483 out <<
"# " << j + 1 <<
": " << key <<
'\n';
494 unsigned int width = 0;
497 const std::map<std::string,
498 std::vector<std::string>>::const_iterator
502 const unsigned int n_subcolumns = super_iter->second.size();
503 for (
unsigned int k = 0; k < n_subcolumns; ++k)
505 const std::map<std::string, Column>::const_iterator
506 col_iter =
columns.find(super_iter->second[k]);
509 width += col_iter->second.max_length;
511 width += n_subcolumns - 1;
515 const std::map<std::string, Column>::const_iterator
518 width = col_iter->second.max_length;
523 if (width < key.size())
529 const std::map<std::string,
530 std::vector<std::string>>::const_iterator
533 colname = super_iter->second.back();
538 for (
unsigned int i = 0; i < n_cols; ++i)
540 if (sel_columns[i] == colname)
542 column_widths[i] += key.size() - width;
551 const unsigned int front_padding = (width - key.size()) / 2,
553 (width - key.size()) - front_padding;
554 for (
unsigned int i = 0; i < front_padding; ++i)
557 for (
unsigned int i = 0; i < rear_padding; ++i)
573 for (
unsigned int i = 0; i < nrows; ++i)
575 for (
unsigned int j = 0; j < n_cols; ++j)
577 const Column &column = *(cols[j]);
578 out << std::setw(column_widths[j]);
579 out << column.
entries[i].get_cached_string();
597 out <<
"\\documentclass[10pt]{report}" <<
'\n'
598 <<
"\\usepackage{float}" <<
'\n'
601 <<
"\\begin{document}" <<
'\n';
603 out <<
"\\begin{table}[H]" <<
'\n'
604 <<
"\\begin{center}" <<
'\n'
605 <<
"\\begin{tabular}{|";
610 unsigned int max_rows = 0;
611 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
614 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
617 column.second.pad_column_below(max_rows);
620 std::vector<std::string> sel_columns;
627 const std::map<std::string, std::vector<std::string>>::const_iterator
632 const unsigned int n_subcolumns = super_iter->second.size();
633 for (
unsigned int k = 0; k < n_subcolumns; ++k)
636 const std::map<std::string, Column>::const_iterator col_iter =
637 columns.find(super_iter->second[k]);
640 out << col_iter->second.tex_format <<
"|";
646 const std::map<std::string, Column>::const_iterator col_iter =
649 out << col_iter->second.tex_format <<
"|";
652 out <<
"} \\hline" <<
'\n';
659 const std::map<std::string, std::vector<std::string>>::const_iterator
664 const unsigned int n_subcolumns = super_iter->second.size();
666 std::map<std::string, std::string>::const_iterator
669 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
670 << tex_super_cap_iter->second <<
"}";
675 const std::map<std::string, Column>::const_iterator col_iter =
678 out << col_iter->second.tex_caption;
683 out <<
"\\\\ \\hline" <<
'\n';
686 const unsigned int nrows =
n_rows();
687 for (
unsigned int i = 0; i < nrows; ++i)
689 const unsigned int n_cols = sel_columns.size();
691 for (
unsigned int j = 0; j < n_cols; ++j)
693 std::string key = sel_columns[j];
695 const std::map<std::string, Column>::const_iterator col_iter =
699 const Column &column = col_iter->second;
701 out << std::setprecision(column.
precision);
703 if (col_iter->second.scientific)
704 out.setf(std::ios::scientific, std::ios::floatfield);
706 out.setf(std::ios::fixed, std::ios::floatfield);
708 std::visit([&out](
const auto &v) { out << v; },
714 out <<
"\\\\ \\hline" <<
'\n';
717 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
722 out <<
"\\end{table}" <<
'\n';
724 out <<
"\\end{document}" <<
'\n';
752 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
753 unsigned int n = col_iter->second.entries.size();
756 std::string first_name = col_iter->first;
757 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
758 Assert(col_iter->second.entries.size() == n,
760 col_iter->first, col_iter->second.entries.size(), first_name, n));
774 const std::map<std::string, std::vector<std::string>>::const_iterator
780 const unsigned int n_subcolumns = super_iter->second.size();
781 for (
unsigned int k = 0; k < n_subcolumns; ++k)
783 const std::string subkey = super_iter->second[k];
785 sel_columns.push_back(subkey);
792 sel_columns.push_back(key);
803 std::vector<internal::TableEntry>::size_type n = 0;
804 for (
const auto &column :
columns)
805 n =
std::max(n, column.second.entries.size());
810 if (column.second.entries.size() == n)
811 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