|
| RCWeakPtr () noexcept |
| Construct a new RCWeakPtr<T>::RCWeakPtr object.
|
|
| RCWeakPtr (const Strong &p) noexcept |
| Construct a new RCWeakPtr<T>::RCWeakPtr object.
|
|
| RCWeakPtr (T *p) noexcept |
| Construct a new RCWeakPtr<T>::RCWeakPtr object.
|
|
void | reset (const Strong &p) noexcept |
| Reassign this weak ptr to the object referenced by the given strong (RCPtr) pointer.
|
|
void | reset (T *p) noexcept |
| Reassign this weak pointer to reference the controller within the specified object.
|
|
void | reset () noexcept |
| remove any existing reference
|
|
void | swap (RCWeakPtr &other) noexcept |
| Swaps thing pointed to by *this withthing pointed to by other.
|
|
olong | use_count () const noexcept |
| Returns count of references to the object.
|
|
bool | expired () const noexcept |
| Returns true if the underlying object is already freed.
|
|
Strong | lock () const noexcept |
| Tries to upgrade the weak reference to a strong reference and returns that result.
|
|
Strong | move_strong () noexcept |
| Try to move the weak pointer into a strong pointer.
|
|
template<typename T>
class openvpn::RCWeakPtr< T >
implements a weak pointer for reference counted objects.
- Template Parameters
-
RCWeakPtr takes a template parameter T which is the type of the object it will hold a weak pointer to. T must be a reference counted type. The purpose of RCWeakPtr is to hold a non-owning pointer to a reference counted object that can be converted to a strong owning pointer if the object still exists. It allows having a pointer to an object without affecting its reference count.
RCWeakPtr contains a member variable controller which holds a pointer to the reference count controller object of the T object it points to. This allows it to query the reference count and check if the object still exists.
The class provides methods to initialize the weak pointer from a strong pointer or raw pointer to a T object. This sets the controller to point to the T object's reference count controller.
It also provides methods to reset the pointer, check if it has expired (if the object was deleted), get a strong owning pointer via lock() if the object still exists, and get the reference count.
The key benefit of RCWeakPtr is being able to hold a non-owning pointer to a reference counted object without affecting its lifetime. It allows referencing the object without incrementing the reference count and can check if the object was deleted.
Definition at line 450 of file rc.hpp.