shared_ptr_to_python.hpp 949 B

12345678910111213141516171819202122232425262728
  1. // Copyright David Abrahams 2003.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef SHARED_PTR_TO_PYTHON_DWA2003224_HPP
  6. # define SHARED_PTR_TO_PYTHON_DWA2003224_HPP
  7. # include <boost/python/refcount.hpp>
  8. # include <boost/python/converter/shared_ptr_deleter.hpp>
  9. # include <boost/shared_ptr.hpp>
  10. # include <boost/get_pointer.hpp>
  11. namespace boost { namespace python { namespace converter {
  12. template <class T>
  13. PyObject* shared_ptr_to_python(shared_ptr<T> const& x)
  14. {
  15. if (!x)
  16. return python::detail::none();
  17. else if (shared_ptr_deleter* d = boost::get_deleter<shared_ptr_deleter>(x))
  18. return incref( get_pointer( d->owner ) );
  19. else
  20. return converter::registered<shared_ptr<T> const&>::converters.to_python(&x);
  21. }
  22. }}} // namespace boost::python::converter
  23. #endif // SHARED_PTR_TO_PYTHON_DWA2003224_HPP