Added serialization functions to Fast* containers (wrappers around STL containers that use a boost pool allocator for speed)
parent
0d2a9018e3
commit
8885b33191
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <boost/pool/pool_alloc.hpp>
|
#include <boost/pool/pool_alloc.hpp>
|
||||||
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
#include <boost/serialization/list.hpp>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
@ -51,6 +53,14 @@ public:
|
||||||
/** Copy constructor from the base map class */
|
/** Copy constructor from the base map class */
|
||||||
FastList(const Base& x) : Base(x) {}
|
FastList(const Base& x) : Base(x) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Serialization function */
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template<class ARCHIVE>
|
||||||
|
void serialize(ARCHIVE & ar, const unsigned int version) {
|
||||||
|
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <boost/pool/pool_alloc.hpp>
|
#include <boost/pool/pool_alloc.hpp>
|
||||||
#include <boost/serialization/base_object.hpp>
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
#include <boost/serialization/map.hpp>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
@ -57,7 +58,7 @@ public:
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
template<class ARCHIVE>
|
template<class ARCHIVE>
|
||||||
void serialize(ARCHIVE & ar, const unsigned int version) {
|
void serialize(ARCHIVE & ar, const unsigned int version) {
|
||||||
ar & boost::serialization::base_object<Base>(*this);
|
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
#include <boost/pool/pool_alloc.hpp>
|
#include <boost/pool/pool_alloc.hpp>
|
||||||
#include <boost/mpl/has_xxx.hpp>
|
#include <boost/mpl/has_xxx.hpp>
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
#include <boost/serialization/set.hpp>
|
||||||
|
|
||||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(print)
|
BOOST_MPL_HAS_XXX_TRAIT_DEF(print)
|
||||||
|
|
||||||
|
|
@ -74,6 +76,14 @@ public:
|
||||||
|
|
||||||
/** Check for equality within tolerance to implement Testable */
|
/** Check for equality within tolerance to implement Testable */
|
||||||
bool equals(const FastSet<VALUE>& other, double tol = 1e-9) const { return FastSetTestableHelper<VALUE>::equals(*this, other, tol); }
|
bool equals(const FastSet<VALUE>& other, double tol = 1e-9) const { return FastSetTestableHelper<VALUE>::equals(*this, other, tol); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Serialization function */
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template<class ARCHIVE>
|
||||||
|
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
|
// This is the default Testable interface for *non*Testable elements, which
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/pool/pool_alloc.hpp>
|
#include <boost/pool/pool_alloc.hpp>
|
||||||
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
#include <boost/serialization/vector.hpp>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
@ -56,6 +58,14 @@ public:
|
||||||
/** Copy constructor from the base map class */
|
/** Copy constructor from the base map class */
|
||||||
FastVector(const Base& x) : Base(x) {}
|
FastVector(const Base& x) : Base(x) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Serialization function */
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template<class ARCHIVE>
|
||||||
|
void serialize(ARCHIVE & ar, const unsigned int version) {
|
||||||
|
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include <gtsam/base/Matrix.h>
|
#include <gtsam/base/Matrix.h>
|
||||||
#include <gtsam/base/Vector.h>
|
#include <gtsam/base/Vector.h>
|
||||||
|
#include <gtsam/base/FastList.h>
|
||||||
|
#include <gtsam/base/FastMap.h>
|
||||||
|
#include <gtsam/base/FastSet.h>
|
||||||
|
#include <gtsam/base/FastVector.h>
|
||||||
|
|
||||||
#include <gtsam/base/serializationTestHelpers.h>
|
#include <gtsam/base/serializationTestHelpers.h>
|
||||||
#include <CppUnitLite/TestHarness.h>
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
|
@ -26,6 +30,53 @@ using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
using namespace gtsam::serializationTestHelpers;
|
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<Vector> list;
|
||||||
|
list.push_back(v1);
|
||||||
|
list.push_back(v2);
|
||||||
|
list.push_back(v3);
|
||||||
|
|
||||||
|
EXPECT(equality(list));
|
||||||
|
EXPECT(equalityXML(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST (Serialization, FastMap) {
|
||||||
|
FastMap<int, Vector> 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<double> 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;
|
||||||
|
vector.push_back(v1);
|
||||||
|
vector.push_back(v2);
|
||||||
|
vector.push_back(v3);
|
||||||
|
|
||||||
|
EXPECT(equality(vector));
|
||||||
|
EXPECT(equalityXML(vector));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST (Serialization, matrix_vector) {
|
TEST (Serialization, matrix_vector) {
|
||||||
|
|
@ -36,6 +87,9 @@ TEST (Serialization, matrix_vector) {
|
||||||
EXPECT(equalityXML<Matrix>(Matrix_(2, 2, 1.0, 2.0, 3.0, 4.0)));
|
EXPECT(equalityXML<Matrix>(Matrix_(2, 2, 1.0, 2.0, 3.0, 4.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue