1 |
|
|
// |
2 |
|
|
// Copyright (c) 2016-2020 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#ifndef __pinocchio_python_utils_std_aligned_vector_hpp__ |
6 |
|
|
#define __pinocchio_python_utils_std_aligned_vector_hpp__ |
7 |
|
|
|
8 |
|
|
#include <boost/python.hpp> |
9 |
|
|
#include <boost/python/suite/indexing/vector_indexing_suite.hpp> |
10 |
|
|
#include <string> |
11 |
|
|
|
12 |
|
|
#include "pinocchio/container/aligned-vector.hpp" |
13 |
|
|
|
14 |
|
|
#include "pinocchio/bindings/python/utils/pickle-vector.hpp" |
15 |
|
|
#include "pinocchio/bindings/python/utils/std-vector.hpp" |
16 |
|
|
|
17 |
|
|
namespace pinocchio |
18 |
|
|
{ |
19 |
|
|
namespace python |
20 |
|
|
{ |
21 |
|
|
|
22 |
|
|
/// |
23 |
|
|
/// \brief Expose an container::aligned_vector from a type given as template argument. |
24 |
|
|
/// |
25 |
|
|
/// \tparam T Type to expose as container::aligned_vector<T>. |
26 |
|
|
/// \tparam EnableFromPythonListConverter Enables the conversion from a Python list to a container::aligned_vector<T>. |
27 |
|
|
/// |
28 |
|
|
/// \sa StdAlignedVectorPythonVisitor |
29 |
|
|
/// |
30 |
|
|
template<class T, bool NoProxy = false, bool EnableFromPythonListConverter = true> |
31 |
|
|
struct StdAlignedVectorPythonVisitor |
32 |
|
|
: public ::boost::python::vector_indexing_suite<typename container::aligned_vector<T>,NoProxy> |
33 |
|
|
, public StdContainerFromPythonList< container::aligned_vector<T> > |
34 |
|
|
{ |
35 |
|
|
typedef container::aligned_vector<T> vector_type; |
36 |
|
|
typedef StdContainerFromPythonList<vector_type> FromPythonListConverter; |
37 |
|
|
|
38 |
|
171 |
static ::boost::python::class_<vector_type> expose(const std::string & class_name, |
39 |
|
|
const std::string & doc_string = "") |
40 |
|
|
{ |
41 |
|
|
namespace bp = boost::python; |
42 |
|
|
|
43 |
|
171 |
bp::class_<vector_type> cl(class_name.c_str(),doc_string.c_str()); |
44 |
|
|
cl |
45 |
|
|
.def(StdAlignedVectorPythonVisitor()) |
46 |
✓✗ |
171 |
.def("tolist",&FromPythonListConverter::tolist,bp::arg("self"), |
47 |
|
|
"Returns the aligned_vector as a Python list.") |
48 |
✓✗✓✗ ✓✗ |
171 |
.def_pickle(PickleVector<vector_type>()); |
49 |
|
|
|
50 |
|
|
// Register conversion |
51 |
|
|
if(EnableFromPythonListConverter) |
52 |
✓✗ |
171 |
FromPythonListConverter::register_converter(); |
53 |
|
|
|
54 |
|
171 |
return cl; |
55 |
|
|
} |
56 |
|
|
}; |
57 |
|
|
} // namespace python |
58 |
|
|
} // namespace pinocchio |
59 |
|
|
|
60 |
|
|
#endif // ifndef __pinocchio_python_utils_std_aligned_vector_hpp__ |