5#ifndef __eigenpy_utils_std_unique_ptr_hpp__ 6#define __eigenpy_utils_std_unique_ptr_hpp__ 8#include "eigenpy/fwd.hpp" 9#include "eigenpy/utils/traits.hpp" 10#include "eigenpy/utils/python-compat.hpp" 12#include <boost/python.hpp> 23typename std::enable_if<!is_python_primitive_type<T>::value, PyObject*>::type
24unique_ptr_to_python(std::unique_ptr<T>&& x) {
25 typedef bp::objects::pointer_holder<std::unique_ptr<T>, T> holder_t;
27 return bp::detail::none();
29 return bp::objects::make_ptr_instance<T, holder_t>::execute(x);
35typename std::enable_if<is_python_primitive_type<T>::value, PyObject*>::type
36unique_ptr_to_python(std::unique_ptr<T>&& x) {
38 return bp::detail::none();
40 return bp::to_python_value<const T&>()(*x);
47typename std::enable_if<!is_python_primitive_type<T>::value, PyObject*>::type
48internal_unique_ptr_to_python(std::unique_ptr<T>& x) {
50 return bp::detail::none();
52 return bp::detail::make_reference_holder::execute(x.get());
58typename std::enable_if<is_python_primitive_type<T>::value, PyObject*>::type
59internal_unique_ptr_to_python(std::unique_ptr<T>& x) {
61 return bp::detail::none();
63 return bp::to_python_value<const T&>()(*x);
72 typedef typename T::element_type element_type;
74 PyObject* operator()(T&& x)
const {
75 return unique_ptr_to_python(std::forward<T>(x));
77#ifndef BOOST_PYTHON_NO_PY_SIGNATURES 78 PyTypeObject
const* get_pytype()
const {
79 return bp::to_python_value<const element_type&>().get_pytype();
93 PyObject* operator()(T x)
const {
94 return internal_unique_ptr_to_python(x);
96#ifndef BOOST_PYTHON_NO_PY_SIGNATURES 97 PyTypeObject
const* get_pytype()
const {
98 return bp::to_python_value<const element_type&>().get_pytype();
120 template <
class ArgumentPackage>
121 static PyObject* postcall(ArgumentPackage
const& args_, PyObject* result) {
123 if (PyInt_Check(result) || PyBool_Check(result) || PyFloat_Check(result) ||
124 PyStr_Check(result) || PyComplex_Check(result)) {
127 return bp::return_internal_reference<>::postcall(args_, result);
138struct to_python_value<const std::unique_ptr<T>&>
140 std::unique_ptr<T>>::type {};
result_converter of ReturnInternalStdUniquePtr
result_converter of StdUniquePtrCallPolicies