diff --git a/gtsam/base/DerivedValue.h b/gtsam/base/DerivedValue.h index f59303675..92f294848 100644 --- a/gtsam/base/DerivedValue.h +++ b/gtsam/base/DerivedValue.h @@ -18,7 +18,16 @@ private: struct PoolTag { }; protected: - DerivedValue() {} + DerivedValue() { + // Register the base/derived class relationship for boost::serialization + // See: http://www.boost.org/doc/libs/1_45_0/libs/serialization/doc/serialization.html#runtimecasting + static bool first = true; + if (first) { + boost::serialization::void_cast_register( + static_cast(NULL), static_cast(NULL) ); + first = false; + } + } public: diff --git a/gtsam/base/Value.h b/gtsam/base/Value.h index 8d0b2dd05..99b5248d6 100644 --- a/gtsam/base/Value.h +++ b/gtsam/base/Value.h @@ -19,7 +19,7 @@ #pragma once #include - +#include #include namespace gtsam { @@ -142,6 +142,16 @@ namespace gtsam { /** Virutal destructor */ virtual ~Value() {} + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int version) { + std::cout << "value serialization" << std::endl; + } + }; } /* namespace gtsam */ + +BOOST_SERIALIZATION_ASSUME_ABSTRACT(gtsam::Value) diff --git a/gtsam/nonlinear/Values.h b/gtsam/nonlinear/Values.h index 9f154609d..a0dc33a74 100644 --- a/gtsam/nonlinear/Values.h +++ b/gtsam/nonlinear/Values.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -244,6 +245,14 @@ namespace gtsam { */ Ordering::shared_ptr orderingArbitrary(Index firstVar = 0) const; + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int version) { + ar & BOOST_SERIALIZATION_NVP(values_); + } + }; /* ************************************************************************* */ diff --git a/tests/testSerialization.cpp b/tests/testSerialization.cpp index 2bd37ebbb..ab58aeb99 100644 --- a/tests/testSerialization.cpp +++ b/tests/testSerialization.cpp @@ -37,6 +37,7 @@ #include #include +#include // whether to print the serialized text to stdout const bool verbose = false; @@ -439,6 +440,10 @@ TEST (Serialization, gaussianISAM) { BOOST_CLASS_EXPORT_GUID(simulated2D::Prior, "gtsam::simulated2D::Prior" ); BOOST_CLASS_EXPORT_GUID(simulated2D::Odometry, "gtsam::simulated2D::Odometry" ); BOOST_CLASS_EXPORT_GUID(simulated2D::Measurement, "gtsam::simulated2D::Measurement"); +BOOST_CLASS_EXPORT(gtsam::Point2) +BOOST_CLASS_EXPORT(gtsam::Point3) +BOOST_CLASS_EXPORT(gtsam::Pose2) +BOOST_CLASS_EXPORT(gtsam::Pose3) /* ************************************************************************* */ TEST (Serialization, smallExample) { using namespace example;