pickle-vector.hpp
Go to the documentation of this file.
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 
12 namespace eigenpy {
18 template <typename VecType>
19 struct 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__
eigenpy::PickleVector
Create a pickle interface for the std::vector.
Definition: pickle-vector.hpp:19
eigenpy::PickleVector::getstate_manages_dict
static bool getstate_manages_dict()
Definition: pickle-vector.hpp:42
eigenpy
Definition: alignment.hpp:14
eigenpy::PickleVector::setstate
static void setstate(boost::python::object op, boost::python::tuple tup)
Definition: pickle-vector.hpp:29
eigenpy::PickleVector::getinitargs
static boost::python::tuple getinitargs(const VecType &)
Definition: pickle-vector.hpp:20
eigenpy::PickleVector::getstate
static boost::python::tuple getstate(boost::python::object op)
Definition: pickle-vector.hpp:24


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45