pyobject_traits.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 PYOBJECT_TRAITS_DWA2002720_HPP
  6. # define PYOBJECT_TRAITS_DWA2002720_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/converter/pyobject_type.hpp>
  9. namespace boost { namespace python { namespace converter {
  10. template <class> struct pyobject_traits;
  11. template <>
  12. struct pyobject_traits<PyObject>
  13. {
  14. // All objects are convertible to PyObject
  15. static bool check(PyObject*) { return true; }
  16. static PyObject* checked_downcast(PyObject* x) { return x; }
  17. #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
  18. static PyTypeObject const* get_pytype() { return 0; }
  19. #endif
  20. };
  21. //
  22. // Specializations
  23. //
  24. # define BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(T) \
  25. template <> struct pyobject_traits<Py##T##Object> \
  26. : pyobject_type<Py##T##Object, &Py##T##_Type> {}
  27. // This is not an exhaustive list; should be expanded.
  28. BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Type);
  29. BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(List);
  30. #if PY_VERSION_HEX < 0x03000000
  31. BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Int);
  32. #endif
  33. BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Long);
  34. BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Dict);
  35. BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Tuple);
  36. }}} // namespace boost::python::converter
  37. #endif // PYOBJECT_TRAITS_DWA2002720_HPP