.. _program_listing_file__tmp_ws_src_eigenpy_include_eigenpy_std-unique-ptr.hpp: Program Listing for File std-unique-ptr.hpp =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/eigenpy/include/eigenpy/std-unique-ptr.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Copyright (c) 2024 INRIA // #ifndef __eigenpy_utils_std_unique_ptr_hpp__ #define __eigenpy_utils_std_unique_ptr_hpp__ #include "eigenpy/fwd.hpp" #include "eigenpy/utils/traits.hpp" #include "eigenpy/utils/python-compat.hpp" #include #include #include namespace eigenpy { namespace details { template typename std::enable_if::value, PyObject*>::type unique_ptr_to_python(std::unique_ptr&& x) { typedef bp::objects::pointer_holder, T> holder_t; if (!x) { return bp::detail::none(); } else { return bp::objects::make_ptr_instance::execute(x); } } template typename std::enable_if::value, PyObject*>::type unique_ptr_to_python(std::unique_ptr&& x) { if (!x) { return bp::detail::none(); } else { return bp::to_python_value()(*x); } } template typename std::enable_if::value, PyObject*>::type internal_unique_ptr_to_python(std::unique_ptr& x) { if (!x) { return bp::detail::none(); } else { return bp::detail::make_reference_holder::execute(x.get()); } } template typename std::enable_if::value, PyObject*>::type internal_unique_ptr_to_python(std::unique_ptr& x) { if (!x) { return bp::detail::none(); } else { return bp::to_python_value()(*x); } } struct StdUniquePtrResultConverter { template struct apply { struct type { typedef typename T::element_type element_type; PyObject* operator()(T&& x) const { return unique_ptr_to_python(std::forward(x)); } #ifndef BOOST_PYTHON_NO_PY_SIGNATURES PyTypeObject const* get_pytype() const { return bp::to_python_value().get_pytype(); } #endif }; }; }; struct InternalStdUniquePtrConverter { template struct apply { struct type { typedef typename remove_cvref::type::element_type element_type; PyObject* operator()(T x) const { return internal_unique_ptr_to_python(x); } #ifndef BOOST_PYTHON_NO_PY_SIGNATURES PyTypeObject const* get_pytype() const { return bp::to_python_value().get_pytype(); } #endif }; }; }; } // namespace details struct StdUniquePtrCallPolicies : bp::default_call_policies { typedef details::StdUniquePtrResultConverter result_converter; }; struct ReturnInternalStdUniquePtr : bp::return_internal_reference<> { typedef details::InternalStdUniquePtrConverter result_converter; template static PyObject* postcall(ArgumentPackage const& args_, PyObject* result) { // Don't run return_internal_reference postcall on primitive type if (PyInt_Check(result) || PyBool_Check(result) || PyFloat_Check(result) || PyStr_Check(result) || PyComplex_Check(result)) { return result; } return bp::return_internal_reference<>::postcall(args_, result); } }; } // namespace eigenpy namespace boost { namespace python { template struct to_python_value&> : eigenpy::details::StdUniquePtrResultConverter::apply< std::unique_ptr >::type {}; } // namespace python } // namespace boost #endif // ifndef __eigenpy_utils_std_unique_ptr_hpp__