From 3793ad3e0ee8c472c09e6a627138a5c2505b3d8b Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Fri, 3 Feb 2012 06:07:31 +0000 Subject: [PATCH 1/2] remove redundant typedef Values in ISAM2.h --- gtsam/nonlinear/ISAM2.h | 1 - 1 file changed, 1 deletion(-) diff --git a/gtsam/nonlinear/ISAM2.h b/gtsam/nonlinear/ISAM2.h index 62a86cf64..0f8776ec2 100644 --- a/gtsam/nonlinear/ISAM2.h +++ b/gtsam/nonlinear/ISAM2.h @@ -314,7 +314,6 @@ public: typedef BayesTree > Base; ///< The BayesTree base class typedef ISAM2 This; ///< This class - typedef Values Values; typedef GRAPH Graph; /** Create an empty ISAM2 instance */ From 191c3e610a885f178b9197269a7d4f50e94a4f7f Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Fri, 3 Feb 2012 06:15:59 +0000 Subject: [PATCH 2/2] enable serialization for Values. --- gtsam/base/DerivedValue.h | 11 ++++++++++- gtsam/base/Value.h | 12 +++++++++++- gtsam/nonlinear/Values.h | 9 +++++++++ tests/testSerialization.cpp | 5 +++++ 4 files changed, 35 insertions(+), 2 deletions(-) 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 ae06daa74..2a721d591 100644 --- a/gtsam/nonlinear/Values.h +++ b/gtsam/nonlinear/Values.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -241,6 +242,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 f2e740180..68f817f8b 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; @@ -441,6 +442,10 @@ TEST (Serialization, gaussianISAM) { BOOST_CLASS_EXPORT_GUID(gtsam::simulated2D::Prior, "gtsam::simulated2D::Prior" ); BOOST_CLASS_EXPORT_GUID(gtsam::simulated2D::Odometry, "gtsam::simulated2D::Odometry" ); BOOST_CLASS_EXPORT_GUID(gtsam::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;