list.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019 INRIA
3 //
4 
5 #ifndef __pinocchio_python_utils_list_hpp__
6 #define __pinocchio_python_utils_list_hpp__
7 
10 
11 #include <eigenpy/exception.hpp>
12 
13 #include <boost/python.hpp>
14 #include <boost/python/type_id.hpp>
15 #include <vector>
16 #include <sstream>
17 #include <string>
18 
19 namespace pinocchio
20 {
21  namespace python
22  {
23 
24  template<typename T, class Allocator>
25  void extract(const boost::python::list & list, std::vector<T, Allocator> & vec)
26  {
27  namespace bp = boost::python;
28 
29  size_t size_list = (size_t)bp::len(list);
30  vec.resize(size_list);
31  for (size_t i = 0; i < size_list; ++i)
32  {
33  bp::extract<T> input_T(list[i]);
34  if (input_T.check())
35  vec[i] = input_T();
36  else
37  {
38  const std::string classname =
39  bp::extract<std::string>(list[i].attr("__class__").attr("__name__"));
40  std::stringstream ss;
41  ss << "The conversion from " << classname << " to " << bp::type_id<T>().name()
42  << " has failed." << std::endl;
43  throw eigenpy::Exception(ss.str());
44  }
45  }
46  }
47 
48  template<typename T>
49  std::vector<T, std::allocator<T>> extract(const boost::python::list & list)
50  {
51  std::vector<T, std::allocator<T>> vec;
52  extract(list, vec);
53  return vec;
54  }
55 
56  template<typename T, class Allocator>
57  std::vector<T, Allocator> extract(const boost::python::list & list)
58  {
59  std::vector<T, Allocator> vec;
60  extract(list, vec);
61  return vec;
62  }
63 
64  } // namespace python
65 } // namespace pinocchio
66 
67 #endif // ifndef __pinocchio_python_utils_list_hpp__
boost::python
path.hpp
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
exception.hpp
vec
vec
python
eigenpy::Exception
pinocchio::python::extract
void extract(const boost::python::list &list, std::vector< T, Allocator > &vec)
Definition: list.hpp:25
fwd.hpp
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:31