c++-gtk-utils
|
This is a smart pointer for managing objects allocated on freestore which maintain their own reference count. More...
#include <c++-gtk-utils/intrusive_ptr.h>
Public Member Functions | |
IntrusivePtr (T *ptr=0) | |
IntrusivePtr (const IntrusivePtr &intr_ptr) | |
IntrusivePtr (IntrusivePtr &&intr_ptr) noexcept | |
template<class U > | |
IntrusivePtr (const IntrusivePtr< U > &intr_ptr) | |
template<class U > | |
IntrusivePtr (IntrusivePtr< U > &&intr_ptr) noexcept | |
IntrusivePtr & | operator= (IntrusivePtr intr_ptr) |
template<class U > | |
IntrusivePtr & | operator= (const IntrusivePtr< U > &intr_ptr) |
template<class U > | |
IntrusivePtr & | operator= (IntrusivePtr< U > &&intr_ptr) |
T * | get () const noexcept |
T & | operator* () const noexcept |
T * | operator-> () const noexcept |
void | reset (T *ptr=0) |
~IntrusivePtr () | |
Friends | |
template<class U > | |
class | IntrusivePtr |
This is a smart pointer for managing objects allocated on freestore which maintain their own reference count.
This is a class which manages objects which maintain their own reference count. It requires that the referenced object has two functions called ref() and unref(), which increment and decrement the reference count respectively. The IntrusiveCounter or IntrusiveLockCounter class can be inherited from to do this, but they do not have to be used. The IntrusiveLockCounter class is the same as the IntrusiveCounter class, except that it locks the reference count when it is incremented or decremented in order that IntrusivePtr objects in different threads can access the same object. (But only the reference count is locked, not the methods of the referenced object.)
All the constructors (including the constructor which takes a raw pointer) increment the reference count, and the destructor decrements it and expects the referenced object to be deleted when the last IntrusivePtr referencing a particular object is destroyed. The IntrusiveCounter and IntrusiveLockCounter classes behave in this way. (This is different from the behaviour of GobjHandle smart pointers, which are constrained by the GObject reference counting system which begins with a reference count of 1 rather than 0, and of course different from normal shared pointer implementations for the same reason. The advantage of the approach with IntrusivePtr is that an already-managed object may safely be passed to the constructor taking a raw pointer without any additional steps being necessary.)
|
inlineexplicit |
This constructor does not throw unless the managed object's ref() function throws (which would not happen with any sane implementation, and does not happen with the IntrusiveCounter and IntrusiveLockCounter classes).
ptr | The object which the IntrusivePtr is to manage (if any). |
|
inline |
This copy constructor does not throw unless the managed object's ref() function throws (which would not happen with any sane implementation, and does not happen with the IntrusiveCounter and IntrusiveLockCounter classes).
intr_ptr | The intrusive pointer to be copied. |
|
inlinenoexcept |
The move constructor does not throw. It has move semantics.
intr_ptr | The instrusive pointer to be moved. |
|
inline |
A version of the copy constructor which enables pointer type conversion (assuming the type passed is implicitly type convertible to the managed type, such as a derived type). This copy constructor does not throw unless the managed object's ref() function throws (which would not happen with any sane implementation, and does not happen with the IntrusiveCounter and IntrusiveLockCounter classes).
intr_ptr | The intrusive pointer to be copied. |
|
inlinenoexcept |
A version of the move constructor which enables pointer type conversion (assuming the type passed is implicitly type convertible to the managed type, such as a derived type). This move constructor does not throw.
intr_ptr | The intrusive pointer to be moved. |
|
inline |
The destructor does not throw unless the destructor of a managed object throws - that should never happen.
|
inlinenoexcept |
This method does not throw.
|
inlinenoexcept |
This method does not throw.
|
inlinenoexcept |
This method does not throw.
|
inline |
A version of the assignment operator which enables pointer type conversion (assuming the type passed is implicitly type convertible to the managed type, such as a derived type). This method does not throw unless the unref() function or destructor of a managed object throws.
intr_ptr | The assignee. |
|
inline |
This method (and so copy or move assignment) does not throw unless the unref() function or destructor of a managed object throws.
intr_ptr | The assignee. |
|
inline |
A version of the operator for move assignment which enables pointer type conversion (assuming the type passed is implicitly type convertible to the managed type, such as a derived type). This method does not throw unless the unref() function or destructor of a managed object throws.
intr_ptr | The intrusive pointer to be moved. |
|
inline |
Causes the intrusive pointer to cease to manage its managed object, deleting it if this is the last intrusive pointer managing it. If the argument passed is not NULL, the intrusive pointer will manage the new object passed. This method does not throw unless the the unref() function or destructor of a managed object throws.
ptr | NULL (the default), or a new object to manage. |