#endif
#include <boost/variant.hpp>
+#include <boost/serialization/map.hpp>
+#include <boost/serialization/string.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/serialization/split_member.hpp>
DEAL_II_NAMESPACE_OPEN
/**
* A <tt>TableEntry</tt> stores the value of a table entry.
* It can either be of type int, unsigned int, double or std::string.
- * In essence, this structure is the same as
+ * In essence, this structure is the same as
* <code>boost::variant<int,unsigned int,double,std::string></code>
* but we wrap this object in a structure for which we can write
- * a function that can serialize it. This is also why the function
+ * a function that can serialize it. This is also why the function
* is not in fact of type boost::any.
*/
struct TableEntry
* Abbreviation for the data type stored by this object.
*/
typedef boost::variant<int,unsigned int,double,std::string> value_type;
-
+
+ /**
+ * Stored value.
+ */
+ value_type value;
+
/**
* Return the value stored by this object. The template type
* T must be one of <code>int,unsigned int,double,std::string</code>
*/
template <typename T>
T get () const;
-
+
/**
* Return the numeric value of this object if data has been stored in
* it either as an integer, an unsigned integer, or a double.
* @return double
**/
double get_numeric_value () const;
-
+
/**
- * Stored value.
+ * Write the data of this object to a
+ * stream for the purpose of
+ * serialization.
*/
- value_type value;
+ template <class Archive>
+ void save (Archive & ar, const unsigned int version) const;
+
+ /**
+ * Read the data of this object from a
+ * stream for the purpose of
+ * serialization.
+ */
+ template <class Archive>
+ void load (Archive & ar, const unsigned int version);
+
+ BOOST_SERIALIZATION_SPLIT_MEMBER()
};
}
*/
void write_tex (std::ostream &file, const bool with_header=true) const;
+ /**
+ * Read or write the data of this
+ * object to or from a stream for
+ * the purpose of serialization.
+ */
+ template <class Archive>
+ void serialize(Archive & ar, const unsigned int version);
+
/** @addtogroup Exceptions
* @{ */
*/
Column (const std::string &tex_caption);
+ /**
+ * Read or write the data of this
+ * object to or from a stream for
+ * the purpose of serialization.
+ */
+ template <class Archive>
+ void serialize(Archive & ar, const unsigned int version);
/**
* List of entries within
throw;
}
}
-
-
+
+
inline
double TableEntry::get_numeric_value () const
{
catch (...)
{}
-
+
// ... then with unsigned int...
try
{
}
catch (...)
{}
-
+
// ...and finally with double precision:
try
{
Assert (false, ExcMessage ("The number stored by this element of the "
"table is not a number."))
}
-
+
return 0;
- }
+ }
+
+
+
+ template <class Archive>
+ void TableEntry::save (Archive & ar,
+ const unsigned int) const
+ {
+ // write first an identifier for the kind
+ // of data stored and then the actual
+ // data, in its correct data type
+ if (const int *p = boost::get<int>(&value))
+ {
+ char c = 'i';
+ ar & c & *p;
+ }
+ else if (const unsigned int *p = boost::get<unsigned int>(&value))
+ {
+ char c = 'u';
+ ar & c & *p;
+ }
+ else if (const double *p = boost::get<double>(&value))
+ {
+ char c = 'd';
+ ar & c & *p;
+ }
+ else if (const std::string *p = boost::get<std::string>(&value))
+ {
+ char c = 's';
+ ar & c & *p;
+ }
+ else
+ Assert (false, ExcInternalError());
+ }
+
+
+
+ template <class Archive>
+ void TableEntry::load (Archive & ar,
+ const unsigned int)
+ {
+ // following what we do in the save()
+ // function, first read in the data type
+ // as a one-character id, and then read
+ // the data
+ char c;
+ ar & c;
+
+ switch (c)
+ {
+ case 'i':
+ {
+ int val;
+ ar & val;
+ value = val;
+ break;
+ }
+
+ case 'u':
+ {
+ unsigned int val;
+ ar & val;
+ value = val;
+ break;
+ }
+
+ case 'd':
+ {
+ double val;
+ ar & val;
+ value = val;
+ break;
+ }
+
+ case 's':
+ {
+ std::string val;
+ ar & val;
+ value = val;
+ break;
+ }
+
+ default:
+ Assert (false, ExcInternalError());
+ }
+ }
}
+
+template <class Archive>
+void
+TableHandler::Column::serialize(Archive & ar,
+ const unsigned int)
+{
+ ar & entries & tex_caption
+ & tex_format & precision
+ & scientific & flag;
+}
+
+
+
+template <class Archive>
+void
+TableHandler::serialize(Archive & ar,
+ const unsigned int)
+{
+ ar & column_order & columns
+ & supercolumns & tex_supercaptions
+ & tex_table_caption
+ & tex_table_label;
+}
+
+
DEAL_II_NAMESPACE_CLOSE
#endif
--- /dev/null
+//---------------------------- table_1.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2010, 2011 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- table_1.cc ---------------------------
+
+// check serialization for TableHandler
+
+#include "serialization.h"
+#include <deal.II/base/table_handler.h>
+#include <boost/serialization/vector.hpp>
+
+namespace dealii
+{
+ bool compare (const TableHandler &t1,
+ const TableHandler &t2)
+ {
+ std::ostringstream o1, o2;
+ t1.write_tex (o1);
+ t1.write_text (o1);
+ t2.write_tex (o2);
+ t2.write_text (o2);
+
+ return (o1.str() == o2.str());
+ }
+}
+
+
+void test ()
+{
+ TableHandler t1, t2;
+ std::string keys[4] = { "key1", "key2", "key3", "key4" };
+
+
+ for (unsigned int i=0; i<10; ++i)
+ {
+ t1.add_value(keys[(0+i)%4], i);
+ t1.add_value(keys[(1+i)%4], sqrt(i));
+ t1.add_value(keys[(2+i)%4], 'a'+i);
+ t1.add_value(keys[(3+i)%4], std::string("abc-")+"0123456789"[i]);
+ }
+ t1.set_tex_table_caption("This is a caption text with \\LaTeX{} symbols");
+
+ verify (t1, t2);
+}
+
+
+int main ()
+{
+ std::ofstream logfile("table_handler/output");
+ deallog << std::setprecision(3);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+
+ deallog << "OK" << std::endl;
+}