1 // Copyright David Abrahams 2003. 2 // Copyright Stefan Seefeld 2016. 3 // Distributed under the Boost Software License, Version 1.0. (See 4 // accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef boost_python_converter_shared_ptr_to_python_hpp_ 8 #define boost_python_converter_shared_ptr_to_python_hpp_ 9 10 #include <boost/python/refcount.hpp> 11 #include <boost/python/converter/shared_ptr_deleter.hpp> 12 #include <boost/shared_ptr.hpp> 13 #include <boost/get_pointer.hpp> 14 15 namespace boost { namespace python { namespace converter { 16 17 template <class T> shared_ptr_to_python(shared_ptr<T> const & x)18 PyObject* shared_ptr_to_python(shared_ptr<T> const& x) 19 { 20 if (!x) 21 return python::detail::none(); 22 else if (shared_ptr_deleter* d = boost::get_deleter<shared_ptr_deleter>(x)) 23 return incref( get_pointer( d->owner ) ); 24 else 25 return converter::registered<shared_ptr<T> const&>::converters.to_python(&x); 26 } 27 28 #if !defined(BOOST_NO_CXX11_SMART_PTR) 29 template <class T> shared_ptr_to_python(std::shared_ptr<T> const & x)30 PyObject* shared_ptr_to_python(std::shared_ptr<T> const& x) 31 { 32 if (!x) 33 return python::detail::none(); 34 else if (shared_ptr_deleter* d = std::get_deleter<shared_ptr_deleter>(x)) 35 return incref(get_pointer(d->owner)); 36 else 37 return converter::registered<std::shared_ptr<T> const&>::converters.to_python(&x); 38 } 39 #endif 40 41 }}} // namespace boost::python::converter 42 43 #endif 44