diff --git a/gtsam/base/FastList.h b/gtsam/base/FastList.h index b34d1fad9..02f8734f6 100644 --- a/gtsam/base/FastList.h +++ b/gtsam/base/FastList.h @@ -20,6 +20,8 @@ #include #include +#include +#include namespace gtsam { @@ -51,6 +53,14 @@ public: /** Copy constructor from the base map class */ FastList(const Base& x) : Base(x) {} +private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int version) { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + } + }; } diff --git a/gtsam/base/FastMap.h b/gtsam/base/FastMap.h index cc5a3b4d6..c9fe30646 100644 --- a/gtsam/base/FastMap.h +++ b/gtsam/base/FastMap.h @@ -20,7 +20,8 @@ #include #include -#include +#include +#include namespace gtsam { @@ -52,12 +53,12 @@ public: /** Copy constructor from the base map class */ FastMap(const Base& x) : Base(x) {} - private: +private: /** Serialization function */ friend class boost::serialization::access; template - void serialize(ARCHIVE & ar, const unsigned int version) { - ar & boost::serialization::base_object(*this); + void serialize(ARCHIVE & ar, const unsigned int version) { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); } }; diff --git a/gtsam/base/FastSet.h b/gtsam/base/FastSet.h index 7d9084e5f..05fb879a1 100644 --- a/gtsam/base/FastSet.h +++ b/gtsam/base/FastSet.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include BOOST_MPL_HAS_XXX_TRAIT_DEF(print) @@ -74,6 +76,14 @@ public: /** Check for equality within tolerance to implement Testable */ bool equals(const FastSet& other, double tol = 1e-9) const { return FastSetTestableHelper::equals(*this, other, tol); } + +private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int version) { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + } }; // This is the default Testable interface for *non*Testable elements, which diff --git a/gtsam/base/FastVector.h b/gtsam/base/FastVector.h index 57b5bb4cc..cb08871d9 100644 --- a/gtsam/base/FastVector.h +++ b/gtsam/base/FastVector.h @@ -20,6 +20,8 @@ #include #include +#include +#include namespace gtsam { @@ -56,6 +58,14 @@ public: /** Copy constructor from the base map class */ FastVector(const Base& x) : Base(x) {} +private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int version) { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + } + }; } diff --git a/gtsam/base/tests/testSerializationBase.cpp b/gtsam/base/tests/testSerializationBase.cpp index 211a1c319..e144b3576 100644 --- a/gtsam/base/tests/testSerializationBase.cpp +++ b/gtsam/base/tests/testSerializationBase.cpp @@ -18,6 +18,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -26,6 +30,53 @@ using namespace std; using namespace gtsam; using namespace gtsam::serializationTestHelpers; +Vector v1 = Vector_(2, 1.0, 2.0); +Vector v2 = Vector_(2, 3.0, 4.0); +Vector v3 = Vector_(2, 5.0, 6.0); + +/* ************************************************************************* */ +TEST (Serialization, FastList) { + FastList list; + list.push_back(v1); + list.push_back(v2); + list.push_back(v3); + + EXPECT(equality(list)); + EXPECT(equalityXML(list)); +} + +/* ************************************************************************* */ +TEST (Serialization, FastMap) { + FastMap map; + map.insert(make_pair(1, v1)); + map.insert(make_pair(2, v2)); + map.insert(make_pair(3, v3)); + + EXPECT(equality(map)); + EXPECT(equalityXML(map)); +} + +/* ************************************************************************* */ +TEST (Serialization, FastSet) { + FastSet set; + set.insert(1.0); + set.insert(2.0); + set.insert(3.0); + + EXPECT(equality(set)); + EXPECT(equalityXML(set)); +} + +/* ************************************************************************* */ +TEST (Serialization, FastVector) { + FastVector vector; + vector.push_back(v1); + vector.push_back(v2); + vector.push_back(v3); + + EXPECT(equality(vector)); + EXPECT(equalityXML(vector)); +} /* ************************************************************************* */ TEST (Serialization, matrix_vector) { @@ -36,6 +87,9 @@ TEST (Serialization, matrix_vector) { EXPECT(equalityXML(Matrix_(2, 2, 1.0, 2.0, 3.0, 4.0))); } +/* ************************************************************************* */ + + /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */