class_wrapper.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright David Abrahams 2001.
  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 CLASS_WRAPPER_DWA20011221_HPP
  6. # define CLASS_WRAPPER_DWA20011221_HPP
  7. # include <boost/python/to_python_converter.hpp>
  8. #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
  9. # include <boost/python/converter/pytype_function.hpp>
  10. #endif
  11. # include <boost/ref.hpp>
  12. namespace boost { namespace python { namespace objects {
  13. //
  14. // These two classes adapt the static execute function of a class
  15. // MakeInstance execute() function returning a new PyObject*
  16. // reference. The first one is used for class copy constructors, and
  17. // the second one is used to handle smart pointers.
  18. //
  19. template <class Src, class MakeInstance>
  20. struct class_cref_wrapper
  21. : to_python_converter<Src,class_cref_wrapper<Src,MakeInstance> ,true>
  22. {
  23. static PyObject* convert(Src const& x)
  24. {
  25. return MakeInstance::execute(boost::ref(x));
  26. }
  27. #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
  28. static PyTypeObject const *get_pytype() { return converter::registered_pytype_direct<Src>::get_pytype(); }
  29. #endif
  30. };
  31. template <class Src, class MakeInstance>
  32. struct class_value_wrapper
  33. : to_python_converter<Src,class_value_wrapper<Src,MakeInstance> ,true>
  34. {
  35. static PyObject* convert(Src x)
  36. {
  37. return MakeInstance::execute(x);
  38. }
  39. #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
  40. static PyTypeObject const *get_pytype() { return MakeInstance::get_pytype(); }
  41. #endif
  42. };
  43. }}} // namespace boost::python::objects
  44. #endif // CLASS_WRAPPER_DWA20011221_HPP