...
 
......@@ -25,6 +25,7 @@ INCLUDE(cmake/python.cmake)
# Project definition
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
SET(CMAKE_CXX_STANDARD 11)
# Project dependencies
ADD_PROJECT_DEPENDENCY(Eigen3 REQUIRED PKG_CONFIG_REQUIRES eigen3)
......
......@@ -93,4 +93,7 @@ std::vector<Bern<Numeric> > makeBernstein(const unsigned int n) {
return res;
}
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(typename Numeric, curves::Bern<Numeric>)
#endif //_CLASS_BERNSTEIN
......@@ -516,4 +516,8 @@ template <typename Time, typename Numeric, bool Safe, typename Point>
const double bezier_curve<Time, Numeric, Safe, Point>::MARGIN(0.001);
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point),
SINGLE_ARG(curves::bezier_curve<Time, Numeric, Safe, Point>))
#endif //_CLASS_BEZIERCURVE
......@@ -171,4 +171,7 @@ struct constant_curve : public curve_abc<Time, Numeric, Safe, Point, Point_deriv
}; // struct constant_curve
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point, typename Point_derivate),
SINGLE_ARG(curves::constant_curve<Time, Numeric, Safe, Point, Point_derivate>))
#endif // _CLASS_CONSTANTCURVE
......@@ -367,4 +367,7 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Safe, Point> {
}
}; // End struct Cubic hermite spline
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point),
SINGLE_ARG(curves::cubic_hermite_spline<Time, Numeric, Safe, Point>))
#endif //_CLASS_CUBICHERMITESPLINE
......@@ -14,9 +14,9 @@
#include "MathDefs.h"
#include "serialization/archive.hpp"
#include "serialization/eigen-matrix.hpp"
#include "serialization/registeration.hpp"
#include <boost/serialization/shared_ptr.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <functional>
namespace curves {
......@@ -136,7 +136,8 @@ struct curve_abc : std::unary_function<Time, Point>, public serialization::Seria
// Serialization of the class
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& /*ar*/, const unsigned int version) {
void serialize(Archive& ar, const unsigned int version) {
serialization::register_types<Archive>(ar, version);
if (version) {
// Do something depending on version ?
}
......@@ -144,4 +145,7 @@ struct curve_abc : std::unary_function<Time, Point>, public serialization::Seria
};
BOOST_SERIALIZATION_ASSUME_ABSTRACT(curve_abc)
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point, typename Point_derivate),
SINGLE_ARG(curves::curve_abc<Time, Numeric, Safe, Point, Point_derivate>))
#endif //_STRUCT_CURVE_ABC
......@@ -309,4 +309,8 @@ struct exact_cubic : public piecewise_curve<Time, Numeric, Safe, Point> {
}
};
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point,
typename T_Point, typename SplineBase),
SINGLE_ARG(curves::exact_cubic<Time, Numeric, Safe, Point, T_Point, SplineBase>))
#endif //_CLASS_EXACTCUBIC
......@@ -183,4 +183,7 @@ BezierFixed evaluateLinear(const BezierLinear& bIn, const X x) {
}
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Numeric, bool Safe),
SINGLE_ARG(curves::linear_variable<Numeric, Safe>))
#endif //_CLASS_LINEAR_VARIABLE
......@@ -608,4 +608,8 @@ const double piecewise_curve<Time, Numeric, Safe, Point, Point_derivate, CurveTy
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point,
typename Point_derivate, typename CurveType),
SINGLE_ARG(curves::piecewise_curve<Time, Numeric, Safe, Point, Point_derivate, CurveType>))
#endif // _CLASS_PIECEWISE_CURVE
......@@ -440,4 +440,7 @@ struct polynomial : public curve_abc<Time, Numeric, Safe, Point> {
}; // class polynomial
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point, typename T_Point),
SINGLE_ARG(curves::polynomial<Time, Numeric, Safe, Point, T_Point>))
#endif //_STRUCT_POLYNOMIAL
......@@ -258,4 +258,7 @@ struct SE3Curve : public curve_abc<Time, Numeric, Safe, Eigen::Transform<Numeric
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe),
SINGLE_ARG(curves::SE3Curve<Time, Numeric, Safe>))
#endif // SE3_CURVE_H
......@@ -12,7 +12,27 @@
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include "registeration.hpp"
#include <boost/serialization/version.hpp>
/* Define the current version number for the serialization
* Must be increased everytime the save() method of a class is modified
* Or when a change is made to register_types()
* */
const unsigned int CURVES_API_VERSION = 1;
#define SINGLE_ARG(...) __VA_ARGS__ // Macro used to be able to put comma in the following macro arguments
// Macro used to define the serialization version of a templated class
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type) \
namespace boost { \
namespace serialization { \
template <Template> \
struct version<Type> { \
static constexpr unsigned int value = CURVES_API_VERSION; \
}; \
template <Template> \
constexpr unsigned int version<Type>::value; \
} \
}
namespace curves {
namespace serialization {
......@@ -34,7 +54,6 @@ struct Serializable {
std::ifstream ifs(filename.c_str());
if (ifs) {
boost::archive::text_iarchive ia(ifs);
register_types<boost::archive::text_iarchive>(ia);
ia >> derived<Derived>();
} else {
const std::string exception_message(filename + " does not seem to be a valid file.");
......@@ -48,7 +67,6 @@ struct Serializable {
std::ofstream ofs(filename.c_str());
if (ofs) {
boost::archive::text_oarchive oa(ofs);
register_types<boost::archive::text_oarchive>(oa);
oa << derived<Derived>();
} else {
const std::string exception_message(filename + " does not seem to be a valid file.");
......@@ -65,7 +83,6 @@ struct Serializable {
std::ifstream ifs(filename.c_str());
if (ifs) {
boost::archive::xml_iarchive ia(ifs);
register_types<boost::archive::xml_iarchive>(ia);
ia >> boost::serialization::make_nvp(tag_name.c_str(), derived<Derived>());
} else {
const std::string exception_message(filename + " does not seem to be a valid file.");
......@@ -82,7 +99,6 @@ struct Serializable {
std::ofstream ofs(filename.c_str());
if (ofs) {
boost::archive::xml_oarchive oa(ofs);
register_types<boost::archive::xml_oarchive>(oa);
oa << boost::serialization::make_nvp(tag_name.c_str(), derived<Derived>());
} else {
const std::string exception_message(filename + " does not seem to be a valid file.");
......@@ -96,7 +112,6 @@ struct Serializable {
std::ifstream ifs(filename.c_str());
if (ifs) {
boost::archive::binary_iarchive ia(ifs);
register_types<boost::archive::binary_iarchive>(ia);
ia >> derived<Derived>();
} else {
const std::string exception_message(filename + " does not seem to be a valid file.");
......@@ -110,7 +125,6 @@ struct Serializable {
std::ofstream ofs(filename.c_str());
if (ofs) {
boost::archive::binary_oarchive oa(ofs);
register_types<boost::archive::binary_oarchive>(oa);
oa << derived<Derived>();
} else {
const std::string exception_message(filename + " does not seem to be a valid file.");
......
......@@ -30,24 +30,26 @@ namespace curves {
namespace serialization {
template <class Archive>
void register_types(Archive& ar) {
void register_types(Archive& ar, const unsigned int version) {
// register derived class
ar.template register_type<polynomial_t>();
ar.template register_type<exact_cubic_t>();
ar.template register_type<bezier_t>();
ar.template register_type<constant_t>();
ar.template register_type<cubic_hermite_spline_t>();
ar.template register_type<piecewise_t>();
ar.template register_type<polynomial3_t>();
ar.template register_type<exact_cubic3_t>();
ar.template register_type<bezier3_t>();
ar.template register_type<constant3_t>();
ar.template register_type<cubic_hermite_spline3_t>();
ar.template register_type<piecewise3_t>();
ar.template register_type<SO3Linear_t>();
ar.template register_type<SE3Curve_t>();
ar.template register_type<sinusoidal_t>();
ar.template register_type<piecewise_SE3_t>();
if(version >= 1){
ar.template register_type<constant3_t>();
ar.template register_type<sinusoidal_t>();
ar.template register_type<constant_t>();
}
}
} // namespace serialization
......
......@@ -213,4 +213,7 @@ struct sinusoidal : public curve_abc<Time, Numeric, Safe, Point> {
}; // struct sinusoidal
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point),
SINGLE_ARG(curves::sinusoidal<Time, Numeric, Safe, Point>))
#endif // _CLASS_SINUSOIDALCURVE
......@@ -302,4 +302,7 @@ struct SO3Linear : public curve_abc<Time, Numeric, Safe, matrix3_t, point3_t > {
} // namespace curves
DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe),
SINGLE_ARG(curves::SO3Linear<Time, Numeric, Safe>))
#endif // _STRUCT_SO3_LINEAR_H
......@@ -94,7 +94,6 @@ struct curve_pickle_suite : pickle_suite {
static object getstate (const Curve& curve) {
std::ostringstream os;
boost::archive::text_oarchive oa(os);
curves::serialization::register_types(oa);
oa << curve;
return str(os.str());
}
......@@ -105,7 +104,6 @@ struct curve_pickle_suite : pickle_suite {
std::string st = extract<std::string> (s)();
std::istringstream is (st);
boost::archive::text_iarchive ia (is);
curves::serialization::register_types(ia);
ia >> curve;
}
};
......
......@@ -173,27 +173,30 @@ BOOST_AUTO_TEST_CASE(serialization) {
BOOST_CHECK(c == c_txt);
BOOST_CHECK(c == c_xml);
BOOST_CHECK(c == c_binary);
}
BOOST_AUTO_TEST_CASE(serialization_3) {
std::string fileName("fileTest_constant3");
point3_t p;
p << -1, 0.5, 2.;
// } BOOST_AUTO_TEST_CASE(serialization_3) {
// This test used to be split in two, but this raise
// a weird "free(): invalid pointer" after test completion
// without failures on Boost 1.72.0
constant3_t c(p);
std::string fileName3("fileTest_constant3");
point3_t p3;
p3 << -1, 0.5, 2.;
c.saveAsText<constant3_t>(fileName + ".txt");
c.saveAsXML<constant3_t>(fileName + ".xml", "constant");
c.saveAsBinary<constant3_t>(fileName);
constant3_t c3(p3);
constant3_t c_txt, c_xml, c_binary;
c_txt.loadFromText<constant3_t>(fileName + ".txt");
c_xml.loadFromXML<constant3_t>(fileName + ".xml", "constant");
c_binary.loadFromBinary<constant3_t>(fileName);
c3.saveAsText<constant3_t>(fileName3 + ".txt");
c3.saveAsXML<constant3_t>(fileName3 + ".xml", "constant");
c3.saveAsBinary<constant3_t>(fileName3);
BOOST_CHECK(c == c_txt);
BOOST_CHECK(c == c_xml);
BOOST_CHECK(c == c_binary);
constant3_t c3_txt, c3_xml, c3_binary;
c3_txt.loadFromText<constant3_t>(fileName3 + ".txt");
c3_xml.loadFromXML<constant3_t>(fileName3 + ".xml", "constant");
c3_binary.loadFromBinary<constant3_t>(fileName3);
BOOST_CHECK(c3 == c3_txt);
BOOST_CHECK(c3 == c3_xml);
BOOST_CHECK(c3 == c3_binary);
}
BOOST_AUTO_TEST_SUITE_END()