Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:07:08

0001 // Copyright David Abrahams 2003.
0002 // Copyright Stefan Seefeld 2016.
0003 // Distributed under the Boost Software License, Version 1.0. (See
0004 // accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef boost_python_converter_shared_ptr_to_python_hpp_
0008 #define boost_python_converter_shared_ptr_to_python_hpp_
0009 
0010 #include <boost/python/refcount.hpp>
0011 #include <boost/python/converter/shared_ptr_deleter.hpp>
0012 #include <boost/shared_ptr.hpp>
0013 #include <boost/get_pointer.hpp>
0014 
0015 namespace boost { namespace python { namespace converter { 
0016 
0017 template <class T>
0018 PyObject* shared_ptr_to_python(shared_ptr<T> const& x)
0019 {
0020     if (!x)
0021         return python::detail::none();
0022     else if (shared_ptr_deleter* d = boost::get_deleter<shared_ptr_deleter>(x))
0023         return incref( get_pointer( d->owner ) );
0024     else
0025         return converter::registered<shared_ptr<T> const&>::converters.to_python(&x);
0026 }
0027 
0028 #if !defined(BOOST_NO_CXX11_SMART_PTR)
0029 template <class T>
0030 PyObject* shared_ptr_to_python(std::shared_ptr<T> const& x)
0031 {
0032   if (!x)
0033     return python::detail::none();
0034   else if (shared_ptr_deleter* d = std::get_deleter<shared_ptr_deleter>(x))
0035     return incref(get_pointer(d->owner));
0036   else
0037     return converter::registered<std::shared_ptr<T> const&>::converters.to_python(&x);
0038 }
0039 #endif
0040 
0041 }}} // namespace boost::python::converter
0042 
0043 #endif