cppyabm  1.0.17
An agent-based library to integrate C++ and Python
Public Member Functions | Protected Attributes | List of all members
handle Class Reference

#include <pytypes.h>

Inheritance diagram for handle:
args_proxy kwargs_proxy object bool_ buffer bytes capsule conftest.Capture conftest.Output conftest.SanitizedString dict dtype ellipsis exception< type > float_ function generic_type int_ iterable iterator list memoryview module_ none pybind11.setup_helpers.ParallelCompile sequence set slice staticmethod str tuple type weakref

Public Member Functions

 handle ()=default
 The default constructor creates a handle with a nullptr-valued pointer. More...
 
 handle (PyObject *ptr)
 Creates a handle from the given raw Python object pointer. More...
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 
PyObject *& ptr ()
 
const handleinc_ref () const &
 
const handledec_ref () const &
 
template<typename T >
cast () 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
 
bool check () const
 
template<>
void cast () const
 

Protected Attributes

PyObject * m_ptr = nullptr
 

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 176 of file pytypes.h.

Constructor & Destructor Documentation

◆ handle() [1/2]

handle::handle ( )
default

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

◆ handle() [2/2]

handle::handle ( PyObject *  ptr)
inline

Creates a handle from the given raw Python object pointer.

Definition at line 181 of file pytypes.h.

Member Function Documentation

◆ cast() [1/2]

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

Definition at line 1795 of file cast.h.

◆ cast() [2/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 1794 of file cast.h.

◆ check()

bool handle::check ( ) const
inline

Definition at line 217 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 199 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 192 of file pytypes.h.

◆ operator bool()

handle::operator bool ( ) const
inlineexplicit

Return true when the handle wraps a valid Python object.

Definition at line 207 of file pytypes.h.

◆ operator!=()

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

Definition at line 215 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 213 of file pytypes.h.

◆ ptr() [1/2]

PyObject*& handle::ptr ( )
inline

Definition at line 185 of file pytypes.h.

◆ ptr() [2/2]

PyObject* handle::ptr ( ) const
inline

Return the underlying PyObject * pointer.

Definition at line 184 of file pytypes.h.

Member Data Documentation

◆ m_ptr

PyObject* handle::m_ptr = nullptr
protected

Definition at line 219 of file pytypes.h.


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