1 #ifndef __pinocchio_python_pybind11_hpp__ 2 #define __pinocchio_python_pybind11_hpp__ 37 #include <pinocchio/fwd.hpp> 40 #include <pybind11/pybind11.h> 42 #include <boost/python.hpp> 47 namespace py = pybind11;
50 inline py::object
to(
T&
t) {
52 bp::object obj = bp::api::object(t);
53 PyObject* pyobj = obj.ptr();
54 return pybind11::reinterpret_borrow<py::object>(pyobj);
57 inline py::object
to(
T*
t) {
60 PyObject* pyobj = converter(t);
62 return py::reinterpret_borrow<py::object>(pyobj);
65 template <
typename ReturnType>
67 return bp::extract<ReturnType&>(model.ptr());
74 static inline type
_from(type
t) {
return t; }
86 return to<
typename std::remove_pointer<
typename std::remove_reference<
97 #define PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(CLASS) \ 98 namespace pinocchio { \ 101 struct convert_type<CLASS> : convert_boost_python_object<CLASS> {}; \ 106 #define _SINGLE_ARG(...) __VA_ARGS__ 107 #define PINOCCHIO_PYBIND11_ADD_ALL_CONVERT_TYPE(CLASS) \ 108 PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(_SINGLE_ARG(CLASS)) \ 109 PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(_SINGLE_ARG(CLASS const)) \ 110 PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(_SINGLE_ARG(CLASS&)) \ 111 PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(_SINGLE_ARG(CLASS const&)) \ 112 PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(_SINGLE_ARG(CLASS*)) \ 113 PINOCCHIO_PYBIND11_ADD_CONVERT_TYPE(_SINGLE_ARG(CLASS const*)) 117 template <
typename R,
typename... Args>
121 template <
typename... Args>
126 template <
typename T>
129 template <
typename R,
typename... Args>
131 static const size_t nargs =
sizeof...(Args);
137 typedef typename std::tuple_element<
i, std::tuple<Args...>>::type
type;
140 typedef R (*func_type)(Args...);
146 return call(f, args...);
160 template <
typename R,
typename... Args>
162 R (*func)(Args...)) {
168 template <
typename T>
170 py::object obj = to<T>(
t);
182 #define PINOCCHIO_PYBIND11_TYPE_CASTER(native_type, boost_python_name) \ 183 namespace pybind11 { \ 186 struct type_caster<native_type> { \ 187 PYBIND11_TYPE_CASTER(_SINGLE_ARG(native_type), boost_python_name); \ 190 bool load(pybind11::handle src, bool) { \ 191 PyObject* source = src.ptr(); \ 192 value = boost::python::extract<native_type>(source); \ 193 return !PyErr_Occurred(); \ 196 static pybind11::handle cast(native_type src, \ 197 pybind11::return_value_policy , \ 198 pybind11::handle ) { \ 199 return boost::python::api::object(src).ptr(); \ 210 #endif // #ifndef __pinocchio_python_pybind11_hpp__
internal::function_wrapper< R(*)(Args...)> make_pybind11_function(R(*func)(Args...))
Creates a function wrapper.
static type _from(type t)
ReturnType & from(py::handle model)
std::tuple_element< i, std::tuple< Args... > >::type type
void call(void(*f)(Args...), typename convert_type< Args >::type... args)
auto operator()(typename convert_type< Args >::type... args)
py::object default_arg(T t)
Main pinocchio namespace.
JointCollectionTpl & model