16 #include <deal.II/base/table_handler.h> 17 #include <deal.II/base/table.h> 19 #include <boost/io/ios_state.hpp> 26 DEAL_II_NAMESPACE_OPEN
48 return boost::get<int>(
value);
57 return boost::get<unsigned int>(
value);
65 return boost::get<double>(
value);
70 "table is not a number."))
78 std::ostringstream ss;
80 ss << std::setprecision(precision);
83 ss.setf(std::ios::scientific, std::ios::floatfield);
85 ss.setf(std::ios::fixed, std::ios::floatfield);
104 struct GetDefaultValue :
public boost::static_visitor<>
106 template <
typename T>
107 void operator()( T &operand )
const 117 boost::apply_visitor(Local::GetDefaultValue(), new_entry.
value);
129 tex_caption(tex_caption),
159 while (entries.size() < size)
161 entries.push_back (entries.back().get_default_constructed_copy());
164 max_length = std::max(max_length, static_cast<unsigned int>(entry.
get_cached_string().length()));
174 for (std::vector<::internal::TableEntry>::iterator it=entries.begin(); it!=entries.end(); ++it)
176 it->cache_string(this->scientific, this->precision);
177 max_length = std::max(max_length, static_cast<unsigned int>(it->get_cached_string().length()));
200 const std::string &superkey)
206 std::pair<std::string, std::vector<std::string> >
207 new_column(superkey, std::vector<std::string>());
222 for (std::vector<std::string>::iterator order_iter=
column_order.begin();
224 if (*order_iter==key)
236 std::pair<std::string, std::string> new_tex_supercaption(superkey, superkey);
247 for (
unsigned int j=0; j<new_order.size(); ++j)
256 const std::string &tex_caption)
259 columns[key].tex_caption=tex_caption;
279 const std::string &tex_supercaption)
289 const std::string &tex_format)
292 Assert(tex_format==
"l" || tex_format==
"c" || tex_format==
"r",
294 columns[key].tex_format=tex_format;
300 const unsigned int precision)
303 if (
columns[key].precision!=precision)
305 columns[key].precision = precision;
306 columns[key].invalidate_cache();
312 const bool scientific)
315 if (
columns[key].scientific!=scientific)
317 columns[key].scientific = scientific;
318 columns[key].invalidate_cache();
327 boost::io::ios_flags_saver restore_flags(out);
332 unsigned int max_rows = 0;
333 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
335 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
337 for (std::map<std::string, Column>::iterator p =
columns.begin();
339 p->second.pad_column_below (max_rows);
342 std::vector<std::string> sel_columns;
345 const unsigned int nrows =
n_rows();
346 const unsigned int n_cols = sel_columns.size();
349 std::vector<const Column *> cols;
350 std::vector<unsigned int> column_widths (n_cols, 0);
351 for (
unsigned int j=0; j<n_cols; ++j)
353 std::string key=sel_columns[j];
354 const std::map<std::string, Column>::const_iterator
357 cols.push_back(&(col_iter->second));
359 column_widths[j] = col_iter->second.max_length;
367 out <<
"| " << std::left;
368 for (
unsigned int j=0; j<n_cols; ++j)
370 const std::string &key = sel_columns[j];
371 column_widths[j] = std::max(column_widths[j],
372 (
unsigned int)key.length());
373 out << std::setw(column_widths[j]);
379 for (
unsigned int i=0; i<nrows; ++i)
382 for (
unsigned int j=0; j<n_cols; ++j)
384 const Column &column=*(cols[j]);
386 out << std::setw(column_widths[j]);
387 out << column.
entries[i].get_cached_string();
400 for (
unsigned int j=0; j<n_cols; ++j)
402 const std::string &key = sel_columns[j];
403 out <<
"# " << j+1 <<
": " << key <<
'\n';
407 for (
unsigned int i=0; i<nrows; ++i)
409 for (
unsigned int j=0; j<n_cols; ++j)
411 const Column &column=*(cols[j]);
413 out << column.
entries[i].get_cached_string();
428 for (
unsigned int j=0; j<n_cols; ++j)
430 std::string key=sel_columns[j];
431 out <<
"# " << j+1 <<
": " << key <<
'\n';
443 unsigned int width=0;
446 const std::map<std::string, std::vector<std::string> >::const_iterator
450 const unsigned int n_subcolumns=super_iter->second.size();
451 for (
unsigned int k=0; k<n_subcolumns; ++k)
453 const std::map<std::string, Column>::const_iterator
454 col_iter=
columns.find(super_iter->second[k]);
457 width += col_iter->second.max_length;
459 width += n_subcolumns - 1;
463 const std::map<std::string, Column>::const_iterator
466 width = col_iter->second.max_length;
471 if (width<key.length())
477 const std::map<std::string, std::vector<std::string> >::const_iterator
480 colname = super_iter->second.back();
485 for (
unsigned int i=0; i<n_cols; ++i)
487 if (sel_columns[i]==colname)
489 column_widths[i] += key.length() - width;
498 const unsigned int front_padding = (width-key.length())/2,
499 rear_padding = (width-key.length()) -
501 for (
unsigned int i=0; i<front_padding; ++i)
504 for (
unsigned int i=0; i<rear_padding; ++i)
520 for (
unsigned int i=0; i<nrows; ++i)
522 for (
unsigned int j=0; j<n_cols; ++j)
524 const Column &column=*(cols[j]);
525 out << std::setw(column_widths[j]);
526 out << column.
entries[i].get_cached_string();
543 out <<
"\\documentclass[10pt]{report}" << std::endl
544 <<
"\\usepackage{float}" << std::endl << std::endl << std::endl
545 <<
"\\begin{document}" << std::endl;
547 out <<
"\\begin{table}[H]" << std::endl
548 <<
"\\begin{center}" << std::endl
549 <<
"\\begin{tabular}{|";
554 unsigned int max_rows = 0;
555 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
557 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
559 for (std::map<std::string, Column>::iterator p =
columns.begin();
561 p->second.pad_column_below (max_rows);
564 std::vector<std::string> sel_columns;
572 const std::map<std::string, std::vector<std::string> >::const_iterator
577 const unsigned int n_subcolumns=super_iter->second.size();
578 for (
unsigned int k=0; k<n_subcolumns; ++k)
581 const std::map<std::string, Column>::const_iterator
582 col_iter=
columns.find(super_iter->second[k]);
585 out << col_iter->second.tex_format <<
"|";
591 const std::map<std::string, Column>::const_iterator
594 out << col_iter->second.tex_format <<
"|";
597 out <<
"} \\hline" << std::endl;
604 const std::map<std::string, std::vector<std::string> >::const_iterator
609 const unsigned int n_subcolumns=super_iter->second.size();
611 std::map<std::string,std::string>::const_iterator
613 out << std::endl <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{" 614 << tex_super_cap_iter->second <<
"}";
619 const std::map<std::string, Column>::const_iterator
622 out << col_iter->second.tex_caption;
627 out <<
"\\\\ \\hline" << std::endl;
630 const unsigned int nrows=
n_rows();
631 for (
unsigned int i=0; i<nrows; ++i)
633 const unsigned int n_cols=sel_columns.size();
635 for (
unsigned int j=0; j<n_cols; ++j)
637 std::string key=sel_columns[j];
639 const std::map<std::string, Column>::const_iterator
643 const Column &column=col_iter->second;
645 out << std::setprecision(column.precision);
647 if (col_iter->second.scientific)
648 out.setf(std::ios::scientific, std::ios::floatfield);
650 out.setf(std::ios::fixed, std::ios::floatfield);
652 out << column.entries[i].value;
657 out <<
"\\\\ \\hline" << std::endl;
660 out <<
"\\end{tabular}" << std::endl
661 <<
"\\end{center}" << std::endl;
666 out <<
"\\end{table}" << std::endl;
668 out <<
"\\end{document}" << std::endl;
691 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
692 unsigned int n = col_iter->second.entries.size();
693 std::string first_name=col_iter->first;
695 for (++col_iter; col_iter!=
columns.end(); ++col_iter)
696 Assert(col_iter->second.entries.size()==n,
698 col_iter->second.entries.size(),
712 const std::map<std::string, std::vector<std::string> >::const_iterator
718 const unsigned int n_subcolumns=super_iter->second.size();
719 for (
unsigned int k=0; k<n_subcolumns; ++k)
721 const std::string subkey=super_iter->second[k];
723 sel_columns.push_back(subkey);
730 sel_columns.push_back(key);
740 std::vector<internal::TableEntry>::size_type n = 0;
741 for (std::map< std::string, Column >::iterator p =
columns.begin(); p !=
columns.end(); ++p)
742 n = std::max(n, p->second.entries.size());
746 for (std::map< std::string, Column >::iterator p =
columns.begin(); p !=
columns.end(); ++p)
747 if (p->second.entries.size() == n)
748 p->second.entries.pop_back();
752 DEAL_II_NAMESPACE_CLOSE
std::map< std::string, std::string > tex_supercaptions
void set_precision(const std::string &key, const unsigned int precision)
static ::ExceptionBase & ExcIO()
void set_tex_supercaption(const std::string &superkey, const std::string &tex_supercaption)
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
std::map< std::string, Column > columns
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)