OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::RCWeakPtr< T > Class Template Reference

implements a weak pointer for reference counted objects. More...

#include <rc.hpp>

Public Types

typedef T element_type
 

Public Member Functions

 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.
 

Private Types

typedef RCPtr< T > Strong
 

Private Attributes

T::Controller::Ptr controller
 Smart pointer to the T::ControllerF.
 

Detailed Description

template<typename T>
class openvpn::RCWeakPtr< T >

implements a weak pointer for reference counted objects.

Template Parameters
TRCWeak enabled type

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.

Member Typedef Documentation

◆ element_type

template<typename T >
typedef T openvpn::RCWeakPtr< T >::element_type

Definition at line 455 of file rc.hpp.

◆ Strong

template<typename T >
typedef RCPtr<T> openvpn::RCWeakPtr< T >::Strong
private

Definition at line 452 of file rc.hpp.

Constructor & Destructor Documentation

◆ RCWeakPtr() [1/3]

template<typename T >
openvpn::RCWeakPtr< T >::RCWeakPtr ( )
noexcept

Construct a new RCWeakPtr<T>::RCWeakPtr object.

Template Parameters
TRCWeak enabled type

Definition at line 479 of file rc.hpp.

◆ RCWeakPtr() [2/3]

template<typename T >
openvpn::RCWeakPtr< T >::RCWeakPtr ( const Strong p)
noexcept

Construct a new RCWeakPtr<T>::RCWeakPtr object.

Template Parameters
TRCWeak enabled type
Parameters
pRCPtr that holds a reference to an RCWeak::Controller

Definition at line 486 of file rc.hpp.

◆ RCWeakPtr() [3/3]

template<typename T >
openvpn::RCWeakPtr< T >::RCWeakPtr ( T *  p)
noexcept

Construct a new RCWeakPtr<T>::RCWeakPtr object.

Template Parameters
TRCWeak enabled type
Parameters
praw pointer to T

Definition at line 497 of file rc.hpp.

Member Function Documentation

◆ expired()

template<typename T >
bool openvpn::RCWeakPtr< T >::expired ( ) const
noexcept

Returns true if the underlying object is already freed.

Template Parameters
TRCWeak enabled type
Returns
true if the object has been freed.
false if the object still exists.

Definition at line 570 of file rc.hpp.

◆ lock()

template<typename T >
RCWeakPtr< T >::Strong openvpn::RCWeakPtr< T >::lock ( ) const
noexcept

Tries to upgrade the weak reference to a strong reference and returns that result.

Template Parameters
TRCWeak enabled type
Returns
RCWeakPtr<T>::Strong

If the underlying object has been freed, returns empty Strong ptr, otherwise returns a Strong referring to the object.

Definition at line 583 of file rc.hpp.

Here is the caller graph for this function:

◆ move_strong()

template<typename T >
RCWeakPtr< T >::Strong openvpn::RCWeakPtr< T >::move_strong ( )
noexcept

Try to move the weak pointer into a strong pointer.

Template Parameters
TRCWeak enabled type
Returns
RCWeakPtr<T>::Strong to the weakly referred to T or nullptr if the T is no longer available

Releases the weak reference and either takes and returns a strong reference if possible or nullptr if the lock cannot be accomplished.

Definition at line 599 of file rc.hpp.

◆ reset() [1/3]

template<typename T >
void openvpn::RCWeakPtr< T >::reset ( )
noexcept

remove any existing reference

Template Parameters
TRCWeak enabled type

Definition at line 533 of file rc.hpp.

◆ reset() [2/3]

template<typename T >
void openvpn::RCWeakPtr< T >::reset ( const Strong p)
noexcept

Reassign this weak ptr to the object referenced by the given strong (RCPtr) pointer.

Template Parameters
TRCWeak enabled type
Parameters
pStrong pointer to an RCWeak enabled object instance

Definition at line 508 of file rc.hpp.

Here is the caller graph for this function:

◆ reset() [3/3]

template<typename T >
void openvpn::RCWeakPtr< T >::reset ( T *  p)
noexcept

Reassign this weak pointer to reference the controller within the specified object.

Template Parameters
TRCWeak enabled type
Parameters
pan instance of an RCWeak enabled type

Definition at line 521 of file rc.hpp.

◆ swap()

template<typename T >
void openvpn::RCWeakPtr< T >::swap ( RCWeakPtr< T > &  other)
noexcept

Swaps thing pointed to by *this withthing pointed to by other.

Template Parameters
TRCWeak enabled type
Parameters
otherthe RCWeakPtr with which *this is to be swapped

Definition at line 543 of file rc.hpp.

Here is the caller graph for this function:

◆ use_count()

template<typename T >
olong openvpn::RCWeakPtr< T >::use_count ( ) const
noexcept

Returns count of references to the object.

Template Parameters
TRCWeak enabled type
Returns
olong ref count

If we point to a controller, we return the object use count for the object the controller refers to. Otherwise we return zero.

Definition at line 556 of file rc.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ controller

template<typename T >
T::Controller::Ptr openvpn::RCWeakPtr< T >::controller
private

Smart pointer to the T::ControllerF.

Definition at line 472 of file rc.hpp.


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