![]() |
ROOT
6.06/09
Reference Guide
|
Several pointers point to the same object, any of them can delete the object, setting all of them to nullptr.
Once all TCoopPtr-s have been destructed, the pointed-to object is also destructed.
Internally, this is modelled as a shared_ptr<unique_ptr<T>>: all shared_ptr-s point to the same pointer (unique_ptr, actually), and a change to that pointer value is visible to all of them.
This is a PAW-style ownership management, useful if deletion needs to be an explicit action (unlike shared_ptr), but shared resource handling is required (like unique_ptr).
Example: TCoopPtr<TH1D> pHist(new TH1D({{10, 0., 1.}})); TCoopPtr<TCanvas> pad = gROOT.Create<TCanvas>(); pad->Draw(pHist); // histogram is drawn; the pad co-owns the histogram pHist.Delete(); // histogram vanishes from pad. Or the histogram could have been deleted on the pad, interactively.
Definition at line 46 of file TCoopPtr.h.
Public Types | |
| using | Pointee_t = std::remove_reference_t< POINTEE > |
| The type pointed to. More... | |
| using | Pointer_t = std::add_pointer_t< Pointee_t > |
| The primitive pointer type. More... | |
| using | SharedPtr_t = std::shared_ptr< void * > |
| The underlying std::shared_ptr. More... | |
Public Member Functions | |
| TCoopPtr ()=default | |
| TCoopPtr (const TCoopPtr &other)=default | |
Creates a synchronized TCoopPtr: once any of them call Delete(), all others will "contain" a nullptr. More... | |
| TCoopPtr (TCoopPtr &&other)=default | |
| TCoopPtr (Pointer_t ptr) | |
| Initialize from a raw pointer. More... | |
| template<class SELF = TCoopPtr, typename std::enable_if< std::is_move_constructible< typename SELF::Pointee_t >::value >::type * = nullptr> | |
| TCoopPtr (POINTEE &&obj) | |
| Create a TCoopPtr from an object. More... | |
| TCoopPtr (std::unique_ptr< POINTEE > &&ptr) | |
| Initialize from a unique_ptr; takes ownership. More... | |
| template<class DERIVED , typename std::enable_if< std::is_base_of< POINTEE, DERIVED >{}>::type * = nullptr> | |
| TCoopPtr (const TCoopPtr< DERIVED > &derived) | |
| Conversion from a pointer to derived to a pointer to base. More... | |
| Pointer_t | Get () const |
| Get the raw pointer. More... | |
| const SharedPtr_t & | GetShared () const |
| POINTEE * | Delete () const |
| Delete the object pointed to. More... | |
| Pointer_t | operator-> () const |
| Access the object pointed to. More... | |
| POINTEE & | operator* () const |
| Dereference the object pointed to. More... | |
| operator bool () const | |
Returns true if the pointer is non-null. More... | |
Private Attributes | |
| SharedPtr_t | fPtrBuf |
#include <ROOT/TCoopPtr.h>
Inheritance diagram for ROOT::TCoopPtr< POINTEE >:| using ROOT::TCoopPtr< POINTEE >::Pointee_t = std::remove_reference_t<POINTEE> |
The type pointed to.
Definition at line 49 of file TCoopPtr.h.
| using ROOT::TCoopPtr< POINTEE >::Pointer_t = std::add_pointer_t<Pointee_t> |
The primitive pointer type.
Definition at line 51 of file TCoopPtr.h.
| using ROOT::TCoopPtr< POINTEE >::SharedPtr_t = std::shared_ptr<void*> |
The underlying std::shared_ptr.
Definition at line 53 of file TCoopPtr.h.
|
default |
|
default |
|
default |
|
inline |
Initialize from a raw pointer.
Definition at line 63 of file TCoopPtr.h.
|
inline |
Create a TCoopPtr from an object.
Tries to invoke POINTEE's move constructor. Is only available if POINTEE is move constructable.
Definition at line 72 of file TCoopPtr.h.
|
inline |
Initialize from a unique_ptr; takes ownership.
Call as TCoopPtr p(std::move(uniquePtr));
Definition at line 79 of file TCoopPtr.h.
|
inline |
Conversion from a pointer to derived to a pointer to base.
Definition at line 85 of file TCoopPtr.h.
|
inline |
Delete the object pointed to.
Safe to be called mutiple times. All other synchronized TCoopPtr will be notified.
Definition at line 98 of file TCoopPtr.h.
|
inline |
Get the raw pointer.
Definition at line 90 of file TCoopPtr.h.
Referenced by ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::operator*(), ROOT::TFilePtr::operator->(), and ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::operator->().
|
inline |
Definition at line 94 of file TCoopPtr.h.
Referenced by ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::TCoopPtr().
|
inline |
Returns true if the pointer is non-null.
Definition at line 108 of file TCoopPtr.h.
|
inline |
Dereference the object pointed to.
Definition at line 106 of file TCoopPtr.h.
|
inline |
Access the object pointed to.
Definition at line 104 of file TCoopPtr.h.
|
private |
Definition at line 111 of file TCoopPtr.h.
Referenced by ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::Delete(), ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::Get(), ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::GetShared(), ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::operator bool(), and ROOT::TCoopPtr< ROOT::THist< DIMENSION, PRECISION > >::TCoopPtr().