11// /
2- // / Copyright (c) 2016-2024 CNRS INRIA
3- // / Copyright (c) 2025-2025 Heriot-Watt University
2+ // / Copyright (c) 2016-2025 CNRS INRIA
3+ // / Copyright (c) 2025 Heriot-Watt University
44// / This file was taken from Pinocchio (header
55// / <pinocchio/bindings/python/utils/std-vector.hpp>)
66// /
@@ -53,7 +53,7 @@ bool from_python_list(PyObject *obj_ptr, T *) {
5353
5454template <typename vector_type, bool NoProxy>
5555struct build_list {
56- static ::boost::python ::list run (vector_type &vec, const bool deep_copy) {
56+ static bp ::list run (vector_type &vec, const bool deep_copy) {
5757 if (deep_copy) return build_list<vector_type, true >::run (vec, true );
5858
5959 bp::list bp_list;
@@ -66,7 +66,7 @@ struct build_list {
6666
6767template <typename vector_type>
6868struct build_list <vector_type, true > {
69- static ::boost::python ::list run (vector_type &vec, const bool ) {
69+ static bp ::list run (vector_type &vec, const bool ) {
7070 typedef bp::iterator<vector_type> iterator;
7171 return bp::list (iterator ()(vec));
7272 }
@@ -77,8 +77,7 @@ struct build_list<vector_type, true> {
7777// / them.
7878template <typename Container>
7979struct overload_base_get_item_for_std_vector
80- : public boost::python::def_visitor<
81- overload_base_get_item_for_std_vector<Container>> {
80+ : public bp::def_visitor<overload_base_get_item_for_std_vector<Container>> {
8281 typedef typename Container::value_type value_type;
8382 typedef typename Container::value_type data_type;
8483 typedef size_t index_type;
@@ -87,13 +86,13 @@ struct overload_base_get_item_for_std_vector
8786 void visit (Class &cl) const {
8887 cl.def (" __getitem__" , &base_get_item_int)
8988 .def (" __getitem__" , &base_get_item_slice)
90- .def (" __getitem__" , &base_get_item_list )
91- .def (" __getitem__" , &base_get_item_tuple );
89+ .def (" __getitem__" , &base_get_item_list_or_tuple<bp::list> )
90+ .def (" __getitem__" , &base_get_item_list_or_tuple<bp::tuple> );
9291 }
9392
9493 private:
95- static boost::python:: object base_get_item_int (
96- boost::python::back_reference<Container &> container, PyObject *i_) {
94+ static bp:: object base_get_item_int (bp::back_reference<Container &> container,
95+ PyObject *i_) {
9796 index_type idx = convert_index (container.get (), i_);
9897 typename Container::iterator i = container.get ().begin ();
9998 std::advance (i, idx);
@@ -108,9 +107,8 @@ struct overload_base_get_item_for_std_vector
108107 return bp::object (bp::handle<>(convert (*i)));
109108 }
110109
111- static boost::python::object base_get_item_slice (
112- boost::python::back_reference<Container &> container,
113- boost::python::slice slice) {
110+ static bp::object base_get_item_slice (
111+ bp::back_reference<Container &> container, bp::slice slice) {
114112 bp::list out;
115113 try {
116114 auto rng =
@@ -134,32 +132,16 @@ struct overload_base_get_item_for_std_vector
134132 return out;
135133 }
136134
137- static bp::object base_get_item_list (bp::back_reference<Container &> c,
138- bp::list idxs) {
135+ template <typename list_or_tuple>
136+ static bp::object base_get_item_list_or_tuple (
137+ bp::back_reference<Container &> c, list_or_tuple idxs) {
139138 const Py_ssize_t m = bp::len (idxs);
140139 bp::list out;
141140 for (Py_ssize_t k = 0 ; k < m; ++k) {
142141 bp::object obj = idxs[k];
143142 bp::extract<long > ei (obj);
144143 if (!ei.check ()) {
145- PyErr_SetString (PyExc_TypeError, " indices must be integers" );
146- bp::throw_error_already_set ();
147- }
148- auto idx = normalize_index (c.get ().size (), ei ());
149- out.append (elem_ref (c.get (), idx));
150- }
151- return out;
152- }
153-
154- static bp::object base_get_item_tuple (bp::back_reference<Container &> c,
155- bp::tuple idxs) {
156- const Py_ssize_t m = bp::len (idxs);
157- bp::list out;
158- for (Py_ssize_t k = 0 ; k < m; ++k) {
159- bp::object obj = idxs[k];
160- bp::extract<long > ei (obj);
161- if (!ei.check ()) {
162- PyErr_SetString (PyExc_TypeError, " indices must be integers" );
144+ PyErr_SetString (PyExc_TypeError, " Indices must be integers" );
163145 bp::throw_error_already_set ();
164146 }
165147 auto idx = normalize_index (c.get ().size (), ei ());
@@ -172,7 +154,7 @@ struct overload_base_get_item_for_std_vector
172154 long idx = i;
173155 if (idx < 0 ) idx += static_cast <long >(n);
174156 if (idx < 0 || idx >= static_cast <long >(n)) {
175- PyErr_SetString (PyExc_IndexError, " index out of range" );
157+ PyErr_SetString (PyExc_IndexError, " Index out of range" );
176158 bp::throw_error_already_set ();
177159 }
178160 return static_cast <index_type>(idx);
@@ -225,7 +207,7 @@ struct extract_to_eigen_ref
225207 extract_to_eigen_ref (api::object const &o) : base(o.ptr()) {}
226208};
227209
228- // / \brief Specialization of the boost::python ::extract struct for references to
210+ // / \brief Specialization of the bp ::extract struct for references to
229211// / Eigen matrix objects.
230212template <typename Scalar, int Rows, int Cols, int Options, int MaxRows,
231213 int MaxCols>
@@ -366,9 +348,8 @@ struct StdContainerFromPythonList {
366348
367349 // / \brief Allocate the std::vector and fill it with the element contained in
368350 // / the list
369- static void construct (
370- PyObject *obj_ptr,
371- boost::python::converter::rvalue_from_python_stage1_data *memory) {
351+ static void construct (PyObject *obj_ptr,
352+ bp::converter::rvalue_from_python_stage1_data *memory) {
372353 // Extract the list
373354 bp::object bp_obj (bp::handle<>(bp::borrowed (obj_ptr)));
374355 bp::list bp_list (bp_obj);
@@ -389,12 +370,11 @@ struct StdContainerFromPythonList {
389370 }
390371
391372 static void register_converter () {
392- ::boost::python:: converter::registry::push_back (
393- &convertible, &construct, ::boost::python ::type_id<vector_type>());
373+ bp:: converter::registry::push_back (&convertible, &construct,
374+ bp ::type_id<vector_type>());
394375 }
395376
396- static ::boost::python::list tolist (vector_type &self,
397- const bool deep_copy = false ) {
377+ static bp::list tolist (vector_type &self, const bool deep_copy = false ) {
398378 return details::build_list<vector_type, NoProxy>::run (self, deep_copy);
399379 }
400380};
@@ -428,7 +408,7 @@ struct contains_algo<T, false> {
428408
429409template <class Container , bool NoProxy>
430410struct contains_vector_derived_policies
431- : public ::boost::python ::vector_indexing_suite<
411+ : public bp ::vector_indexing_suite<
432412 Container, NoProxy,
433413 contains_vector_derived_policies<Container, NoProxy>> {
434414 typedef typename Container::value_type key_type;
@@ -445,7 +425,7 @@ struct contains_vector_derived_policies
445425// /
446426template <typename Container, bool NoProxy, typename CoVisitor>
447427struct ExposeStdMethodToStdVector
448- : public boost::python ::def_visitor<
428+ : public bp ::def_visitor<
449429 ExposeStdMethodToStdVector<Container, NoProxy, CoVisitor>> {
450430 typedef StdContainerFromPythonList<Container, NoProxy>
451431 FromPythonListConverter;
@@ -533,7 +513,7 @@ struct StdVectorPythonVisitor {
533513 cl.def (IdVisitor<vector_type>());
534514
535515 // Standard vector indexing definition
536- boost::python ::vector_indexing_suite<
516+ bp ::vector_indexing_suite<
537517 vector_type, NoProxy,
538518 internal::contains_vector_derived_policies<vector_type, NoProxy>>
539519 vector_indexing;
0 commit comments