18#include <boost/io/ios_state.hpp>
46 return std::get<int>(
value);
55 return std::get<unsigned int>(
value);
63 return std::get<std::uint64_t>(
value);
71 return std::get<double>(
value);
76 ExcMessage(
"The number stored by this element of the "
77 "table is not a number."));
86 std::ostringstream ss;
88 ss << std::setprecision(precision);
91 ss.setf(std::ios::scientific, std::ios::floatfield);
93 ss.setf(std::ios::fixed, std::ios::floatfield);
98 std::visit([&ss](
const auto &v) { ss << v; },
value);
119 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
131 : tex_caption(tex_caption)
160 while (entries.size() <
size)
162 entries.push_back(entries.back().get_default_constructed_copy());
177 for (
const auto &entry : entries)
179 entry.cache_string(this->scientific, this->precision);
182 static_cast<unsigned int>(entry.get_cached_string().size()));
201 ExcMessage(
"You are trying to declare a column with key <" + key +
202 "> but such a column already exists."));
214 unsigned int max_col_length = 0;
215 for (
const auto &column :
columns)
218 static_cast<unsigned int>(column.second.entries.size()));
223 while (column.second.entries.size() < max_col_length)
225 column.second.entries.emplace_back(
"");
227 entry.
cache_string(column.second.scientific, column.second.precision);
228 column.second.max_length =
245 const std::string &superkey)
251 std::pair<std::string, std::vector<std::string>> new_column(
252 superkey, std::vector<std::string>());
266 const auto order_iter =
277 std::pair<std::string, std::string> new_tex_supercaption(superkey,
290 for (
const auto &new_column : new_order)
303 const std::string &tex_caption)
306 columns[key].tex_caption = tex_caption;
329 const std::string &tex_supercaption)
340 const std::string &tex_format)
343 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
345 columns[key].tex_format = tex_format;
352 const unsigned int precision)
355 if (
columns[key].precision != precision)
357 columns[key].precision = precision;
358 columns[key].invalidate_cache();
367 if (
columns[key].scientific != scientific)
369 columns[key].scientific = scientific;
370 columns[key].invalidate_cache();
379 boost::io::ios_flags_saver restore_flags(out);
384 unsigned int max_rows = 0;
385 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
388 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
391 column.second.pad_column_below(max_rows);
394 std::vector<std::string> sel_columns;
397 const unsigned int nrows =
n_rows();
398 const unsigned int n_cols = sel_columns.size();
401 std::vector<const Column *> cols;
402 std::vector<unsigned int> column_widths(n_cols, 0);
403 for (
unsigned int j = 0; j < n_cols; ++j)
405 const std::string &key = sel_columns[j];
406 const std::map<std::string, Column>::const_iterator col_iter =
409 cols.push_back(&(col_iter->second));
411 column_widths[j] = col_iter->second.max_length;
419 out <<
"| " << std::left;
420 for (
unsigned int j = 0; j < n_cols; ++j)
422 const std::string &key = sel_columns[j];
425 static_cast<unsigned int>(key.size()));
426 out << std::setw(column_widths[j]);
432 for (
unsigned int i = 0; i < nrows; ++i)
435 for (
unsigned int j = 0; j < n_cols; ++j)
437 const Column &column = *(cols[j]);
439 out << std::setw(column_widths[j]);
440 out << column.
entries[i].get_cached_string();
453 for (
unsigned int j = 0; j < n_cols; ++j)
455 const std::string &key = sel_columns[j];
456 out <<
"# " << j + 1 <<
": " << key <<
'\n';
460 for (
unsigned int i = 0; i < nrows; ++i)
462 for (
unsigned int j = 0; j < n_cols; ++j)
464 const Column &column = *(cols[j]);
466 out << column.
entries[i].get_cached_string();
481 for (
unsigned int j = 0; j < n_cols; ++j)
483 const std::string &key = sel_columns[j];
484 out <<
"# " << j + 1 <<
": " << key <<
'\n';
495 unsigned int width = 0;
498 const std::map<std::string,
499 std::vector<std::string>>::const_iterator
503 const unsigned int n_subcolumns = super_iter->second.size();
504 for (
unsigned int k = 0; k < n_subcolumns; ++k)
506 const std::map<std::string, Column>::const_iterator
507 col_iter =
columns.find(super_iter->second[k]);
510 width += col_iter->second.max_length;
512 width += n_subcolumns - 1;
516 const std::map<std::string, Column>::const_iterator
519 width = col_iter->second.max_length;
524 if (width < key.size())
530 const std::map<std::string,
531 std::vector<std::string>>::const_iterator
534 colname = super_iter->second.back();
539 for (
unsigned int i = 0; i < n_cols; ++i)
541 if (sel_columns[i] == colname)
543 column_widths[i] += key.size() - width;
552 const unsigned int front_padding = (width - key.size()) / 2,
554 (width - key.size()) - front_padding;
555 for (
unsigned int i = 0; i < front_padding; ++i)
558 for (
unsigned int i = 0; i < rear_padding; ++i)
574 for (
unsigned int i = 0; i < nrows; ++i)
576 for (
unsigned int j = 0; j < n_cols; ++j)
578 const Column &column = *(cols[j]);
579 out << std::setw(column_widths[j]);
580 out << column.
entries[i].get_cached_string();
598 out <<
"\\documentclass[10pt]{report}" <<
'\n'
599 <<
"\\usepackage{float}" <<
'\n'
602 <<
"\\begin{document}" <<
'\n';
604 out <<
"\\begin{table}[H]" <<
'\n'
605 <<
"\\begin{center}" <<
'\n'
606 <<
"\\begin{tabular}{|";
611 unsigned int max_rows = 0;
612 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
615 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
618 column.second.pad_column_below(max_rows);
621 std::vector<std::string> sel_columns;
628 const std::map<std::string, std::vector<std::string>>::const_iterator
633 const unsigned int n_subcolumns = super_iter->second.size();
634 for (
unsigned int k = 0; k < n_subcolumns; ++k)
637 const std::map<std::string, Column>::const_iterator col_iter =
638 columns.find(super_iter->second[k]);
641 out << col_iter->second.tex_format <<
"|";
647 const std::map<std::string, Column>::const_iterator col_iter =
650 out << col_iter->second.tex_format <<
"|";
653 out <<
"} \\hline" <<
'\n';
660 const std::map<std::string, std::vector<std::string>>::const_iterator
665 const unsigned int n_subcolumns = super_iter->second.size();
667 std::map<std::string, std::string>::const_iterator
670 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
671 << tex_super_cap_iter->second <<
"}";
676 const std::map<std::string, Column>::const_iterator col_iter =
679 out << col_iter->second.tex_caption;
684 out <<
"\\\\ \\hline" <<
'\n';
687 const unsigned int nrows =
n_rows();
688 for (
unsigned int i = 0; i < nrows; ++i)
690 const unsigned int n_cols = sel_columns.size();
692 for (
unsigned int j = 0; j < n_cols; ++j)
694 const std::string &key = sel_columns[j];
696 const std::map<std::string, Column>::const_iterator col_iter =
700 const Column &column = col_iter->second;
702 out << std::setprecision(column.
precision);
704 if (col_iter->second.scientific)
705 out.setf(std::ios::scientific, std::ios::floatfield);
707 out.setf(std::ios::fixed, std::ios::floatfield);
709 std::visit([&out](
const auto &v) { out << v; },
715 out <<
"\\\\ \\hline" <<
'\n';
718 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
723 out <<
"\\end{table}" <<
'\n';
725 out <<
"\\end{document}" <<
'\n';
753 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
754 unsigned int n = col_iter->second.entries.size();
758 std::string first_name = col_iter->first;
759 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
760 Assert(col_iter->second.entries.size() == n,
762 col_iter->second.entries.size(),
778 const std::map<std::string, std::vector<std::string>>::const_iterator
784 const unsigned int n_subcolumns = super_iter->second.size();
785 for (
unsigned int k = 0; k < n_subcolumns; ++k)
787 const std::string subkey = super_iter->second[k];
789 sel_columns.push_back(subkey);
796 sel_columns.push_back(key);
807 std::vector<internal::TableEntry>::size_type n = 0;
808 for (
const auto &column :
columns)
809 n =
std::max(n, column.second.entries.size());
814 if (column.second.entries.size() == n)
815 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