18#include <boost/io/ios_state.hpp>
45 return boost::get<int>(
value);
54 return boost::get<unsigned int>(
value);
62 return boost::get<std::uint64_t>(
value);
70 return boost::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);
114 template <
typename T>
138 : tex_caption(tex_caption)
167 while (entries.size() < size)
169 entries.push_back(entries.back().get_default_constructed_copy());
184 for (
const auto &entry : entries)
186 entry.cache_string(this->scientific, this->precision);
189 static_cast<unsigned int>(entry.get_cached_string().length()));
208 ExcMessage(
"You are trying to declare a column with key <" + key +
209 "> but such a column already exists."));
221 unsigned int max_col_length = 0;
222 for (
const auto &column :
columns)
225 static_cast<unsigned int>(column.second.entries.size()));
230 while (column.second.entries.size() < max_col_length)
232 column.second.entries.emplace_back(
"");
234 entry.
cache_string(column.second.scientific, column.second.precision);
235 column.second.max_length =
237 static_cast<unsigned int>(
253 const std::string &superkey)
259 std::pair<std::string, std::vector<std::string>> new_column(
260 superkey, std::vector<std::string>());
274 const auto order_iter =
285 std::pair<std::string, std::string> new_tex_supercaption(superkey,
298 for (
const auto &new_column : new_order)
311 const std::string &tex_caption)
314 columns[key].tex_caption = tex_caption;
337 const std::string &tex_supercaption)
348 const std::string &tex_format)
351 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
353 columns[key].tex_format = tex_format;
360 const unsigned int precision)
363 if (
columns[key].precision != precision)
365 columns[key].precision = precision;
366 columns[key].invalidate_cache();
375 if (
columns[key].scientific != scientific)
377 columns[key].scientific = scientific;
378 columns[key].invalidate_cache();
387 boost::io::ios_flags_saver restore_flags(out);
392 unsigned int max_rows = 0;
393 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
396 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
399 column.second.pad_column_below(max_rows);
402 std::vector<std::string> sel_columns;
405 const unsigned int nrows =
n_rows();
406 const unsigned int n_cols = sel_columns.size();
409 std::vector<const Column *> cols;
410 std::vector<unsigned int> column_widths(n_cols, 0);
411 for (
unsigned int j = 0; j < n_cols; ++j)
413 std::string key = sel_columns[j];
414 const std::map<std::string, Column>::const_iterator col_iter =
417 cols.push_back(&(col_iter->second));
419 column_widths[j] = col_iter->second.max_length;
427 out <<
"| " << std::left;
428 for (
unsigned int j = 0; j < n_cols; ++j)
430 const std::string &key = sel_columns[j];
433 static_cast<unsigned int>(key.length()));
434 out << std::setw(column_widths[j]);
440 for (
unsigned int i = 0; i < nrows; ++i)
443 for (
unsigned int j = 0; j < n_cols; ++j)
445 const Column &column = *(cols[j]);
447 out << std::setw(column_widths[j]);
448 out << column.
entries[i].get_cached_string();
461 for (
unsigned int j = 0; j < n_cols; ++j)
463 const std::string &key = sel_columns[j];
464 out <<
"# " << j + 1 <<
": " << key <<
'\n';
468 for (
unsigned int i = 0; i < nrows; ++i)
470 for (
unsigned int j = 0; j < n_cols; ++j)
472 const Column &column = *(cols[j]);
474 out << column.
entries[i].get_cached_string();
489 for (
unsigned int j = 0; j < n_cols; ++j)
491 std::string key = sel_columns[j];
492 out <<
"# " << j + 1 <<
": " << key <<
'\n';
503 unsigned int width = 0;
506 const std::map<std::string,
507 std::vector<std::string>>::const_iterator
511 const unsigned int n_subcolumns = super_iter->second.size();
512 for (
unsigned int k = 0; k < n_subcolumns; ++k)
514 const std::map<std::string, Column>::const_iterator
515 col_iter =
columns.find(super_iter->second[k]);
518 width += col_iter->second.max_length;
520 width += n_subcolumns - 1;
524 const std::map<std::string, Column>::const_iterator
527 width = col_iter->second.max_length;
532 if (width < key.length())
538 const std::map<std::string,
539 std::vector<std::string>>::const_iterator
542 colname = super_iter->second.back();
547 for (
unsigned int i = 0; i < n_cols; ++i)
549 if (sel_columns[i] == colname)
551 column_widths[i] += key.length() - width;
556 width = key.length();
560 const unsigned int front_padding = (width - key.length()) / 2,
562 (width - key.length()) - front_padding;
563 for (
unsigned int i = 0; i < front_padding; ++i)
566 for (
unsigned int i = 0; i < rear_padding; ++i)
582 for (
unsigned int i = 0; i < nrows; ++i)
584 for (
unsigned int j = 0; j < n_cols; ++j)
586 const Column &column = *(cols[j]);
587 out << std::setw(column_widths[j]);
588 out << column.
entries[i].get_cached_string();
606 out <<
"\\documentclass[10pt]{report}" <<
'\n'
607 <<
"\\usepackage{float}" <<
'\n'
610 <<
"\\begin{document}" <<
'\n';
612 out <<
"\\begin{table}[H]" <<
'\n'
613 <<
"\\begin{center}" <<
'\n'
614 <<
"\\begin{tabular}{|";
619 unsigned int max_rows = 0;
620 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
623 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
626 column.second.pad_column_below(max_rows);
629 std::vector<std::string> sel_columns;
636 const std::map<std::string, std::vector<std::string>>::const_iterator
641 const unsigned int n_subcolumns = super_iter->second.size();
642 for (
unsigned int k = 0; k < n_subcolumns; ++k)
645 const std::map<std::string, Column>::const_iterator col_iter =
646 columns.find(super_iter->second[k]);
649 out << col_iter->second.tex_format <<
"|";
655 const std::map<std::string, Column>::const_iterator col_iter =
658 out << col_iter->second.tex_format <<
"|";
661 out <<
"} \\hline" <<
'\n';
668 const std::map<std::string, std::vector<std::string>>::const_iterator
673 const unsigned int n_subcolumns = super_iter->second.size();
675 std::map<std::string, std::string>::const_iterator
678 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{"
679 << tex_super_cap_iter->second <<
"}";
684 const std::map<std::string, Column>::const_iterator col_iter =
687 out << col_iter->second.tex_caption;
692 out <<
"\\\\ \\hline" <<
'\n';
695 const unsigned int nrows =
n_rows();
696 for (
unsigned int i = 0; i < nrows; ++i)
698 const unsigned int n_cols = sel_columns.size();
700 for (
unsigned int j = 0; j < n_cols; ++j)
702 std::string key = sel_columns[j];
704 const std::map<std::string, Column>::const_iterator col_iter =
708 const Column &column = col_iter->second;
710 out << std::setprecision(column.
precision);
712 if (col_iter->second.scientific)
713 out.setf(std::ios::scientific, std::ios::floatfield);
715 out.setf(std::ios::fixed, std::ios::floatfield);
717 out << column.
entries[i].value;
722 out <<
"\\\\ \\hline" <<
'\n';
725 out <<
"\\end{tabular}" <<
'\n' <<
"\\end{center}" <<
'\n';
730 out <<
"\\end{table}" <<
'\n';
732 out <<
"\\end{document}" <<
'\n';
760 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
761 unsigned int n = col_iter->second.entries.size();
764 std::string first_name = col_iter->first;
765 for (++col_iter; col_iter !=
columns.end(); ++col_iter)
766 Assert(col_iter->second.entries.size() == n,
768 col_iter->first, col_iter->second.entries.size(), first_name, n));
782 const std::map<std::string, std::vector<std::string>>::const_iterator
788 const unsigned int n_subcolumns = super_iter->second.size();
789 for (
unsigned int k = 0; k < n_subcolumns; ++k)
791 const std::string subkey = super_iter->second[k];
793 sel_columns.push_back(subkey);
800 sel_columns.push_back(key);
812 for (
const auto &column :
columns)
813 n =
std::max(n, column.second.entries.size());
818 if (column.second.entries.size() == n)
819 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)
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)
void set_tex_table_label(const std::string &table_label)
void set_precision(const std::string &key, const unsigned int precision)
#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)
void pad_column_below(const unsigned int length)
unsigned int n_rows() const
void get_selected_columns(std::vector< std::string > &sel_columns) const
#define Assert(cond, exc)
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
static ::ExceptionBase & ExcUndefinedTexFormat(std::string arg1)
std::string tex_table_caption
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcColumnOrSuperColumnNotExistent(std::string arg1)
std::vector< std::string > column_order
std::vector< internal::TableEntry > entries
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::map< std::string, Column > columns
types::global_dof_index size_type
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
void operator()(T &operand) const
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