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

Reference count base class for objects tracked by RCPtr. Allows copying and assignment. More...

#include <rc.hpp>

Public Member Functions

virtual ~RCCopyable ()=default
 
 RCCopyable () noexcept=default
 
 RCCopyable (const RCCopyable &) noexcept
 Construct a new RCCopyable object.
 
 RCCopyable (RCCopyable &&) noexcept
 Construct a new RCCopyable object by move.
 
RCCopyableoperator= (const RCCopyable &) noexcept
 Ensures the new ref count is not copied with the rest of the object.
 
RCCopyableoperator= (RCCopyable &&) noexcept
 Ensures the new ref count is not moved with the rest of the object.
 
olong use_count () const noexcept
 Returns the use count as reported by defering to the injected ref count type.
 

Private Attributes

RCImpl refcount_
 

Friends

template<typename R >
void intrusive_ptr_add_ref (R *rcptr) noexcept
 Helper to increment a ref count.
 
template<typename R >
void intrusive_ptr_release (R *rcptr) noexcept
 Helper to decrement a ref count.
 

Detailed Description

template<typename RCImpl>
class openvpn::RCCopyable< RCImpl >

Reference count base class for objects tracked by RCPtr. Allows copying and assignment.

Template Parameters
RCImplThe ref count implementation that will be used - thread_safe_refcount or thread_unsafe_refcount

Implements basic reference counting functionality for objects plus copy/assign.

The purpose of RCCopyable is to provide a base class that other classes can inherit from to enable reference counting and automatic memory management. It takes a template parameter RCImpl which specifies the actual reference count implementation class that will be used, either thread_safe_refcount or thread_unsafe_refcount.

RCCopyable provides a common base class for enabling reference counting on other classes via inheritance. It delegates the actual reference count tracking to the RCImpl implementation specified as a template parameter.

Since copy and assignment are allowed and this is a reference counted type, some atypical logic is implemented to make those operations work properly. This means that while the rest of the inheriting object will be copied as per usual, for this object we will give the copy a fresh reference count, since the count is bookkeeping metadata. The referencing pointers to the individual objects will then take care of properly maintaining the RC of the new and the donor object as per usual.

The member functions just delegate to the refcount_ object that's injected via template.

Definition at line 978 of file rc.hpp.

Constructor & Destructor Documentation

◆ ~RCCopyable()

template<typename RCImpl >
virtual openvpn::RCCopyable< RCImpl >::~RCCopyable ( )
virtualdefault

◆ RCCopyable() [1/3]

template<typename RCImpl >
openvpn::RCCopyable< RCImpl >::RCCopyable ( )
defaultnoexcept

◆ RCCopyable() [2/3]

template<typename RCImpl >
openvpn::RCCopyable< RCImpl >::RCCopyable ( const RCCopyable< RCImpl > &  )
noexcept

Construct a new RCCopyable object.

Template Parameters
RCImplRC compatible type to use as ref count

Copy/move construction/assignment are no-ops because we always want to default-construct the refcount from scratch. We never want to actually copy or move the refcount because that would break any referencing smart pointers.

We make a fresh object (by copy/move/assignment) and we want a new ref count.

Definition at line 1008 of file rc.hpp.

◆ RCCopyable() [3/3]

template<typename RCImpl >
openvpn::RCCopyable< RCImpl >::RCCopyable ( RCCopyable< RCImpl > &&  )
noexcept

Construct a new RCCopyable object by move.

Template Parameters
RCImplRC compatible type to use as ref count

Copy/move construction/assignment are no-ops because we always want to default-construct the refcount from scratch. We never want to actually copy or move the refcount because that would break any referencing smart pointers.

We make a fresh object (by copy/move/assignment) and we want a new ref count.

Definition at line 1020 of file rc.hpp.

Member Function Documentation

◆ operator=() [1/2]

template<typename RCImpl >
RCCopyable< RCImpl > & openvpn::RCCopyable< RCImpl >::operator= ( const RCCopyable< RCImpl > &  )
noexcept

Ensures the new ref count is not copied with the rest of the object.

Template Parameters
RCImpl
Returns
RCCopyable<RCImpl>&

Copy/move construction/assignment are no-ops because we always want to default-construct the refcount from scratch. We never want to actually copy or move the refcount because that would break any referencing smart pointers.

We make a fresh object (by copy/move/assignment) and we want a new ref count.

Definition at line 1033 of file rc.hpp.

◆ operator=() [2/2]

template<typename RCImpl >
RCCopyable< RCImpl > & openvpn::RCCopyable< RCImpl >::operator= ( RCCopyable< RCImpl > &&  )
noexcept

Ensures the new ref count is not moved with the rest of the object.

Template Parameters
RCImpl
Returns
RCCopyable<RCImpl>&

Copy/move construction/assignment are no-ops because we always want to default-construct the refcount from scratch. We never want to actually copy or move the refcount because that would break any referencing smart pointers.

We make a fresh object (by copy/move/assignment) and we want a new ref count.

Definition at line 1049 of file rc.hpp.

◆ use_count()

template<typename RCImpl >
olong openvpn::RCCopyable< RCImpl >::use_count ( ) const
noexcept

Returns the use count as reported by defering to the injected ref count type.

Template Parameters
RCImplthe injected ref count implementation
Returns
olong current ref count

Definition at line 1059 of file rc.hpp.

Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ intrusive_ptr_add_ref

template<typename RCImpl >
template<typename R >
void intrusive_ptr_add_ref ( R *  rcptr)
friend

Helper to increment a ref count.

Template Parameters
Rtype that has an incrementable member refcount_
Parameters
rcptrpointer to instance of R
Todo:
consider removing debug cout

Helper function template to implement incrementing of a member 'refcount_' of a type R; acts as an adapter layer to implement this funtionality as well as some conditionally built debug logging.

Definition at line 1400 of file rc.hpp.

◆ intrusive_ptr_release

template<typename RCImpl >
template<typename R >
void intrusive_ptr_release ( R *  rcptr)
friend

Helper to decrement a ref count.

Template Parameters
Rtype that has an decrementable member refcount_
Parameters
rcptrpointer to instance of R
Todo:
consider removing debug cout

Helper function template to implement decrementing of a member 'refcount_' of a type R; acts as an adapter layer to implement this funtionality as well as some conditionally built debug logging and a conditionally built notify hook.

Definition at line 1418 of file rc.hpp.

Member Data Documentation

◆ refcount_

template<typename RCImpl >
RCImpl openvpn::RCCopyable< RCImpl >::refcount_
private

Definition at line 994 of file rc.hpp.


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