17#include <boost/io/ios_state.hpp>
44 return std::get<int>(
value);
53 return std::get<unsigned int>(
value);
61 return std::get<std::uint64_t>(
value);
69 return std::get<double>(
value);
74 ExcMessage(
"The number stored by this element of the "
75 "table is not a number."));
84 std::ostringstream ss;
86 ss << std::setprecision(precision);
89 ss.setf(std::ios::scientific, std::ios::floatfield);
91 ss.setf(std::ios::fixed, std::ios::floatfield);
93 std::visit([&ss](
const auto &v) { ss << v; },
value);
114 auto &arg) { arg = std::remove_reference_t<decltype(arg)>(); },
126 : tex_caption(tex_caption)
155 while (entries.size() < size)
157 entries.push_back(entries.back().get_default_constructed_copy());
172 for (
const auto &entry : entries)
174 entry.cache_string(this->scientific, this->precision);
177 static_cast<unsigned int>(entry.get_cached_string().size()));
196 ExcMessage(
"You are trying to declare a column with key <" + key +
197 "> but such a column already exists."));
209 unsigned int max_col_length = 0;
210 for (
const auto &column :
columns)
213 static_cast<unsigned int>(column.second.entries.size()));
218 while (column.second.entries.size() < max_col_length)
220 column.second.entries.emplace_back(
"");
222 entry.
cache_string(column.second.scientific, column.second.precision);
223 column.second.max_length =
240 const std::string &superkey)
246 std::pair<std::string, std::vector<std::string>> new_column(
247 superkey, std::vector<std::string>());
261 const auto order_iter =
272 std::pair<std::string, std::string> new_tex_supercaption(superkey,
285 for (
const auto &new_column : new_order)
298 const std::string &tex_caption)
301 columns[key].tex_caption = tex_caption;
324 const std::string &tex_supercaption)
335 const std::string &tex_format)
338 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
340 columns[key].tex_format = tex_format;
347 const unsigned int precision)
350 if (
columns[key].precision != precision)
352 columns[key].precision = precision;
353 columns[key].invalidate_cache();
362 if (
columns[key].scientific != scientific)
364 columns[key].scientific = scientific;
365 columns[key].invalidate_cache();
374 boost::io::ios_flags_saver restore_flags(out);
379 unsigned int max_rows = 0;
380 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
386 column.second.pad_column_below(max_rows);
389 std::vector<std::string> sel_columns;
392 const unsigned int nrows =
n_rows();
393 const unsigned int n_cols = sel_columns.size();
396 std::vector<const Column *> cols;
397 std::vector<unsigned int> column_widths(n_cols, 0);
398 for (
unsigned int j = 0; j < n_cols; ++j)
400 std::string key = sel_columns[j];
401 const std::map<std::string, Column>::const_iterator col_iter =
404 cols.push_back(&(col_iter->second));
406 column_widths[j] = col_iter->second.max_length;
414 out <<
"| " << std::left;
415 for (
unsigned int j = 0; j < n_cols; ++j)
417 const std::string &key = sel_columns[j];
420 static_cast<unsigned int>(key.size()));
421 out << std::setw(column_widths[j]);
427 for (
unsigned int i = 0; i < nrows; ++i)
430 for (
unsigned int j = 0; j < n_cols; ++j)
432 const Column &column = *(cols[j]);
434 out << std::setw(column_widths[j]);
435 out << column.
entries[i].get_cached_string();
448 for (
unsigned int j = 0; j < n_cols; ++j)
450 const std::string &key = sel_columns[j];
451 out <<
"# " << j + 1 <<
": " << key <<
'\n';
455 for (
unsigned int i = 0; i < nrows; ++i)
457 for (
unsigned int j = 0; j < n_cols; ++j)
459 const Column &column = *(cols[j]);
461 out << column.
entries[i].get_cached_string();
476 for (
unsigned int j = 0; j < n_cols; ++j)
478 std::string key = sel_columns[j];
479 out <<
"# " << j + 1 <<
": " << key <<
'\n';
490 unsigned int width = 0;
493 const std::map<std::string,
494 std::vector<std::string>>::const_iterator
498 const unsigned int n_subcolumns = super_iter->second.size();
499 for (
unsigned int k = 0; k < n_subcolumns; ++k)
501 const std::map<std::string, Column>::const_iterator
502 col_iter =
columns.find(super_iter->second[k]);
505 width += col_iter->second.max_length;
507 width += n_subcolumns - 1;
511 const std::map<std::string, Column>::const_iterator
514 width = col_iter->second.max_length;
519 if (width < key.size())
525 const std::map<std::string,
526 std::vector<std::string>>::const_iterator
529 colname = super_iter->second.back();
534 for (
unsigned int i = 0; i < n_cols; ++i)
536 if (sel_columns[i] == colname)
538 column_widths[i] += key.size() - width;
547 const unsigned int front_padding = (width - key.size()) / 2,
549 (width - key.size()) - front_padding;
550 for (
unsigned int i = 0; i < front_padding; ++i)
553 for (
unsigned int i = 0; i < rear_padding; ++i)
569 for (
unsigned int i = 0; i < nrows; ++i)
571 for (
unsigned int j = 0; j < n_cols; ++j)
573 const Column &column = *(cols[j]);
574 out << std::setw(column_widths[j]);
575 out << column.
entries[i].get_cached_string();
593 out <<
"\\documentclass[10pt]{report}" <<
'\n'
594 <<
"\\usepackage{float}" <<
'\n'
597 <<
"\\begin{document}" <<
'\n';
599 out <<
"\\begin{table}[H]" <<
'\n'
600 <<
"\\begin{center}" <<
'\n'
601 <<
"\\begin{tabular}{|";
606 unsigned int max_rows = 0;
607 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
613 column.second.pad_column_below(max_rows);
616 std::vector<std::string> sel_columns;
623 const std::map<std::string, std::vector<std::string>>::const_iterator
628 const unsigned int n_subcolumns = super_iter->second.size();
629 for (
unsigned int k = 0; k < n_subcolumns; ++k)
632 const std::map<std::string, Column>::const_iterator col_iter =
633 columns.find(super_iter->second[k]);
636 out << col_iter->second.tex_format <<
"|";
642 const std::map<std::string, Column>::const_iterator col_iter =
645 out << col_iter->second.tex_format <<
"|";
648 out <<
"} \\hline" <<
'\n';
655 const std::map<std::string, std::vector<std::string>>::const_iterator
660 const unsigned int n_subcolumns = super_iter->second.size();
662 std::map<std::string, std::string>::const_iterator
665 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
666 << tex_super_cap_iter->second <<
"}";
671 const std::map<std::string, Column>::const_iterator col_iter =
674 out << col_iter->second.tex_caption;
679 out <<
"\\\\ \\hline" <<
'\n';
682 const unsigned int nrows =
n_rows();
683 for (
unsigned int i = 0; i < nrows; ++i)
685 const unsigned int n_cols = sel_columns.size();
687 for (
unsigned int j = 0; j < n_cols; ++j)
689 std::string key = sel_columns[j];
691 const std::map<std::string, Column>::const_iterator col_iter =
695 const Column &column = col_iter->second;
697 out << std::setprecision(column.
precision);
699 if (col_iter->second.scientific)
700 out.setf(std::ios::scientific, std::ios::floatfield);
702 out.setf(std::ios::fixed, std::ios::floatfield);
704 std::visit([&out](
const auto &v) { out << v; },
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);
799 std::vector<internal::TableEntry>::size_type n = 0;
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 & 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