Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | List of all members
handle Class Reference

#include <pytypes.h>

Inheritance diagram for handle:
Inheritance graph
[legend]

Public Member Functions

template<typename T >
T cast () const
 
template<>
void cast () const
 
bool check () const
 
const handledec_ref () const &
 
 handle ()=default
 The default constructor creates a handle with a nullptr-valued pointer. More...
 
template<typename T , detail::enable_if_t< detail::all_of< detail::none_of< std::is_base_of< handle, T >, detail::is_pyobj_ptr_or_nullptr_t< T >>, std::is_convertible< T, PyObject * >>::value, int > = 0>
 handle (T &obj)
 Enable implicit conversion through T::operator PyObject *(). More...
 
template<typename T , detail::enable_if_t< detail::is_pyobj_ptr_or_nullptr_t< T >::value, int > = 0>
 handle (T ptr)
 
const handleinc_ref () const &
 
 operator bool () const
 Return true when the handle wraps a valid Python object. More...
 
bool operator!= (const handle &h) const
 
bool operator== (const handle &h) const
 
PyObject *& ptr ()
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 

Static Public Member Functions

static std::size_t inc_ref_counter ()
 

Protected Attributes

PyObject * m_ptr = nullptr
 

Private Member Functions

void throw_gilstate_error (const std::string &function_name) const
 

Static Private Member Functions

static std::size_t inc_ref_counter (std::size_t add)
 

Detailed Description

\rst Holds a reference to a Python object (no reference counting)

The handle class is a thin wrapper around an arbitrary Python object (i.e. a PyObject * in Python's C API). It does not perform any automatic reference counting and merely provides a basic C++ interface to various Python API functions.

.. seealso:: The object class inherits from handle and adds automatic reference counting features. \endrst

Definition at line 226 of file pytypes.h.

Constructor & Destructor Documentation

◆ handle() [1/3]

handle::handle ( )
default

The default constructor creates a handle with a nullptr-valued pointer.

◆ handle() [2/3]

template<typename T , detail::enable_if_t< detail::is_pyobj_ptr_or_nullptr_t< T >::value, int > = 0>
handle::handle ( T  ptr)
inline

Enable implicit conversion from PyObject * and nullptr. Not using handle(PyObject *ptr) to avoid implicit conversion from 0.

Definition at line 236 of file pytypes.h.

◆ handle() [3/3]

template<typename T , detail::enable_if_t< detail::all_of< detail::none_of< std::is_base_of< handle, T >, detail::is_pyobj_ptr_or_nullptr_t< T >>, std::is_convertible< T, PyObject * >>::value, int > = 0>
handle::handle ( T obj)
inline

Enable implicit conversion through T::operator PyObject *().

Definition at line 247 of file pytypes.h.

Member Function Documentation

◆ cast() [1/2]

template<typename T >
T handle::cast

\rst Attempt to cast the Python object into the given C++ type. A cast_error will be throw upon failure. \endrst

Definition at line 1234 of file cast.h.

◆ cast() [2/2]

template<>
void handle::cast ( ) const
inline

Definition at line 1238 of file cast.h.

◆ check()

bool handle::check ( ) const
inline

Definition at line 303 of file pytypes.h.

◆ dec_ref()

const handle& handle::dec_ref ( ) const &
inline

\rst Manually decrease the reference count of the Python object. Usually, it is preferable to use the object class which derives from handle and calls this function automatically. Returns a reference to itself. \endrst

Definition at line 276 of file pytypes.h.

◆ inc_ref()

const handle& handle::inc_ref ( ) const &
inline

\rst Manually increase the reference count of the Python object. Usually, it is preferable to use the object class which derives from handle and calls this function automatically. Returns a reference to itself. \endrst

Definition at line 258 of file pytypes.h.

◆ inc_ref_counter() [1/2]

static std::size_t handle::inc_ref_counter ( )
inlinestatic

Definition at line 342 of file pytypes.h.

◆ inc_ref_counter() [2/2]

static std::size_t handle::inc_ref_counter ( std::size_t  add)
inlinestaticprivate

Definition at line 335 of file pytypes.h.

◆ operator bool()

handle::operator bool ( ) const
inlineexplicit

Return true when the handle wraps a valid Python object.

Definition at line 293 of file pytypes.h.

◆ operator!=()

bool handle::operator!= ( const handle h) const
inline

Definition at line 301 of file pytypes.h.

◆ operator==()

bool handle::operator== ( const handle h) const
inline

\rst Deprecated: Check that the underlying pointers are the same. Equivalent to obj1 is obj2 in Python. \endrst

Definition at line 299 of file pytypes.h.

◆ ptr() [1/2]

PyObject*& handle::ptr ( )
inline

Definition at line 251 of file pytypes.h.

◆ ptr() [2/2]

PyObject* handle::ptr ( ) const
inline

Return the underlying PyObject * pointer.

Definition at line 250 of file pytypes.h.

◆ throw_gilstate_error()

void handle::throw_gilstate_error ( const std::string &  function_name) const
inlineprivate

Definition at line 310 of file pytypes.h.

Member Data Documentation

◆ m_ptr

PyObject* handle::m_ptr = nullptr
protected

Definition at line 306 of file pytypes.h.


The documentation for this class was generated from the following files:


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:10:01