Commit d2e99bb7 authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

[serialization] factorize all register_type call in a header file

parent 90d22b7e
#ifndef _STRUCT_SE3_CURVE_H
#define _STRUCT_SE3_CURVE_H
#include "fwd.h"
#include "MathDefs.h"
#include "curve_abc.h"
#include "so3_linear.h"
......@@ -192,20 +191,6 @@ struct SE3Curve : public curve_abc<Time, Numeric, Safe, Eigen::Transform<Numeric
if (version) {
// Do something depending on version ?
}
//register derived class
ar.template register_type<bezier_curve<Scalar, Scalar, Safe, pointX_t> >();
ar.template register_type<cubic_hermite_spline<Scalar, Scalar, Safe, pointX_t> >();
ar.template register_type<exact_cubic<Scalar, Scalar, Safe, pointX_t> >();
ar.template register_type<piecewise_curve<Scalar, Scalar, Safe, pointX_t,
std::vector<pointX_t, Eigen::aligned_allocator<pointX_t> >, polynomial_t> >();
ar.template register_type<piecewise_curve<Scalar, Scalar, Safe, pointX_t,
std::vector<pointX_t, Eigen::aligned_allocator<pointX_t> >, bezier_curve<Scalar, Scalar, Safe, pointX_t> > >();
ar.template register_type<piecewise_curve<Scalar, Scalar, Safe, pointX_t,
std::vector<pointX_t, Eigen::aligned_allocator<pointX_t> >, cubic_hermite_spline<Scalar, Scalar, Safe, pointX_t> > >();
ar.template register_type<polynomial_t>();
ar.template register_type<SO3Linear_t>();
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(curve_abc_t);
ar& boost::serialization::make_nvp("dim", dim_);
ar& boost::serialization::make_nvp("translation_curve", translation_curve_);
......
......@@ -3,9 +3,6 @@
#ifndef __curves_serialization_archive_hpp__
#define __curves_serialization_archive_hpp__
#include "fwd.hpp"
#include <fstream>
#include <string>
#include <stdexcept>
......@@ -15,6 +12,7 @@
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include "registeration.h"
namespace curves {
namespace serialization {
......@@ -36,6 +34,7 @@ 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.");
......@@ -49,6 +48,7 @@ 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.");
......@@ -63,6 +63,7 @@ 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.");
......@@ -77,6 +78,7 @@ 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.");
......@@ -90,6 +92,7 @@ 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.");
......@@ -103,6 +106,7 @@ 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.");
......
/**
* \file registeration.h
* \brief registeration of class for serialization
* \author Pierre Fernbach
* \version 0.1
* \date 27/11/19
*
* Boost::serialization need to be aware of all the derived class of the abstract curve_abc,
* and thier template parameters.
* Otherwise we cannot serialize a pointer to curve_abc.
* New class should be added at the end and the order should not change
* or it will break backward compatibility when deserializing objects.
*
*/
#ifndef CURVES_REGISTERATION_H
#define CURVES_REGISTERATION_H
#include <Eigen/Dense>
#include <vector>
#include "curves/fwd.h"
namespace curves {
namespace serialization {
template <class Archive>
void register_types(Archive& ar){
typedef double Scalar;
typedef Eigen::Matrix<Scalar, -1, 1> pointX_t;
typedef std::vector<pointX_t, Eigen::aligned_allocator<pointX_t> > t_point_t;
//register derived class
ar.template register_type<bezier_curve<Scalar, Scalar, true, pointX_t> >();
ar.template register_type<cubic_hermite_spline<Scalar, Scalar, true, pointX_t> >();
ar.template register_type<exact_cubic<Scalar, Scalar, true, pointX_t,
t_point_t, polynomial<Scalar, Scalar, true, pointX_t,t_point_t> > >();
ar.template register_type<piecewise_curve<Scalar, Scalar, true, pointX_t,
t_point_t, polynomial<Scalar, Scalar, true, pointX_t, t_point_t> ,pointX_t> >();
ar.template register_type<piecewise_curve<Scalar, Scalar, true, pointX_t,
t_point_t, bezier_curve<Scalar, Scalar, true, pointX_t> ,pointX_t> >();
ar.template register_type<piecewise_curve<Scalar, Scalar, true, pointX_t,
t_point_t, cubic_hermite_spline<Scalar, Scalar, true, pointX_t> ,pointX_t> >();
ar.template register_type<polynomial<Scalar, Scalar, true, pointX_t, t_point_t> >();
ar.template register_type<SO3Linear<Scalar, Scalar, true> >();
}
}
}
#endif // CURVES_REGISTERATION_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment