Skip to content

Commit

Permalink
Merge pull request #137 from loco-3d/std-ptr
Browse files Browse the repository at this point in the history
smart pointers: boost -> std
  • Loading branch information
nim65s authored Dec 5, 2024
2 parents 7d03a36 + 07e0d20 commit 147a51c
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 95 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- :warning: BREAKING: switch from boost smart pointers to std ones
- setup nix
- setup mergify

## [1.4.1] - 2024-04-12

- tests: fix use of np.random in tests
Expand Down
2 changes: 1 addition & 1 deletion include/ndcurves/bezier_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Safe, Point> {
typedef std::vector<point_t, Eigen::aligned_allocator<point_t> > t_point_t;
typedef typename t_point_t::const_iterator cit_point_t;
typedef bezier_curve<Time, Numeric, Safe, Point> bezier_curve_t;
typedef boost::shared_ptr<bezier_curve_t> bezier_curve_ptr_t;
typedef std::shared_ptr<bezier_curve_t> bezier_curve_ptr_t;
typedef piecewise_curve<Time, Numeric, Safe, point_t, point_t, bezier_curve_t>
piecewise_curve_t;
typedef curve_abc<Time, Numeric, Safe, point_t> curve_abc_t; // parent class
Expand Down
5 changes: 2 additions & 3 deletions include/ndcurves/curve_abc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
#ifndef _STRUCT_CURVE_ABC
#define _STRUCT_CURVE_ABC

#include <boost/serialization/shared_ptr.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <functional>
#include <memory>

#include "MathDefs.h"
#include "serialization/archive.hpp"
Expand Down Expand Up @@ -43,7 +42,7 @@ struct curve_abc : public serialization::Serializable {
curve_t; // parent class
typedef curve_abc<Time, Numeric, Safe, point_derivate_t>
curve_derivate_t; // parent class
typedef boost::shared_ptr<curve_t> curve_ptr_t;
typedef std::shared_ptr<curve_t> curve_ptr_t;

/* Constructors - destructors */
public:
Expand Down
4 changes: 2 additions & 2 deletions include/ndcurves/exact_cubic.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ struct exact_cubic : public piecewise_curve<Time, Numeric, Safe, Point> {
std::size_t getNumberSplines() { return this->getNumberCurves(); }

spline_t getSplineAt(std::size_t index) {
boost::shared_ptr<spline_t> s_ptr =
boost::dynamic_pointer_cast<spline_t>(this->curves_.at(index));
std::shared_ptr<spline_t> s_ptr =
std::dynamic_pointer_cast<spline_t>(this->curves_.at(index));
if (s_ptr)
return *s_ptr;
else
Expand Down
12 changes: 6 additions & 6 deletions include/ndcurves/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef CURVES_FWD_H
#define CURVES_FWD_H
#include <Eigen/Dense>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <memory>
#include <vector>

namespace ndcurves {
Expand Down Expand Up @@ -94,11 +94,11 @@ typedef curve_abc<double, double, true, transform_t, point6_t>
// (return dimension are fixed)

// shared pointer to abstract types:
typedef boost::shared_ptr<curve_abc_t> curve_ptr_t;
typedef boost::shared_ptr<curve_3_t> curve3_ptr_t;
typedef boost::shared_ptr<curve_rotation_t> curve_rotation_ptr_t;
typedef boost::shared_ptr<curve_translation_t> curve_translation_ptr_t;
typedef boost::shared_ptr<curve_SE3_t> curve_SE3_ptr_t;
typedef std::shared_ptr<curve_abc_t> curve_ptr_t;
typedef std::shared_ptr<curve_3_t> curve3_ptr_t;
typedef std::shared_ptr<curve_rotation_t> curve_rotation_ptr_t;
typedef std::shared_ptr<curve_translation_t> curve_translation_ptr_t;
typedef std::shared_ptr<curve_SE3_t> curve_SE3_ptr_t;

// definition of all curves class with pointX as return type:
typedef polynomial<double, double, true, pointX_t, t_pointX_t> polynomial_t;
Expand Down
8 changes: 4 additions & 4 deletions include/ndcurves/piecewise_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#define _CLASS_PIECEWISE_CURVE

#include <boost/serialization/vector.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <fstream>
#include <memory>
#include <sstream>

#include "curve_abc.h"
Expand Down Expand Up @@ -46,15 +46,15 @@ struct piecewise_curve
typedef curve_abc<Time, Numeric, Safe, point_t, point_derivate_t>
base_curve_t; // parent class
typedef CurveType curve_t; // contained curves base class
typedef boost::shared_ptr<curve_t> curve_ptr_t;
typedef std::shared_ptr<curve_t> curve_ptr_t;
typedef typename std::vector<curve_ptr_t> t_curve_ptr_t;
typedef typename std::vector<Time> t_time_t;
typedef piecewise_curve<Time, Numeric, Safe, Point, Point_derivate, CurveType>
piecewise_curve_t;
typedef piecewise_curve<Time, Numeric, Safe, Point_derivate, Point_derivate,
typename CurveType::curve_derivate_t>
piecewise_curve_derivate_t;
typedef boost::shared_ptr<typename piecewise_curve_derivate_t::curve_t>
typedef std::shared_ptr<typename piecewise_curve_derivate_t::curve_t>
curve_derivate_ptr_t;

public:
Expand Down Expand Up @@ -174,7 +174,7 @@ struct piecewise_curve

template <typename Curve>
void add_curve(const Curve& curve) {
curve_ptr_t curve_ptr = boost::make_shared<Curve>(curve);
curve_ptr_t curve_ptr = std::make_shared<Curve>(curve);
add_curve_ptr(curve_ptr);
}

Expand Down
6 changes: 3 additions & 3 deletions include/ndcurves/se3_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ struct SE3Curve : public curve_abc<Time, Numeric, Safe,
typedef curve_abc<Time, Numeric, Safe, matrix3_t, point3_t>
curve_rotation_t; // templated class used for the rotation (return
// dimension are fixed)
typedef boost::shared_ptr<curve_X_t> curve_ptr_t;
typedef boost::shared_ptr<curve_rotation_t> curve_rotation_ptr_t;
typedef boost::shared_ptr<curve_translation_t> curve_translation_ptr_t;
typedef std::shared_ptr<curve_X_t> curve_ptr_t;
typedef std::shared_ptr<curve_rotation_t> curve_rotation_ptr_t;
typedef std::shared_ptr<curve_translation_t> curve_translation_ptr_t;

typedef SO3Linear<Time, Numeric, Safe> SO3Linear_t;
typedef polynomial<Time, Numeric, Safe, pointX_t> polynomial_t;
Expand Down
1 change: 0 additions & 1 deletion include/ndcurves/serialization/curves.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

#include <boost/serialization/shared_ptr.hpp>
#include <boost/shared_ptr.hpp>

#include "ndcurves/bezier_curve.h"
#include "ndcurves/constant_curve.h"
Expand Down
62 changes: 31 additions & 31 deletions python/ndcurves/curves_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,10 @@ SE3Curve_t* wrapSE3CurveFromPosAndRotation(const pointX_t& init_pos,
SE3Curve_t* wrapSE3CurveFromBezier3Translation(bezier3_t& translation_curve,
const matrix3_t& init_rot,
const matrix3_t& end_rot) {
boost::shared_ptr<bezier3_t> translation(
new bezier3_t(translation_curve.waypoints().begin(),
translation_curve.waypoints().end(),
translation_curve.min(), translation_curve.max()));
std::shared_ptr<bezier3_t> translation = std::make_shared<bezier3_t>(
translation_curve.waypoints().begin(),
translation_curve.waypoints().end(), translation_curve.min(),
translation_curve.max());
return new SE3Curve_t(translation, init_rot, end_rot);
}

Expand Down Expand Up @@ -891,8 +891,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
eigenpy::exposeQuaternion();*/
/** END eigenpy init**/
/** Expose base abstracts class for each dimension/type : **/
class_<curve_abc_t, boost::noncopyable,
boost::shared_ptr<curve_abc_callback>>("curve")
class_<curve_abc_t, boost::noncopyable, std::shared_ptr<curve_abc_callback>>(
"curve")
.def("__call__", &curve_abc_t::operator(),
"Evaluate the curve at the given time.", args("self", "t"))
.def("derivate", &curve_abc_t::derivate,
Expand Down Expand Up @@ -933,7 +933,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<curve_abc_t>());

class_<curve_3_t, boost::noncopyable, bases<curve_abc_t>,
boost::shared_ptr<curve_3_callback>>("curve3")
std::shared_ptr<curve_3_callback>>("curve3")
.def("__call__", &curve_3_t::operator(),
"Evaluate the curve at the given time.", args("self", "t"))
.def("derivate", &curve_3_t::derivate,
Expand All @@ -959,7 +959,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<curve_3_t>());

class_<curve_rotation_t, boost::noncopyable, bases<curve_abc_t>,
boost::shared_ptr<curve_rotation_callback>>("curve_rotation")
std::shared_ptr<curve_rotation_callback>>("curve_rotation")
.def("__call__", &curve_rotation_t::operator(),
"Evaluate the curve at the given time.", args("self", "t"))
.def("derivate", &curve_rotation_t::derivate,
Expand All @@ -985,7 +985,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<curve_rotation_t>());

class_<curve_SE3_t, boost::noncopyable, bases<curve_abc_t>,
boost::shared_ptr<curve_SE3_callback>>("curve_SE3")
std::shared_ptr<curve_SE3_callback>>("curve_SE3")
.def("__call__", &se3Return,
"Evaluate the curve at the given time. Return as an homogeneous "
"matrix.",
Expand Down Expand Up @@ -1039,8 +1039,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
&bezier3_t::cross;
bezier3_t (bezier3_t::*cross_pointBez3)(const bezier3_t::point_t&) const =
&bezier3_t::cross;
class_<bezier3_t, bases<curve_3_t>, boost::shared_ptr<bezier3_t>>("bezier3",
init<>())
class_<bezier3_t, bases<curve_3_t>, std::shared_ptr<bezier3_t>>("bezier3",
init<>())
.def("__init__", make_constructor(&wrapBezier3Constructor))
.def("__init__", make_constructor(&wrapBezier3ConstructorBounds))
.def("__init__", make_constructor(&wrapBezier3ConstructorConstraints))
Expand Down Expand Up @@ -1108,8 +1108,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
bezier_t (bezier_t::*cross_bez)(const bezier_t&) const = &bezier_t::cross;
bezier_t (bezier_t::*cross_pointBez)(const bezier_t::point_t&) const =
&bezier_t::cross;
class_<bezier_t, bases<curve_abc_t>, boost::shared_ptr<bezier_t>>("bezier",
init<>())
class_<bezier_t, bases<curve_abc_t>, std::shared_ptr<bezier_t>>("bezier",
init<>())
.def("__init__", make_constructor(&wrapBezierConstructor))
.def("__init__", make_constructor(&wrapBezierConstructorBounds))
.def("__init__", make_constructor(&wrapBezierConstructorConstraints))
Expand Down Expand Up @@ -1204,8 +1204,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
const bezier_linear_variable_t::point_t&) const =
&bezier_linear_variable_t::cross;
class_<bezier_linear_variable_t, bases<curve_abc_t>,
boost::shared_ptr<bezier_linear_variable_t>>("bezier_linear_variable",
no_init)
std::shared_ptr<bezier_linear_variable_t>>("bezier_linear_variable",
no_init)
.def("__init__", make_constructor(&wrapBezierLinearConstructor))
.def("__init__", make_constructor(&wrapBezierLinearConstructorBounds))
.def("min", &bezier_linear_variable_t::min)
Expand Down Expand Up @@ -1269,7 +1269,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
polynomial_t (polynomial_t::*cross_point)(const polynomial_t::point_t&)
const = &polynomial_t::cross;

class_<polynomial_t, bases<curve_abc_t>, boost::shared_ptr<polynomial_t>>(
class_<polynomial_t, bases<curve_abc_t>, std::shared_ptr<polynomial_t>>(
"polynomial", init<>())
.def(
"__init__",
Expand Down Expand Up @@ -1360,7 +1360,7 @@ BOOST_PYTHON_MODULE(ndcurves) {

/** END polynomial function**/
/** BEGIN piecewise curve function **/
class_<piecewise_t, bases<curve_abc_t>, boost::shared_ptr<piecewise_t>>(
class_<piecewise_t, bases<curve_abc_t>, std::shared_ptr<piecewise_t>>(
"piecewise", init<>())
.def("__init__",
make_constructor(&wrapPiecewiseCurveConstructor,
Expand Down Expand Up @@ -1438,7 +1438,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def(CopyableVisitor<piecewise_t>())
.def_pickle(curve_pickle_suite<piecewise_t>());

class_<piecewise3_t, bases<curve_3_t>, boost::shared_ptr<piecewise3_t>>(
class_<piecewise3_t, bases<curve_3_t>, std::shared_ptr<piecewise3_t>>(
"piecewise3", init<>())
.def("__init__",
make_constructor(&wrapPiecewise3CurveConstructor,
Expand Down Expand Up @@ -1513,7 +1513,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<piecewise3_t>());

class_<piecewise_bezier_t, bases<curve_abc_t>,
boost::shared_ptr<piecewise_bezier_t>>("piecewise_bezier", init<>())
std::shared_ptr<piecewise_bezier_t>>("piecewise_bezier", init<>())
.def("__init__",
make_constructor(&wrapPiecewiseBezierConstructor,
default_call_policies(), arg("curve")),
Expand All @@ -1537,8 +1537,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<piecewise_bezier_t>());

class_<piecewise_linear_bezier_t, bases<curve_abc_t>,
boost::shared_ptr<piecewise_linear_bezier_t>>(
"piecewise_bezier_linear", init<>(args("self")))
std::shared_ptr<piecewise_linear_bezier_t>>("piecewise_bezier_linear",
init<>(args("self")))
.def("__init__",
make_constructor(&wrapPiecewiseBezierLinearConstructor,
default_call_policies(), arg("curve")),
Expand All @@ -1562,8 +1562,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def(CopyableVisitor<piecewise_linear_bezier_t>())
.def_pickle(curve_pickle_suite<piecewise_linear_bezier_t>());

class_<piecewise_SE3_t, bases<curve_SE3_t>,
boost::shared_ptr<piecewise_SE3_t>>("piecewise_SE3", init<>())
class_<piecewise_SE3_t, bases<curve_SE3_t>, std::shared_ptr<piecewise_SE3_t>>(
"piecewise_SE3", init<>())
.def("__init__",
make_constructor(&wrapPiecewiseSE3Constructor,
default_call_policies(), arg("curve")),
Expand Down Expand Up @@ -1602,7 +1602,7 @@ BOOST_PYTHON_MODULE(ndcurves) {

/** END piecewise curve function **/
/** BEGIN exact_cubic curve**/
class_<exact_cubic_t, bases<curve_abc_t>, boost::shared_ptr<exact_cubic_t>>(
class_<exact_cubic_t, bases<curve_abc_t>, std::shared_ptr<exact_cubic_t>>(
"exact_cubic", init<>(args("self")))
.def("__init__",
make_constructor(&wrapExactCubicConstructor, default_call_policies(),
Expand All @@ -1622,8 +1622,8 @@ BOOST_PYTHON_MODULE(ndcurves) {
/** END exact_cubic curve**/
/** BEGIN cubic_hermite_spline **/
class_<cubic_hermite_spline_t, bases<curve_abc_t>,
boost::shared_ptr<cubic_hermite_spline_t>>("cubic_hermite_spline",
init<>(args("self")))
std::shared_ptr<cubic_hermite_spline_t>>("cubic_hermite_spline",
init<>(args("self")))
.def("__init__", make_constructor(&wrapCubicHermiteSplineConstructor,
bp::default_call_policies(),
args("points", "tangents", "times")))
Expand Down Expand Up @@ -1661,7 +1661,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
/** END bernstein polynomial**/

/** BEGIN SO3 Linear**/
class_<SO3Linear_t, bases<curve_rotation_t>, boost::shared_ptr<SO3Linear_t>>(
class_<SO3Linear_t, bases<curve_rotation_t>, std::shared_ptr<SO3Linear_t>>(
"SO3Linear", init<>())
.def("__init__",
make_constructor(
Expand Down Expand Up @@ -1689,7 +1689,7 @@ BOOST_PYTHON_MODULE(ndcurves) {

/** END SO3 Linear**/
/** BEGIN SE3 Curve**/
class_<SE3Curve_t, bases<curve_SE3_t>, boost::shared_ptr<SE3Curve_t>>(
class_<SE3Curve_t, bases<curve_SE3_t>, std::shared_ptr<SE3Curve_t>>(
"SE3Curve", init<>())
.def("__init__",
make_constructor(
Expand Down Expand Up @@ -1763,7 +1763,7 @@ BOOST_PYTHON_MODULE(ndcurves) {

/** END SE3 Curve**/
/** BEGIN constant curve function**/
class_<constant_t, bases<curve_abc_t>, boost::shared_ptr<constant_t>>(
class_<constant_t, bases<curve_abc_t>, std::shared_ptr<constant_t>>(
"constant", init<>())
.def("__init__",
make_constructor(&wrapConstantConstructorTime,
Expand All @@ -1785,7 +1785,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<constant_t>());
/** END constant function**/
/** BEGIN constant 3 curve function**/
class_<constant3_t, bases<curve_3_t>, boost::shared_ptr<constant3_t>>(
class_<constant3_t, bases<curve_3_t>, std::shared_ptr<constant3_t>>(
"constant3", init<>())
.def("__init__",
make_constructor(&wrapConstant3ConstructorTime,
Expand All @@ -1807,7 +1807,7 @@ BOOST_PYTHON_MODULE(ndcurves) {
.def_pickle(curve_pickle_suite<constant3_t>());
/** END constant 3 function**/
/** BEGIN sinusoidal curve function**/
class_<sinusoidal_t, bases<curve_abc_t>, boost::shared_ptr<sinusoidal_t>>(
class_<sinusoidal_t, bases<curve_abc_t>, std::shared_ptr<sinusoidal_t>>(
"sinusoidal", init<>())
.def("__init__",
make_constructor(&wrapSinusoidalConstructor, default_call_policies(),
Expand Down
Loading

0 comments on commit 147a51c

Please sign in to comment.