5 #ifndef __eigenpy_utils_std_array_hpp__
6 #define __eigenpy_utils_std_array_hpp__
8 #include <boost/python/suite/indexing/indexing_suite.hpp>
15 template <
typename Container,
bool NoProxy,
class SliceAllocator,
16 class DerivedPolicies>
20 template <
typename Container,
bool NoProxy,
class SliceAllocator>
23 Container, NoProxy, SliceAllocator,
24 final_array_derived_policies<Container, NoProxy, SliceAllocator> > {};
27 template <
typename Container,
bool NoProxy =
false,
28 class SliceAllocator = std::allocator<typename Container::value_type>,
30 Container, NoProxy, SliceAllocator> >
32 :
public bp::vector_indexing_suite<Container, NoProxy, DerivedPolicies> {
35 typedef typename Container::value_type
key_type;
40 static constexpr std::size_t
Size = std::tuple_size<Container>{};
42 template <
class Class>
47 PyErr_SetString(PyExc_NotImplementedError,
48 "Cannot delete item from std::array type.");
49 bp::throw_error_already_set();
54 PyErr_SetString(PyExc_NotImplementedError,
55 "Cannot delete slice from std::array type.");
56 bp::throw_error_already_set();
62 PyErr_SetString(PyExc_NotImplementedError,
63 "Setting this slice would insert into an std::array, "
64 "which is not supported.");
65 bp::throw_error_already_set();
67 std::fill(container.begin() + from, container.begin() + to,
v);
73 Iter first, Iter last) {
75 PyErr_SetString(PyExc_NotImplementedError,
76 "Setting this slice would insert into an std::array, "
77 "which is not supported.");
78 bp::throw_error_already_set();
80 if (
long(to - from) == std::distance(first, last)) {
81 std::copy(first, last, container.begin() + from);
83 PyErr_SetString(PyExc_NotImplementedError,
84 "Size of std::array slice and size of right-hand side "
85 "iterator are incompatible.");
86 bp::throw_error_already_set();
95 for (
size_t i = from; i < to; i++) {
96 out.push_back(container[i]);
98 return bp::object(std::move(out));
109 template <
typename array_type,
bool NoProxy =
false,
110 class SliceAllocator =
111 std::allocator<typename array_type::value_type> >
115 static ::boost::python::list
tolist(array_type &
self,
const bool deep_copy) {
119 static void expose(
const std::string &class_name,
120 const std::string &doc_string =
"") {
124 template <
typename DerivedVisitor>
125 static void expose(
const std::string &class_name,
126 const bp::def_visitor<DerivedVisitor> &visitor) {
127 expose(class_name,
"", visitor);
130 template <
typename DerivedVisitor>
131 static void expose(
const std::string &class_name,
132 const std::string &doc_string,
133 const bp::def_visitor<DerivedVisitor> &visitor) {
134 if (!register_symbolic_link_to_registered_type<array_type>()) {
135 bp::class_<array_type> cl(class_name.c_str(), doc_string.c_str());
136 cl.def(bp::init<const array_type &>(bp::args(
"self",
"other"),
137 "Copy constructor"));
141 cl.def(indexing_suite)
144 (bp::arg(
"self"), bp::arg(
"deep_copy") =
false),
145 "Returns the std::array as a Python list.");
151 template <
typename MatrixType, std::
size_t Size>
153 std::ostringstream oss;
155 oss << Size <<
"_" <<
name;
156 typedef std::array<MatrixType, Size> array_type;
158 Eigen::aligned_allocator<MatrixType> >
::
165 #endif // ifndef __eigenpy_utils_std_array_hpp__