handle является умным указателем на тип объекта Python; он содержит указатель типа T*, где T является параметром шаблона. T должен быть либо типом, полученным из PyObject, либо типом POD, начальный sizeof(PyObject) байты компоновки совместимы с PyObject. Используйте handle<> на границе между API Python/'C' и высокоуровневым кодом; предпочтите объект для обобщенного интерфейса объектам Python.
В этом документе термин «upcast» относится к операции, которая преобразует указатель Y в базовый класс pointerT через static_cast<T>, если Y получен из T, или через каст в стиле C (T), если это не так. Однако в последнем случае «подкаст» плохо формируется, если начальный размер (PyObject) байты Y не совместимы с макетом PyObject.
namespace boost { namespace python
{
template <class T>
class handle
{
typedef unspecified-member-function-pointer bool_type;
public:
typedef T element_type;
public:
~handle();
template <class Y>
explicit handle(detail::borrowed<null_ok<Y> >* p);
template <class Y>
explicit handle(null_ok<detail::borrowed<Y> >* p);
template <class Y>
explicit handle(detail::borrowed<Y>* p);
template <class Y>
explicit handle(null_ok<Y>* p);
template <class Y>
explicit handle(Y* p);
handle();
handle& operator=(handle const& r);
template<typename Y>
handle& operator=(handle<Y> const & r);
template <typename Y>
handle(handle<Y> const& r);
handle(handle const& r);
T* operator-> () const;
T& operator* () const;
T* get() const;
void reset();
T* release();
operator bool_type() const;
private:
T* m_p;
};
template <class T> struct null_ok;
namespace detail { template <class T> struct borrowed; }
}}
virtual ~handle();
- Effects
Py_XDECREF(upcast<PyObject*>(m_p))
template <class Y>
explicit handle(detail::borrowed<null_ok<Y> >* p);
- Effects
Py_XINCREF(upcast<PyObject*>(p));
m_p = upcast<T*>(p);
template <class Y>
explicit handle(null_ok<detail::borrowed<Y> >* p);
- Effects
Py_XINCREF(upcast<PyObject*>(p));
m_p = upcast<T*>(p);
template <class Y>
explicit handle(detail::borrowed<Y>* p);
- Effects
Py_XINCREF(upcast<PyObject*>(p));
m_p = upcast<T*>(expect_non_null(p));
template <class Y>
explicit handle(null_ok<Y>* p);
- Effects
m_p =upcast<T*>(p);<17
template <class Y>
explicit handle(Y* p);
- Effects
m_pupcast<T*>(expect_non_null(p));
handle();
template <typename Y>
handle(handle<Y> const& r);
handle(handle const& r);
- Effects
m_p = r.m_p; Py_XINCREF(upcast(m_p);
handle& operator=(handle const& r);
template<typename Y>
handle& operator=(handle<Y> const & r);
- Effects
Py_XINCREF(PyObject*>(r);Py_XDECREF(upcast<PyObject>(m_p;
T* release();
void reset();
- Effects
*this=handle<T>();
T* operator-> () const;
T* get() const;
T& operator* () const;
operator bool_type() const;
- Returns
0 если m_p<2 == 0, указатель, конвертируемый в истинное в противном случае.