Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilhem Saurel
ndcurves
Commits
20477962
Unverified
Commit
20477962
authored
Jul 25, 2020
by
Guilhem Saurel
Committed by
GitHub
Jul 25, 2020
Browse files
Merge pull request #46 from pFernbach/topic/serialization_version
serialization version
parents
65315995
6559791b
Changes
16
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
20477962
...
...
@@ -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
)
...
...
include/curves/bernstein.h
View file @
20477962
...
...
@@ -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
include/curves/bezier_curve.h
View file @
20477962
...
...
@@ -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
include/curves/constant_curve.h
View file @
20477962
...
...
@@ -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
include/curves/cubic_hermite_spline.h
View file @
20477962
...
...
@@ -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
include/curves/curve_abc.h
View file @
20477962
...
...
@@ -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
include/curves/exact_cubic.h
View file @
20477962
...
...
@@ -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
include/curves/linear_variable.h
View file @
20477962
...
...
@@ -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
include/curves/piecewise_curve.h
View file @
20477962
...
...
@@ -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
include/curves/polynomial.h
View file @
20477962
...
...
@@ -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
include/curves/se3_curve.h
View file @
20477962
...
...
@@ -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
include/curves/serialization/archive.hpp
View file @
20477962
...
...
@@ -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."
);
...
...
include/curves/serialization/registeration.hpp
View file @
20477962
...
...
@@ -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
...
...
include/curves/sinusoidal.h
View file @
20477962
...
...
@@ -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
include/curves/so3_linear.h
View file @
20477962
...
...
@@ -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
python/curves/curves_python.cpp
View file @
20477962
...
...
@@ -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
;
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment