16 #ifndef dealii__table_handler_h 17 #define dealii__table_handler_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 30 #include <boost/variant.hpp> 31 #include <boost/serialization/map.hpp> 32 #include <boost/serialization/string.hpp> 33 #include <boost/serialization/vector.hpp> 34 #include <boost/serialization/split_member.hpp> 37 DEAL_II_NAMESPACE_OPEN
90 void cache_string(
bool scientific,
unsigned int precision)
const;
110 template <
class Archive>
111 void save (Archive &ar,
const unsigned int version)
const;
117 template <
class Archive>
118 void load (Archive &ar,
const unsigned int version);
120 BOOST_SERIALIZATION_SPLIT_MEMBER()
126 typedef boost::variant<int,unsigned int,unsigned long long int,double,std::string>
value_type;
138 friend class ::TableHandler;
326 table_with_separate_column_description,
327 simple_table_with_separate_column_description,
342 template <
typename T>
343 void add_value (
const std::string &key,
350 void set_auto_fill_mode (
const bool state);
364 void add_column_to_supercolumn (
const std::string &key,
365 const std::string &superkey);
383 void set_column_order (
const std::vector<std::string> &new_order);
390 void set_precision (
const std::string &key,
391 const unsigned int precision);
397 void set_scientific (
const std::string &key,
398 const bool scientific);
405 void set_tex_caption (
const std::string &key,
406 const std::string &tex_caption);
411 void set_tex_table_caption (
const std::string &table_caption);
416 void set_tex_table_label (
const std::string &table_label);
423 void set_tex_supercaption (
const std::string &superkey,
424 const std::string &tex_supercaption);
432 void set_tex_format (
const std::string &key,
433 const std::string &format=
"c");
446 void write_text (std::ostream &out,
455 void write_tex (std::ostream &file,
const bool with_header=
true)
const;
468 void clear_current_row ();
474 template <
class Archive>
475 void serialize(Archive &ar,
const unsigned int version);
487 <<
"Column <" << arg1 <<
"> does not exist.");
494 <<
"Supercolumn <" << arg1 <<
"> does not exist.");
501 <<
"Column or supercolumn <" << arg1 <<
"> does not exist.");
507 std::string,
int, std::string,
int,
508 <<
"Column <" << arg1 <<
"> has got " << arg2
509 <<
" rows, but Column <" << arg3 <<
"> has got " << arg4 <<
".");
516 <<
"<" << arg1 <<
"> is not a tex column format. Use " 517 <<
"'l', 'c', or 'r' to indicate left, centered, or " 518 <<
"right aligned text.");
536 Column (
const std::string &tex_caption);
542 void pad_column_below (
const unsigned int length);
548 template <
class Archive>
549 void save(Archive &ar,
const unsigned int version)
const;
550 template<
class Archive>
551 void load(Archive &ar,
const unsigned int version);
552 BOOST_SERIALIZATION_SPLIT_MEMBER()
559 void invalidate_cache();
619 void get_selected_columns (std::vector<std::string> &sel_columns)
const;
626 unsigned int n_rows()
const;
681 template <
typename T>
688 template <
typename T>
699 return boost::get<T>(
value);
703 Assert(
false,
ExcMessage (
"This TableEntry object does not store a datum of type T"));
710 template <
class Archive>
712 const unsigned int)
const 717 if (
const int *p = boost::get<int>(&
value))
722 else if (
const unsigned int *p = boost::get<unsigned int>(&
value))
727 else if (
const double *p = boost::get<double>(&
value))
732 else if (
const std::string *p = boost::get<std::string>(&
value))
737 else if (
const unsigned long long int *p = boost::get<unsigned long long int>(&
value))
743 Assert (
false, ExcInternalError());
748 template <
class Archive>
795 unsigned long long int val;
802 Assert (
false, ExcInternalError());
807 template <
typename T>
812 if (columns.find(key) == columns.end())
814 std::pair<std::string, Column> new_column(key,
Column(key));
815 columns.insert(new_column);
816 column_order.push_back(key);
819 if (auto_fill_mode ==
true)
824 for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p)
825 n = (n >= p->second.entries.size() ? n : p->second.entries.size());
827 while (columns[key].entries.size()+1 < n)
831 entry.
cache_string(columns[key].scientific, columns[key].precision);
832 columns[key].max_length = std::max(columns[key].max_length, static_cast<unsigned int>(entry.
get_cached_string().length()));
839 entry.
cache_string(columns[key].scientific, columns[key].precision);
840 columns[key].max_length = std::max(columns[key].max_length, static_cast<unsigned int>(entry.
get_cached_string().length()));
844 template <
class Archive>
848 ar &entries &tex_caption
849 & tex_format &precision
855 template<
class Archive>
857 TableHandler::Column::load(Archive &ar,
const unsigned int )
859 ar &entries &tex_caption
860 & tex_format &precision
868 template <
class Archive>
873 ar &column_order &columns
874 & supercolumns &tex_supercaptions
881 DEAL_II_NAMESPACE_CLOSE
std::map< std::string, std::string > tex_supercaptions
void save(Archive &ar, const unsigned int version) const
::ExceptionBase & ExcMessage(std::string arg1)
void add_value(const std::string &key, const T value)
const std::string & get_cached_string() const
void cache_string(bool scientific, unsigned int precision) const
void load(Archive &ar, const unsigned int version)
std::vector< std::string > column_order
std::string tex_table_caption
double get_numeric_value() const
TableEntry get_default_constructed_copy() const
#define DeclException1(Exception1, type1, outsequence)
#define Assert(cond, exc)
void save(Archive &ar, const unsigned int version) const
boost::variant< int, unsigned int, unsigned long long int, double, std::string > value_type
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
void serialize(Archive &ar, const unsigned int version)
std::vector< internal::TableEntry > entries
std::map< std::string, Column > columns
std::map< std::string, std::vector< std::string > > supercolumns
std::string tex_table_label