GEOSX
Public Member Functions | List of all members
LvArray::python::PyObjectRef< T > Class Template Reference

A class that manages an owned Python reference with RAII semantics. More...

#include <pythonHelpers.hpp>

Public Member Functions

 PyObjectRef ()=default
 Create an uninitialized (nullptr) reference.
 
 PyObjectRef (T *const src)
 Take ownership of a reference to src. More...
 
 PyObjectRef (PyObjectRef const &src)
 Create a new reference to src. More...
 
 PyObjectRef (PyObjectRef &&src)
 Steal a reference from src. More...
 
 ~PyObjectRef ()
 Destructor, decreases the reference count.
 
PyObjectRefoperator= (PyObjectRef const &src)
 Create a new reference to src. More...
 
PyObjectRefoperator= (PyObjectRef &&src)
 Steal a reference from src. More...
 
PyObjectRefoperator= (PyObject *src)
 Decrease the reference count to the current object and take ownership of a new reference. More...
 
 operator T* ()
 Conversion operator to a T *. More...
 
T * get () const
 Return a pointer to the managed object. More...
 
T ** getAddress ()
 Return the address of the pointer to the manged object. More...
 
T * release ()
 Return the address of the managed object and release ownership. More...
 

Detailed Description

template<typename T = PyObject>
class LvArray::python::PyObjectRef< T >

A class that manages an owned Python reference with RAII semantics.

Template Parameters
TThe type of the managed object, must be castable to a PyObject.

Definition at line 144 of file pythonHelpers.hpp.

Constructor & Destructor Documentation

◆ PyObjectRef() [1/3]

template<typename T = PyObject>
LvArray::python::PyObjectRef< T >::PyObjectRef ( T *const  src)
inline

Take ownership of a reference to src.

Parameters
srcThe object to be referenced.
Note
Does not increase the reference count.

Definition at line 158 of file pythonHelpers.hpp.

◆ PyObjectRef() [2/3]

template<typename T = PyObject>
LvArray::python::PyObjectRef< T >::PyObjectRef ( PyObjectRef< T > const &  src)
inline

Create a new reference to src.

Parameters
srcThe object to create a new reference to.
Note
Increases the reference count.

Definition at line 167 of file pythonHelpers.hpp.

◆ PyObjectRef() [3/3]

template<typename T = PyObject>
LvArray::python::PyObjectRef< T >::PyObjectRef ( PyObjectRef< T > &&  src)
inline

Steal a reference from src.

Parameters
srcThe object to steal a reference to.
Note
Does not increase the reference count.

Definition at line 175 of file pythonHelpers.hpp.

Member Function Documentation

◆ get()

template<typename T = PyObject>
T* LvArray::python::PyObjectRef< T >::get ( ) const
inline

Return a pointer to the managed object.

Returns
A pointer to the managed object.

Definition at line 235 of file pythonHelpers.hpp.

◆ getAddress()

template<typename T = PyObject>
T* * LvArray::python::PyObjectRef< T >::getAddress ( )
inline

Return the address of the pointer to the manged object.

Returns
The address of the pointer to the manged object.

Useful for functions which take a PyObject** as an output parameter and fill it with a new reference.

Definition at line 244 of file pythonHelpers.hpp.

◆ operator T*()

template<typename T = PyObject>
LvArray::python::PyObjectRef< T >::operator T* ( )
inline

Conversion operator to a T *.

Returns
A pointer to the managed object.

Definition at line 228 of file pythonHelpers.hpp.

◆ operator=() [1/3]

template<typename T = PyObject>
PyObjectRef& LvArray::python::PyObjectRef< T >::operator= ( PyObjectRef< T > const &  src)
inline

Create a new reference to src.

Parameters
srcThe object to create a new reference to.
Returns
*this.
Note
Increases the reference count.

Definition at line 190 of file pythonHelpers.hpp.

◆ operator=() [2/3]

template<typename T = PyObject>
PyObjectRef& LvArray::python::PyObjectRef< T >::operator= ( PyObjectRef< T > &&  src)
inline

Steal a reference from src.

Parameters
srcThe object to steal a reference to.
Returns
*this.
Note
Does not increase the reference count.

Definition at line 203 of file pythonHelpers.hpp.

◆ operator=() [3/3]

template<typename T = PyObject>
PyObjectRef& LvArray::python::PyObjectRef< T >::operator= ( PyObject *  src)
inline

Decrease the reference count to the current object and take ownership of a new reference.

Parameters
srcThe new object to be referenced.
Returns
*this.

Definition at line 216 of file pythonHelpers.hpp.

◆ release()

template<typename T = PyObject>
T* LvArray::python::PyObjectRef< T >::release ( )
inline

Return the address of the managed object and release ownership.

Returns
The address of the managed object and release ownership.

Useful for functions which return a PyObject *.

Definition at line 252 of file pythonHelpers.hpp.


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