return_opaque_pointer.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright Gottfried Ganßauge 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. /*
  6. * Generic Return value converter generator for opaque C++-pointers
  7. */
  8. # ifndef RETURN_OPAQUE_POINTER_HPP_
  9. # define RETURN_OPAQUE_POINTER_HPP_
  10. # include <boost/python/detail/prefix.hpp>
  11. # include <boost/python/opaque_pointer_converter.hpp>
  12. # include <boost/python/detail/force_instantiate.hpp>
  13. # include <boost/python/to_python_value.hpp>
  14. # include <boost/python/detail/value_arg.hpp>
  15. # include <boost/mpl/assert.hpp>
  16. namespace boost { namespace python {
  17. namespace detail
  18. {
  19. template <class Pointee>
  20. static void opaque_pointee(Pointee const volatile*)
  21. {
  22. force_instantiate(opaque<Pointee>::instance);
  23. }
  24. }
  25. struct return_opaque_pointer
  26. {
  27. template <class R>
  28. struct apply
  29. {
  30. BOOST_MPL_ASSERT_MSG( is_pointer<R>::value, RETURN_OPAQUE_POINTER_EXPECTS_A_POINTER_TYPE, (R));
  31. struct type :
  32. boost::python::to_python_value<
  33. typename detail::value_arg<R>::type
  34. >
  35. {
  36. type() { detail::opaque_pointee(R()); }
  37. };
  38. };
  39. };
  40. }} // namespace boost::python
  41. # endif // RETURN_OPAQUE_POINTER_HPP_