16 #include <deal.II/base/table_handler.h> 17 #include <deal.II/base/table.h> 24 DEAL_II_NAMESPACE_OPEN
46 return boost::get<int>(
value);
55 return boost::get<unsigned int>(
value);
63 return boost::get<double>(
value);
68 "table is not a number."))
76 std::ostringstream ss;
78 ss << std::setprecision(precision);
81 ss.setf(std::ios::scientific, std::ios::floatfield);
83 ss.setf(std::ios::fixed, std::ios::floatfield);
102 struct GetDefaultValue :
public boost::static_visitor<>
104 template <
typename T>
105 void operator()( T &operand )
const 115 boost::apply_visitor(Local::GetDefaultValue(), new_entry.
value);
127 tex_caption(tex_caption),
159 entries.push_back (
entries.back().get_default_constructed_copy());
172 for (std::vector<::internal::TableEntry>::iterator it=
entries.begin(); it!=
entries.end(); ++it)
198 const std::string &superkey)
204 std::pair<std::string, std::vector<std::string> >
205 new_column(superkey, std::vector<std::string>());
220 for (std::vector<std::string>::iterator order_iter=
column_order.begin();
222 if (*order_iter==key)
234 std::pair<std::string, std::string> new_tex_supercaption(superkey, superkey);
238 Assert(
false, ExcInternalError());
245 for (
unsigned int j=0; j<new_order.size(); ++j)
247 ExcColumnOrSuperColumnNotExistent(new_order[j]));
254 const std::string &tex_caption)
257 columns[key].tex_caption=tex_caption;
277 const std::string &tex_supercaption)
287 const std::string &tex_format)
290 Assert(tex_format==
"l" || tex_format==
"c" || tex_format==
"r",
291 ExcUndefinedTexFormat(tex_format));
292 columns[key].tex_format=tex_format;
298 const unsigned int precision)
301 if (
columns[key].precision!=precision)
303 columns[key].precision = precision;
304 columns[key].invalidate_cache();
310 const bool scientific)
313 if (
columns[key].scientific!=scientific)
315 columns[key].scientific = scientific;
316 columns[key].invalidate_cache();
329 unsigned int max_rows = 0;
330 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
332 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
334 for (std::map<std::string, Column>::iterator p =
columns.begin();
336 p->second.pad_column_below (max_rows);
339 std::vector<std::string> sel_columns;
342 const unsigned int nrows =
n_rows();
343 const unsigned int n_cols = sel_columns.size();
346 std::vector<const Column *> cols;
347 std::vector<unsigned int> column_widths (n_cols, 0);
348 for (
unsigned int j=0; j<n_cols; ++j)
350 std::string key=sel_columns[j];
351 const std::map<std::string, Column>::const_iterator
354 cols.push_back(&(col_iter->second));
356 column_widths[j] = col_iter->second.max_length;
364 out <<
"| " << std::left;
365 for (
unsigned int j=0; j<n_cols; ++j)
367 const std::string &key = sel_columns[j];
368 column_widths[j] = std::max(column_widths[j],
369 (
unsigned int)key.length());
370 out << std::setw(column_widths[j]);
376 for (
unsigned int i=0; i<nrows; ++i)
379 for (
unsigned int j=0; j<n_cols; ++j)
381 const Column &column=*(cols[j]);
383 out << std::setw(column_widths[j]);
384 out << column.
entries[i].get_cached_string();
394 case simple_table_with_separate_column_description:
397 for (
unsigned int j=0; j<n_cols; ++j)
399 const std::string &key = sel_columns[j];
400 out <<
"# " << j+1 <<
": " << key <<
'\n';
404 for (
unsigned int i=0; i<nrows; ++i)
406 for (
unsigned int j=0; j<n_cols; ++j)
408 const Column &column=*(cols[j]);
410 out << column.
entries[i].get_cached_string();
420 case table_with_separate_column_description:
425 for (
unsigned int j=0; j<n_cols; ++j)
427 std::string key=sel_columns[j];
428 out <<
"# " << j+1 <<
": " << key <<
'\n';
433 case table_with_headers:
440 unsigned int width=0;
443 const std::map<std::string, std::vector<std::string> >::const_iterator
447 const unsigned int n_subcolumns=super_iter->second.size();
448 for (
unsigned int k=0; k<n_subcolumns; ++k)
450 const std::map<std::string, Column>::const_iterator
451 col_iter=
columns.find(super_iter->second[k]);
454 width += col_iter->second.max_length;
456 width += n_subcolumns - 1;
460 const std::map<std::string, Column>::const_iterator
463 width = col_iter->second.max_length;
468 if (width<key.length())
474 const std::map<std::string, std::vector<std::string> >::const_iterator
477 colname = super_iter->second.back();
482 for (
unsigned int i=0; i<n_cols; ++i)
484 if (sel_columns[i]==colname)
486 column_widths[i] += key.length() - width;
495 const unsigned int front_padding = (width-key.length())/2,
496 rear_padding = (width-key.length()) -
498 for (
unsigned int i=0; i<front_padding; ++i)
501 for (
unsigned int i=0; i<rear_padding; ++i)
511 Assert (
false, ExcInternalError());
517 for (
unsigned int i=0; i<nrows; ++i)
519 for (
unsigned int j=0; j<n_cols; ++j)
521 const Column &column=*(cols[j]);
522 out << std::setw(column_widths[j]);
523 out << column.
entries[i].get_cached_string();
540 out <<
"\\documentclass[10pt]{report}" << std::endl
541 <<
"\\usepackage{float}" << std::endl << std::endl << std::endl
542 <<
"\\begin{document}" << std::endl;
544 out <<
"\\begin{table}[H]" << std::endl
545 <<
"\\begin{center}" << std::endl
546 <<
"\\begin{tabular}{|";
551 unsigned int max_rows = 0;
552 for (std::map<std::string, Column>::const_iterator p =
columns.begin();
554 max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
556 for (std::map<std::string, Column>::iterator p =
columns.begin();
558 p->second.pad_column_below (max_rows);
561 std::vector<std::string> sel_columns;
569 const std::map<std::string, std::vector<std::string> >::const_iterator
574 const unsigned int n_subcolumns=super_iter->second.size();
575 for (
unsigned int k=0; k<n_subcolumns; ++k)
578 const std::map<std::string, Column>::const_iterator
579 col_iter=
columns.find(super_iter->second[k]);
582 out << col_iter->second.tex_format <<
"|";
588 const std::map<std::string, Column>::const_iterator
591 out << col_iter->second.tex_format <<
"|";
594 out <<
"} \\hline" << std::endl;
601 const std::map<std::string, std::vector<std::string> >::const_iterator
606 const unsigned int n_subcolumns=super_iter->second.size();
608 std::map<std::string,std::string>::const_iterator
610 out << std::endl <<
"\\multicolumn{" << n_subcolumns <<
"}{|c|}{" 611 << tex_super_cap_iter->second <<
"}";
616 const std::map<std::string, Column>::const_iterator
619 out << col_iter->second.tex_caption;
624 out <<
"\\\\ \\hline" << std::endl;
627 const unsigned int nrows=
n_rows();
628 for (
unsigned int i=0; i<nrows; ++i)
630 const unsigned int n_cols=sel_columns.size();
632 for (
unsigned int j=0; j<n_cols; ++j)
634 std::string key=sel_columns[j];
636 const std::map<std::string, Column>::const_iterator
640 const Column &column=col_iter->second;
642 out << std::setprecision(column.precision);
644 if (col_iter->second.scientific)
645 out.setf(std::ios::scientific, std::ios::floatfield);
647 out.setf(std::ios::fixed, std::ios::floatfield);
649 out << column.entries[i].value;
654 out <<
"\\\\ \\hline" << std::endl;
657 out <<
"\\end{tabular}" << std::endl
658 <<
"\\end{center}" << std::endl;
663 out <<
"\\end{table}" << std::endl;
665 out <<
"\\end{document}" << std::endl;
688 std::map<std::string, Column>::const_iterator col_iter =
columns.begin();
689 unsigned int n = col_iter->second.entries.size();
690 std::string first_name=col_iter->first;
692 for (++col_iter; col_iter!=
columns.end(); ++col_iter)
693 Assert(col_iter->second.entries.size()==n,
694 ExcWrongNumberOfDataEntries(col_iter->first,
695 col_iter->second.entries.size(),
709 const std::map<std::string, std::vector<std::string> >::const_iterator
715 const unsigned int n_subcolumns=super_iter->second.size();
716 for (
unsigned int k=0; k<n_subcolumns; ++k)
718 const std::string subkey=super_iter->second[k];
720 sel_columns.push_back(subkey);
727 sel_columns.push_back(key);
737 std::vector<internal::TableEntry>::size_type n = 0;
738 for (std::map< std::string, Column >::iterator p =
columns.begin(); p !=
columns.end(); ++p)
739 n = std::max(n, p->second.entries.size());
743 for (std::map< std::string, Column >::iterator p =
columns.begin(); p !=
columns.end(); ++p)
744 if (p->second.entries.size() == n)
745 p->second.entries.pop_back();
749 DEAL_II_NAMESPACE_CLOSE
std::map< std::string, std::string > tex_supercaptions
void set_precision(const std::string &key, const unsigned int precision)
void set_tex_supercaption(const std::string &superkey, const std::string &tex_supercaption)
::ExceptionBase & ExcMessage(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
std::vector< std::string > column_order
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
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)
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
void set_auto_fill_mode(const bool state)