]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/python/converter/pyobject_type.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / python / converter / pyobject_type.hpp
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
7
8 # include <boost/python/cast.hpp>
9
10 namespace boost { namespace python { namespace converter {
11
12 BOOST_PYTHON_DECL inline
13 PyObject* checked_downcast_impl(PyObject *obj, PyTypeObject *type)
14 {
15 return (PyType_IsSubtype(Py_TYPE(obj), type) ? obj : NULL);
16 }
17 // Used as a base class for specializations which need to provide
18 // Python type checking capability.
19 template <class Object, PyTypeObject* pytype>
20 struct pyobject_type
21 {
22 static bool check(PyObject* x)
23 {
24 return ::PyObject_IsInstance(x, (PyObject*)pytype);
25 }
26
27 static Object* checked_downcast(PyObject* x)
28 {
29 return python::downcast<Object>(
30 (checked_downcast_impl)(x, pytype)
31 );
32 }
33 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
34 static PyTypeObject const* get_pytype() { return pytype; }
35 #endif
36 };
37
38 }}} // namespace boost::python::converter
39
40 #endif // PYOBJECT_TYPE_DWA2002720_HPP