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);
94 std::visit([&ss](
auto &v) { ss << v; },
value);
115 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
127 : tex_caption(tex_caption)
156 while (entries.size() < size)
158 entries.push_back(entries.back().get_default_constructed_copy());
173 for (
const auto &entry : entries)
175 entry.cache_string(this->scientific, this->precision);
178 static_cast<unsigned int>(entry.get_cached_string().size()));
197 ExcMessage(
"You are trying to declare a column with key <" + key +
198 "> but such a column already exists."));
210 unsigned int max_col_length = 0;
211 for (
const auto &column :
columns)
214 static_cast<unsigned int>(column.second.entries.size()));
219 while (column.second.entries.size() < max_col_length)
221 column.second.entries.emplace_back(
"");
223 entry.
cache_string(column.second.scientific, column.second.precision);
224 column.second.max_length =
241 const std::string &superkey)
247 std::pair<std::string, std::vector<std::string>> new_column(
248 superkey, std::vector<std::string>());
262 const auto order_iter =
273 std::pair<std::string, std::string> new_tex_supercaption(superkey,
286 for (
const auto &new_column : new_order)
299 const std::string &tex_caption)
302 columns[key].tex_caption = tex_caption;
325 const std::string &tex_supercaption)
336 const std::string &tex_format)
339 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
341 columns[key].tex_format = tex_format;
348 const unsigned int precision)
351 if (
columns[key].precision != precision)
353 columns[key].precision = precision;
354 columns[key].invalidate_cache();
363 if (
columns[key].scientific != scientific)
365 columns[key].scientific = scientific;
366 columns[key].invalidate_cache();
375 boost::io::ios_flags_saver restore_flags(out);
380 unsigned int max_rows = 0;
381 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
384 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
387 column.second.pad_column_below(max_rows);
390 std::vector<std::string> sel_columns;
393 const unsigned int nrows =
n_rows();
394 const unsigned int n_cols = sel_columns.size();
397 std::vector<const Column *> cols;
398 std::vector<unsigned int> column_widths(n_cols, 0);
399 for (
unsigned int j = 0; j < n_cols; ++j)
401 std::string key = sel_columns[j];
402 const std::map<std::string, Column>::const_iterator col_iter =
405 cols.push_back(&(col_iter->second));
407 column_widths[j] = col_iter->second.max_length;
415 out <<
"| " << std::left;
416 for (
unsigned int j = 0; j < n_cols; ++j)
418 const std::string &key = sel_columns[j];
421 static_cast<unsigned int>(key.size()));
422 out << std::setw(column_widths[j]);
428 for (
unsigned int i = 0; i < nrows; ++i)
431 for (
unsigned int j = 0; j < n_cols; ++j)
433 const Column &column = *(cols[j]);
435 out << std::setw(column_widths[j]);
436 out << column.
entries[i].get_cached_string();
449 for (
unsigned int j = 0; j < n_cols; ++j)
451 const std::string &key = sel_columns[j];
452 out <<
"# " << j + 1 <<
": " << key <<
'\n';
456 for (
unsigned int i = 0; i < nrows; ++i)
458 for (
unsigned int j = 0; j < n_cols; ++j)
460 const Column &column = *(cols[j]);
462 out << column.
entries[i].get_cached_string();
477 for (
unsigned int j = 0; j < n_cols; ++j)
479 std::string key = sel_columns[j];
480 out <<
"# " << j + 1 <<
": " << key <<
'\n';
491 unsigned int width = 0;
494 const std::map<std::string,
495 std::vector<std::string>>::const_iterator
499 const unsigned int n_subcolumns = super_iter->second.size();
500 for (
unsigned int k = 0; k < n_subcolumns; ++k)
502 const std::map<std::string, Column>::const_iterator
503 col_iter =
columns.find(super_iter->second[k]);
506 width += col_iter->second.max_length;
508 width += n_subcolumns - 1;
512 const std::map<std::string, Column>::const_iterator
515 width = col_iter->second.max_length;
520 if (width < key.size())
526 const std::map<std::string,
527 std::vector<std::string>>::const_iterator
530 colname = super_iter->second.back();
535 for (
unsigned int i = 0; i < n_cols; ++i)
537 if (sel_columns[i] == colname)
539 column_widths[i] += key.size() - width;
548 const unsigned int front_padding = (width - key.size()) / 2,
550 (width - key.size()) - front_padding;
551 for (
unsigned int i = 0; i < front_padding; ++i)
554 for (
unsigned int i = 0; i < rear_padding; ++i)
570 for (
unsigned int i = 0; i < nrows; ++i)
572 for (
unsigned int j = 0; j < n_cols; ++j)
574 const Column &column = *(cols[j]);
575 out << std::setw(column_widths[j]);
576 out << column.
entries[i].get_cached_string();
594 out <<
"\\documentclass[10pt]{report}" <<
'\n'
595 <<
"\\usepackage{float}" <<
'\n'
598 <<
"\\begin{document}" <<
'\n';
600 out <<
"\\begin{table}[H]" <<
'\n'
601 <<
"\\begin{center}" <<
'\n'
602 <<
"\\begin{tabular}{|";
607 unsigned int max_rows = 0;
608 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
611 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
614 column.second.pad_column_below(max_rows);
617 std::vector<std::string> sel_columns;
624 const std::map<std::string, std::vector<std::string>>::const_iterator
629 const unsigned int n_subcolumns = super_iter->second.size();
630 for (
unsigned int k = 0; k < n_subcolumns; ++k)
633 const std::map<std::string, Column>::const_iterator col_iter =
634 columns.find(super_iter->second[k]);
637 out << col_iter->second.tex_format <<
"|";
643 const std::map<std::string, Column>::const_iterator col_iter =
646 out << col_iter->second.tex_format <<
"|";
649 out <<
"} \\hline" <<
'\n';
656 const std::map<std::string, std::vector<std::string>>::const_iterator
661 const unsigned int n_subcolumns = super_iter->second.size();
663 std::map<std::string, std::string>::const_iterator
666 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
667 << tex_super_cap_iter->second <<
"}";
672 const std::map<std::string, Column>::const_iterator col_iter =
675 out << col_iter->second.tex_caption;
680 out <<
"\\\\ \\hline" <<
'\n';
683 const unsigned int nrows =
n_rows();
684 for (
unsigned int i = 0; i < nrows; ++i)
686 const unsigned int n_cols = sel_columns.size();
688 for (
unsigned int j = 0; j < n_cols; ++j)
690 std::string key = sel_columns[j];
692 const std::map<std::string, Column>::const_iterator col_iter =
696 const Column &column = col_iter->second;
698 out << std::setprecision(column.
precision);
700 if (col_iter->second.scientific)
701 out.setf(std::ios::scientific, std::ios::floatfield);
703 out.setf(std::ios::fixed, std::ios::floatfield);
705 std::visit([&out](
auto &v) { out << v; }, column.
entries[i].value);
710 out <<
"\\\\ \\hline" <<
'\n';
713 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
718 out <<
"\\end{table}" <<
'\n';
720 out <<
"\\end{document}" <<
'\n';
748 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
749 unsigned int n = col_iter->second.entries.size();
752 std::string first_name = col_iter->first;
753 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
754 Assert(col_iter->second.entries.size() == n,
756 col_iter->first, col_iter->second.entries.size(), first_name, n));
770 const std::map<std::string, std::vector<std::string>>::const_iterator
776 const unsigned int n_subcolumns = super_iter->second.size();
777 for (
unsigned int k = 0; k < n_subcolumns; ++k)
779 const std::string subkey = super_iter->second[k];
781 sel_columns.push_back(subkey);
788 sel_columns.push_back(key);
800 for (
const auto &column :
columns)
801 n =
std::max(n, column.second.entries.size());
806 if (column.second.entries.size() == n)
807 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 & ExcColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcUndefinedTexFormat(std::string arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcColumnOrSuperColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcSuperColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcWrongNumberOfDataEntries(std::string arg1, int arg2, std::string arg3, int arg4)
#define Assert(cond, exc)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
types::global_dof_index size_type
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