pytype_object_mgr_traits.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright David Abrahams 2002.
  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 PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
  6. # define PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/detail/raw_pyobject.hpp>
  9. # include <boost/python/cast.hpp>
  10. # include <boost/python/converter/pyobject_type.hpp>
  11. # include <boost/python/errors.hpp>
  12. namespace boost { namespace python { namespace converter {
  13. // Provide a forward declaration as a convenience for clients, who all
  14. // need it.
  15. template <class T> struct object_manager_traits;
  16. // Derive specializations of object_manager_traits from this class
  17. // when T is an object manager for a particular Python type hierarchy.
  18. //
  19. template <PyTypeObject* pytype, class T>
  20. struct pytype_object_manager_traits
  21. : pyobject_type<T, pytype> // provides check()
  22. {
  23. BOOST_STATIC_CONSTANT(bool, is_specialized = true);
  24. static inline python::detail::new_reference adopt(PyObject*);
  25. };
  26. //
  27. // implementations
  28. //
  29. template <PyTypeObject* pytype, class T>
  30. inline python::detail::new_reference pytype_object_manager_traits<pytype,T>::adopt(PyObject* x)
  31. {
  32. return python::detail::new_reference(python::pytype_check(pytype, x));
  33. }
  34. }}} // namespace boost::python::converter
  35. #endif // PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP