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_TYPE_DWA2002720_HPP
6 # define PYOBJECT_TYPE_DWA2002720_HPP
8 # include <boost/python/cast.hpp>
10 namespace boost { namespace python { namespace converter {
12 BOOST_PYTHON_DECL inline
13 PyObject* checked_downcast_impl(PyObject *obj, PyTypeObject *type)
15 return (PyType_IsSubtype(Py_TYPE(obj), type) ? obj : NULL);
17 // Used as a base class for specializations which need to provide
18 // Python type checking capability.
19 template <class Object, PyTypeObject* pytype>
22 static bool check(PyObject* x)
24 return ::PyObject_IsInstance(x, (PyObject*)pytype);
27 static Object* checked_downcast(PyObject* x)
29 return python::downcast<Object>(
30 (checked_downcast_impl)(x, pytype)
33 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
34 static PyTypeObject const* get_pytype() { return pytype; }
38 }}} // namespace boost::python::converter
40 #endif // PYOBJECT_TYPE_DWA2002720_HPP