numpy_object_mgr_traits.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright Jim Bosch 2010-2012.
  2. // Copyright Stefan Seefeld 2016.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef boost_python_numpy_numpy_object_mgr_traits_hpp_
  7. #define boost_python_numpy_numpy_object_mgr_traits_hpp_
  8. #include <boost/python/numpy/config.hpp>
  9. /**
  10. * @brief Macro that specializes object_manager_traits by requiring a
  11. * source-file implementation of get_pytype().
  12. */
  13. #define NUMPY_OBJECT_MANAGER_TRAITS(manager) \
  14. template <> \
  15. struct BOOST_NUMPY_DECL object_manager_traits<manager> \
  16. { \
  17. BOOST_STATIC_CONSTANT(bool, is_specialized = true); \
  18. static inline python::detail::new_reference adopt(PyObject* x) \
  19. { \
  20. return python::detail::new_reference(python::pytype_check((PyTypeObject*)get_pytype(), x)); \
  21. } \
  22. static bool check(PyObject* x) \
  23. { \
  24. return ::PyObject_IsInstance(x, (PyObject*)get_pytype()); \
  25. } \
  26. static manager* checked_downcast(PyObject* x) \
  27. { \
  28. return python::downcast<manager>((checked_downcast_impl)(x, (PyTypeObject*)get_pytype())); \
  29. } \
  30. static PyTypeObject const * get_pytype(); \
  31. }
  32. #endif