1
1
// /
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
4
4
// / This file was taken from Pinocchio (header
5
5
// / <pinocchio/bindings/python/utils/std-vector.hpp>)
6
6
// /
@@ -53,7 +53,7 @@ bool from_python_list(PyObject *obj_ptr, T *) {
53
53
54
54
template <typename vector_type, bool NoProxy>
55
55
struct 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) {
57
57
if (deep_copy) return build_list<vector_type, true >::run (vec, true );
58
58
59
59
bp::list bp_list;
@@ -66,7 +66,7 @@ struct build_list {
66
66
67
67
template <typename vector_type>
68
68
struct 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 ) {
70
70
typedef bp::iterator<vector_type> iterator;
71
71
return bp::list (iterator ()(vec));
72
72
}
@@ -77,8 +77,7 @@ struct build_list<vector_type, true> {
77
77
// / them.
78
78
template <typename Container>
79
79
struct 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>> {
82
81
typedef typename Container::value_type value_type;
83
82
typedef typename Container::value_type data_type;
84
83
typedef size_t index_type;
@@ -87,13 +86,13 @@ struct overload_base_get_item_for_std_vector
87
86
void visit (Class &cl) const {
88
87
cl.def (" __getitem__" , &base_get_item_int)
89
88
.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> );
92
91
}
93
92
94
93
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_) {
97
96
index_type idx = convert_index (container.get (), i_);
98
97
typename Container::iterator i = container.get ().begin ();
99
98
std::advance (i, idx);
@@ -108,9 +107,8 @@ struct overload_base_get_item_for_std_vector
108
107
return bp::object (bp::handle<>(convert (*i)));
109
108
}
110
109
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) {
114
112
bp::list out;
115
113
try {
116
114
auto rng =
@@ -134,32 +132,16 @@ struct overload_base_get_item_for_std_vector
134
132
return out;
135
133
}
136
134
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) {
139
138
const Py_ssize_t m = bp::len (idxs);
140
139
bp::list out;
141
140
for (Py_ssize_t k = 0 ; k < m; ++k) {
142
141
bp::object obj = idxs[k];
143
142
bp::extract<long > ei (obj);
144
143
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" );
163
145
bp::throw_error_already_set ();
164
146
}
165
147
auto idx = normalize_index (c.get ().size (), ei ());
@@ -172,7 +154,7 @@ struct overload_base_get_item_for_std_vector
172
154
long idx = i;
173
155
if (idx < 0 ) idx += static_cast <long >(n);
174
156
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" );
176
158
bp::throw_error_already_set ();
177
159
}
178
160
return static_cast <index_type>(idx);
@@ -225,7 +207,7 @@ struct extract_to_eigen_ref
225
207
extract_to_eigen_ref (api::object const &o) : base(o.ptr()) {}
226
208
};
227
209
228
- // / \brief Specialization of the boost::python ::extract struct for references to
210
+ // / \brief Specialization of the bp ::extract struct for references to
229
211
// / Eigen matrix objects.
230
212
template <typename Scalar, int Rows, int Cols, int Options, int MaxRows,
231
213
int MaxCols>
@@ -366,9 +348,8 @@ struct StdContainerFromPythonList {
366
348
367
349
// / \brief Allocate the std::vector and fill it with the element contained in
368
350
// / 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) {
372
353
// Extract the list
373
354
bp::object bp_obj (bp::handle<>(bp::borrowed (obj_ptr)));
374
355
bp::list bp_list (bp_obj);
@@ -389,12 +370,11 @@ struct StdContainerFromPythonList {
389
370
}
390
371
391
372
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>());
394
375
}
395
376
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 ) {
398
378
return details::build_list<vector_type, NoProxy>::run (self, deep_copy);
399
379
}
400
380
};
@@ -428,7 +408,7 @@ struct contains_algo<T, false> {
428
408
429
409
template <class Container , bool NoProxy>
430
410
struct contains_vector_derived_policies
431
- : public ::boost::python ::vector_indexing_suite<
411
+ : public bp ::vector_indexing_suite<
432
412
Container, NoProxy,
433
413
contains_vector_derived_policies<Container, NoProxy>> {
434
414
typedef typename Container::value_type key_type;
@@ -445,7 +425,7 @@ struct contains_vector_derived_policies
445
425
// /
446
426
template <typename Container, bool NoProxy, typename CoVisitor>
447
427
struct ExposeStdMethodToStdVector
448
- : public boost::python ::def_visitor<
428
+ : public bp ::def_visitor<
449
429
ExposeStdMethodToStdVector<Container, NoProxy, CoVisitor>> {
450
430
typedef StdContainerFromPythonList<Container, NoProxy>
451
431
FromPythonListConverter;
@@ -533,7 +513,7 @@ struct StdVectorPythonVisitor {
533
513
cl.def (IdVisitor<vector_type>());
534
514
535
515
// Standard vector indexing definition
536
- boost::python ::vector_indexing_suite<
516
+ bp ::vector_indexing_suite<
537
517
vector_type, NoProxy,
538
518
internal::contains_vector_derived_policies<vector_type, NoProxy>>
539
519
vector_indexing;
0 commit comments