16 #include <deal.II/base/table_handler.h> 18 #include <boost/io/ios_state.hpp> 25 DEAL_II_NAMESPACE_OPEN
44 return boost::get<int>(
value);
53 return boost::get<unsigned int>(
value);
61 return boost::get<unsigned long long int>(
value);
69 return boost::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);
111 struct GetDefaultValue :
public boost::static_visitor<>
113 template <
typename T>
115 operator()(T &operand)
const 126 boost::apply_visitor(Local::GetDefaultValue(), new_entry.
value);
137 : tex_caption(tex_caption)
166 while (entries.size() < size)
168 entries.push_back(entries.back().get_default_constructed_copy());
183 for (
const auto &entry : entries)
185 entry.cache_string(this->scientific, this->precision);
188 static_cast<unsigned int>(entry.get_cached_string().length()));
207 ExcMessage(
"You are trying to declare a column with key <" + key +
208 "> but such a column already exists."));
220 unsigned int max_col_length = 0;
221 for (
const auto &column :
columns)
223 std::max(max_col_length,
224 static_cast<unsigned int>(column.second.entries.size()));
229 while (column.second.entries.size() < max_col_length)
231 column.second.entries.emplace_back(
"");
233 entry.
cache_string(column.second.scientific, column.second.precision);
234 column.second.max_length =
235 std::max(column.second.max_length,
236 static_cast<unsigned int>(
252 const std::string &superkey)
258 std::pair<std::string, std::vector<std::string>> new_column(
259 superkey, std::vector<std::string>());
273 const auto order_iter =
284 std::pair<std::string, std::string> new_tex_supercaption(superkey,
297 for (
const auto &new_column : new_order)
310 const std::string &tex_caption)
313 columns[key].tex_caption = tex_caption;
336 const std::string &tex_supercaption)
347 const std::string &tex_format)
350 Assert(tex_format ==
"l" || tex_format ==
"c" || tex_format ==
"r",
352 columns[key].tex_format = tex_format;
359 const unsigned int precision)
362 if (
columns[key].precision != precision)
364 columns[key].precision = precision;
365 columns[key].invalidate_cache();
374 if (
columns[key].scientific != scientific)
376 columns[key].scientific = scientific;
377 columns[key].invalidate_cache();
386 boost::io::ios_flags_saver restore_flags(out);
391 unsigned int max_rows = 0;
392 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
395 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
398 column.second.pad_column_below(max_rows);
401 std::vector<std::string> sel_columns;
404 const unsigned int nrows =
n_rows();
405 const unsigned int n_cols = sel_columns.size();
408 std::vector<const Column *> cols;
409 std::vector<unsigned int> column_widths(n_cols, 0);
410 for (
unsigned int j = 0; j < n_cols; ++j)
412 std::string key = sel_columns[j];
413 const std::map<std::string, Column>::const_iterator col_iter =
416 cols.push_back(&(col_iter->second));
418 column_widths[j] = col_iter->second.max_length;
426 out <<
"| " << std::left;
427 for (
unsigned int j = 0; j < n_cols; ++j)
429 const std::string &key = sel_columns[j];
431 std::max(column_widths[j],
432 static_cast<unsigned int>(key.length()));
433 out << std::setw(column_widths[j]);
439 for (
unsigned int i = 0; i < nrows; ++i)
442 for (
unsigned int j = 0; j < n_cols; ++j)
444 const Column &column = *(cols[j]);
446 out << std::setw(column_widths[j]);
447 out << column.
entries[i].get_cached_string();
460 for (
unsigned int j = 0; j < n_cols; ++j)
462 const std::string &key = sel_columns[j];
463 out <<
"# " << j + 1 <<
": " << key <<
'\n';
467 for (
unsigned int i = 0; i < nrows; ++i)
469 for (
unsigned int j = 0; j < n_cols; ++j)
471 const Column &column = *(cols[j]);
473 out << column.
entries[i].get_cached_string();
488 for (
unsigned int j = 0; j < n_cols; ++j)
490 std::string key = sel_columns[j];
491 out <<
"# " << j + 1 <<
": " << key <<
'\n';
502 unsigned int width = 0;
505 const std::map<std::string,
506 std::vector<std::string>>::const_iterator
510 const unsigned int n_subcolumns = super_iter->second.size();
511 for (
unsigned int k = 0; k < n_subcolumns; ++k)
513 const std::map<std::string, Column>::const_iterator
514 col_iter =
columns.find(super_iter->second[k]);
517 width += col_iter->second.max_length;
519 width += n_subcolumns - 1;
523 const std::map<std::string, Column>::const_iterator
526 width = col_iter->second.max_length;
531 if (width < key.length())
537 const std::map<std::string,
538 std::vector<std::string>>::const_iterator
541 colname = super_iter->second.back();
546 for (
unsigned int i = 0; i < n_cols; ++i)
548 if (sel_columns[i] == colname)
550 column_widths[i] += key.length() - width;
555 width = key.length();
559 const unsigned int front_padding = (width - key.length()) / 2,
561 (width - key.length()) - front_padding;
562 for (
unsigned int i = 0; i < front_padding; ++i)
565 for (
unsigned int i = 0; i < rear_padding; ++i)
581 for (
unsigned int i = 0; i < nrows; ++i)
583 for (
unsigned int j = 0; j < n_cols; ++j)
585 const Column &column = *(cols[j]);
586 out << std::setw(column_widths[j]);
587 out << column.
entries[i].get_cached_string();
605 out <<
"\\documentclass[10pt]{report}" << std::endl
606 <<
"\\usepackage{float}" << std::endl
609 <<
"\\begin{document}" << std::endl;
611 out <<
"\\begin{table}[H]" << std::endl
612 <<
"\\begin{center}" << std::endl
613 <<
"\\begin{tabular}{|";
618 unsigned int max_rows = 0;
619 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
622 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
625 column.second.pad_column_below(max_rows);
628 std::vector<std::string> sel_columns;
635 const std::map<std::string, std::vector<std::string>>::const_iterator
640 const unsigned int n_subcolumns = super_iter->second.size();
641 for (
unsigned int k = 0; k < n_subcolumns; ++k)
644 const std::map<std::string, Column>::const_iterator col_iter =
645 columns.find(super_iter->second[k]);
648 out << col_iter->second.tex_format <<
"|";
654 const std::map<std::string, Column>::const_iterator col_iter =
657 out << col_iter->second.tex_format <<
"|";
660 out <<
"} \\hline" << std::endl;
667 const std::map<std::string, std::vector<std::string>>::const_iterator
672 const unsigned int n_subcolumns = super_iter->second.size();
674 std::map<std::string, std::string>::const_iterator
677 <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{" 678 << tex_super_cap_iter->second <<
"}";
683 const std::map<std::string, Column>::const_iterator col_iter =
686 out << col_iter->second.tex_caption;
691 out <<
"\\\\ \\hline" << std::endl;
694 const unsigned int nrows =
n_rows();
695 for (
unsigned int i = 0; i < nrows; ++i)
697 const unsigned int n_cols = sel_columns.size();
699 for (
unsigned int j = 0; j < n_cols; ++j)
701 std::string key = sel_columns[j];
703 const std::map<std::string, Column>::const_iterator col_iter =
707 const Column &column = col_iter->second;
709 out << std::setprecision(column.precision);
711 if (col_iter->second.scientific)
712 out.setf(std::ios::scientific, std::ios::floatfield);
714 out.setf(std::ios::fixed, std::ios::floatfield);
716 out << column.entries[i].value;
721 out <<
"\\\\ \\hline" << std::endl;
724 out <<
"\\end{tabular}" << std::endl <<
"\\end{center}" << std::endl;
729 out <<
"\\end{table}" << std::endl;
731 out <<
"\\end{document}" << std::endl;
754 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
755 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->first, col_iter->second.entries.size(), first_name, n));
776 const std::map<std::string, std::vector<std::string>>::const_iterator
782 const unsigned int n_subcolumns = super_iter->second.size();
783 for (
unsigned int k = 0; k < n_subcolumns; ++k)
785 const std::string subkey = super_iter->second[k];
787 sel_columns.push_back(subkey);
794 sel_columns.push_back(key);
805 std::vector<internal::TableEntry>::size_type n = 0;
806 for (
const auto &column :
columns)
807 n = std::max(n, column.second.entries.size());
812 if (column.second.entries.size() == n)
813 column.second.entries.pop_back();
817 DEAL_II_NAMESPACE_CLOSE
std::map< std::string, std::string > tex_supercaptions
void set_precision(const std::string &key, const unsigned int precision)
void declare_column(const std::string &key)
static ::ExceptionBase & ExcIO()
void set_tex_supercaption(const std::string &superkey, const std::string &tex_supercaption)
std::map< std::string, Column > columns
static ::ExceptionBase & ExcColumnOrSuperColumnNotExistent(std::string arg1)
const std::string & get_cached_string() const
void set_tex_caption(const std::string &key, const std::string &tex_caption)
#define AssertThrow(cond, exc)
void cache_string(bool scientific, unsigned int precision) const
void add_column_to_supercolumn(const std::string &key, const std::string &superkey)
void set_tex_format(const std::string &key, const std::string &format="c")
void get_selected_columns(std::vector< std::string > &sel_columns) const
static ::ExceptionBase & ExcSuperColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcWrongNumberOfDataEntries(std::string arg1, int arg2, std::string arg3, int arg4)
std::vector< std::string > column_order
static ::ExceptionBase & ExcMessage(std::string arg1)
std::string tex_table_caption
double get_numeric_value() const
TableEntry get_default_constructed_copy() const
void write_text(std::ostream &out, const TextOutputFormat format=table_with_headers) const
#define Assert(cond, exc)
void set_tex_table_label(const std::string &table_label)
void write_tex(std::ostream &file, const bool with_header=true) const
static ::ExceptionBase & ExcUndefinedTexFormat(std::string arg1)
void set_column_order(const std::vector< std::string > &new_order)
void set_scientific(const std::string &key, const bool scientific)
void pad_column_below(const unsigned int length)
static ::ExceptionBase & ExcColumnNotExistent(std::string arg1)
std::vector< internal::TableEntry > entries
unsigned int n_rows() const
void set_tex_table_caption(const std::string &table_caption)
std::map< std::string, std::vector< std::string > > supercolumns
std::string tex_table_label
static ::ExceptionBase & ExcInternalError()
void set_auto_fill_mode(const bool state)