Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:37

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef PYOBJECT_TYPE_DWA2002720_HPP
0006 # define PYOBJECT_TYPE_DWA2002720_HPP
0007 
0008 # include <boost/python/cast.hpp>
0009 
0010 namespace boost { namespace python { namespace converter { 
0011 
0012 BOOST_PYTHON_DECL inline
0013 PyObject* checked_downcast_impl(PyObject *obj, PyTypeObject *type)
0014 {
0015   return (PyType_IsSubtype(Py_TYPE(obj), type) ? obj : NULL);
0016 }
0017 // Used as a base class for specializations which need to provide
0018 // Python type checking capability.
0019 template <class Object, PyTypeObject* pytype>
0020 struct pyobject_type 
0021 {
0022     static bool check(PyObject* x)
0023     {
0024         return ::PyObject_IsInstance(x, (PyObject*)pytype);
0025     }
0026 
0027     static Object* checked_downcast(PyObject* x)
0028     {
0029         return python::downcast<Object>(
0030             (checked_downcast_impl)(x, pytype)
0031             );
0032     }
0033 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0034     static PyTypeObject const* get_pytype() { return pytype; }
0035 #endif
0036 };
0037 
0038 }}} // namespace boost::python::converter
0039 
0040 #endif // PYOBJECT_TYPE_DWA2002720_HPP