LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
lsst::cpputils::python::PySharedPtr< T > Class Template Referencefinal

A shared pointer that tracks both a C++ object and its associated PyObject. More...

#include <PySharedPtr.h>

Public Types

using element_type = T
 
using element_type = T
 

Public Member Functions

 PySharedPtr (T *const ptr)
 Create a pointer that counts as an extra reference in the Python environment.
 
 PySharedPtr (PySharedPtr const &) noexcept=default
 
 PySharedPtr (PySharedPtr &&) noexcept=default
 
PySharedPtroperator= (PySharedPtr const &) noexcept=default
 
PySharedPtroperator= (PySharedPtr &&) noexcept=default
 
 ~PySharedPtr () noexcept=default
 
 PySharedPtr (std::shared_ptr< T > r) noexcept
 
 operator std::shared_ptr< T > () noexcept
 
T * get () const noexcept
 
 PySharedPtr (T *const ptr)
 Create a pointer that counts as an extra reference in the Python environment.
 
 PySharedPtr (PySharedPtr const &) noexcept=default
 
 PySharedPtr (PySharedPtr &&) noexcept=default
 
PySharedPtroperator= (PySharedPtr const &) noexcept=default
 
PySharedPtroperator= (PySharedPtr &&) noexcept=default
 
 ~PySharedPtr () noexcept=default
 
 PySharedPtr (std::shared_ptr< T > r) noexcept
 
 operator std::shared_ptr< T > () noexcept
 
T * get () const noexcept
 

Detailed Description

template<typename T>
class lsst::cpputils::python::PySharedPtr< T >

A shared pointer that tracks both a C++ object and its associated PyObject.

Each group of PySharedPtr for a given object collectively counts as one reference to that object for the purpose of Python garbage collection.

A PySharedPtr is implicitly convertible to and from a std::shared_ptr to minimize API impact. Any shared_ptr created this way will (I think) keep the Python reference alive, as described above.

Definition at line 49 of file PySharedPtr.h.

Member Typedef Documentation

◆ element_type [1/2]

template<typename T >
using lsst::cpputils::python::PySharedPtr< T >::element_type = T

Definition at line 51 of file PySharedPtr.h.

◆ element_type [2/2]

template<typename T >
using lsst::cpputils::python::PySharedPtr< T >::element_type = T

Definition at line 51 of file PySharedPtr.h.

Constructor & Destructor Documentation

◆ PySharedPtr() [1/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( T *const ptr)
inlineexplicit

Create a pointer that counts as an extra reference in the Python environment.

Parameters
ptra pointer to a pybind11-managed object.

Definition at line 59 of file PySharedPtr.h.

59 : _impl() {
60 if (ptr != nullptr) {
61 // `cast` returns new PyObject only if `*ptr` not yet associated with one
62 PyObject* pyObj = pybind11::cast(ptr).ptr();
63 Py_INCREF(pyObj);
64 // if any operation with shared_ptr fails, pyObj will get decremented correctly
65 std::shared_ptr<PyObject> manager(pyObj, [](PyObject* const obj) noexcept {
66 if (obj != nullptr) Py_DECREF(obj);
67 });
68 _impl = std::shared_ptr<T>(manager, ptr);
69 }
70 }
uint64_t * ptr
Definition RangeSet.cc:95

◆ PySharedPtr() [2/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( PySharedPtr< T > const & )
defaultnoexcept

◆ PySharedPtr() [3/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( PySharedPtr< T > && )
defaultnoexcept

◆ ~PySharedPtr() [1/2]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::~PySharedPtr ( )
defaultnoexcept

◆ PySharedPtr() [4/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( std::shared_ptr< T > r)
inlinenoexcept

Definition at line 78 of file PySharedPtr.h.

78: _impl(std::move(r)) {}
T move(T... args)

◆ PySharedPtr() [5/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( T *const ptr)
inlineexplicit

Create a pointer that counts as an extra reference in the Python environment.

Parameters
ptra pointer to a pybind11-managed object.

Definition at line 59 of file PySharedPtr.h.

59 : _impl() {
60 if (ptr != nullptr) {
61 // `cast` returns new PyObject only if `*ptr` not yet associated with one
62 PyObject* pyObj = pybind11::cast(ptr).ptr();
63 Py_INCREF(pyObj);
64 // if any operation with shared_ptr fails, pyObj will get decremented correctly
65 std::shared_ptr<PyObject> manager(pyObj, [](PyObject* const obj) noexcept {
66 if (obj != nullptr) Py_DECREF(obj);
67 });
68 _impl = std::shared_ptr<T>(manager, ptr);
69 }
70 }

◆ PySharedPtr() [6/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( PySharedPtr< T > const & )
defaultnoexcept

◆ PySharedPtr() [7/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( PySharedPtr< T > && )
defaultnoexcept

◆ ~PySharedPtr() [2/2]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::~PySharedPtr ( )
defaultnoexcept

◆ PySharedPtr() [8/8]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::PySharedPtr ( std::shared_ptr< T > r)
inlinenoexcept

Definition at line 78 of file PySharedPtr.h.

78: _impl(std::move(r)) {}

Member Function Documentation

◆ get() [1/2]

template<typename T >
T * lsst::cpputils::python::PySharedPtr< T >::get ( ) const
inlinenoexcept

Definition at line 81 of file PySharedPtr.h.

81{ return _impl.get(); }

◆ get() [2/2]

template<typename T >
T * lsst::cpputils::python::PySharedPtr< T >::get ( ) const
inlinenoexcept

Definition at line 81 of file PySharedPtr.h.

81{ return _impl.get(); }

◆ operator std::shared_ptr< T >() [1/2]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::operator std::shared_ptr< T > ( )
inlinenoexcept

Definition at line 79 of file PySharedPtr.h.

79{ return _impl; }

◆ operator std::shared_ptr< T >() [2/2]

template<typename T >
lsst::cpputils::python::PySharedPtr< T >::operator std::shared_ptr< T > ( )
inlinenoexcept

Definition at line 79 of file PySharedPtr.h.

79{ return _impl; }

◆ operator=() [1/4]

template<typename T >
PySharedPtr & lsst::cpputils::python::PySharedPtr< T >::operator= ( PySharedPtr< T > && )
defaultnoexcept

◆ operator=() [2/4]

template<typename T >
PySharedPtr & lsst::cpputils::python::PySharedPtr< T >::operator= ( PySharedPtr< T > && )
defaultnoexcept

◆ operator=() [3/4]

template<typename T >
PySharedPtr & lsst::cpputils::python::PySharedPtr< T >::operator= ( PySharedPtr< T > const & )
defaultnoexcept

◆ operator=() [4/4]

template<typename T >
PySharedPtr & lsst::cpputils::python::PySharedPtr< T >::operator= ( PySharedPtr< T > const & )
defaultnoexcept

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