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


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04