Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0000d66e7c+4a51730b0a,g0485b4d2cb+be65c9c1d7,g0fba68d861+f95c35e0c3,g1ec0fe41b4+3ea9d11450,g1fd858c14a+41d169aaf2,g2440f9efcc+8c5ae1fdc5,g35bb328faa+8c5ae1fdc5,g4d2262a081+30937b6477,g53246c7159+8c5ae1fdc5,g55585698de+c657de43f9,g56a49b3a55+7eddd92ad8,g60b5630c4e+c657de43f9,g67b6fd64d1+97cc007aa2,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g7ac00fbb6c+9304e3655a,g8352419a5c+8c5ae1fdc5,g8852436030+3f3bba821f,g89139ef638+97cc007aa2,g94187f82dc+c657de43f9,g989de1cb63+97cc007aa2,g9d31334357+c657de43f9,g9f33ca652e+06d39d8afb,ga815be3f0b+8e7c4d07ad,gabe3b4be73+8856018cbb,gabf8522325+977d9fabaf,gb1101e3267+12c96a40b1,gb89ab40317+97cc007aa2,gc91f06edcd+2ffb87f22b,gcf25f946ba+3f3bba821f,gd6cbbdb0b4+1cc2750d2e,gde0f65d7ad+bbe98f05bf,ge278dab8ac+6b863515ed,ge410e46f29+97cc007aa2,gf35d7ec915+97dd712d81,gf5e32f922b+8c5ae1fdc5,gf67bdafdda+97cc007aa2,gf6800124b1+bb7d8e732a,w.2025.19
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
 

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
 

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

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/4]

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
64 // if any operation with shared_ptr fails, pyObj will get decremented correctly
66 if (obj != nullptr) Py_DECREF(obj);
67 });
69 }
70 }
A shared pointer that tracks both a C++ object and its associated PyObject.
Definition PySharedPtr.h:49

◆ PySharedPtr() [2/4]

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

◆ PySharedPtr() [3/4]

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

◆ ~PySharedPtr()

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

◆ PySharedPtr() [4/4]

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()

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 >()

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/2]

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

◆ operator=() [2/2]

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

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