eigenpy 3.12.0
Bindings between Numpy and Eigen using Boost.Python
Loading...
Searching...
No Matches
pickle-vector.hpp
1//
2// Copyright (c) 2019-2020 CNRS INRIA
3//
4
5#ifndef __eigenpy_utils_pickle_vector_hpp__
6#define __eigenpy_utils_pickle_vector_hpp__
7
8#include <boost/python.hpp>
9#include <boost/python/stl_iterator.hpp>
10#include <boost/python/tuple.hpp>
11
12namespace eigenpy {
18template <typename VecType>
19struct PickleVector : boost::python::pickle_suite {
20 static boost::python::tuple getinitargs(const VecType&) {
21 return boost::python::make_tuple();
22 }
23
24 static boost::python::tuple getstate(boost::python::object op) {
25 return boost::python::make_tuple(
26 boost::python::list(boost::python::extract<const VecType&>(op)()));
27 }
28
29 static void setstate(boost::python::object op, boost::python::tuple tup) {
30 if (boost::python::len(tup) > 0) {
31 VecType& o = boost::python::extract<VecType&>(op)();
32 boost::python::stl_input_iterator<typename VecType::value_type> begin(
33 tup[0]),
34 end;
35 while (begin != end) {
36 o.push_back(*begin);
37 ++begin;
38 }
39 }
40 }
41
42 static bool getstate_manages_dict() { return true; }
43};
44} // namespace eigenpy
45
46#endif // ifndef __eigenpy_utils_pickle_vector_hpp__
Create a pickle interface for the std::vector.