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

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

#include <rc.hpp>

Inheritance diagram for openvpn::RC< RCImpl >:
[legend]

Public Types

typedef RCPtr< RCPtr
 

Public Member Functions

 RC () noexcept=default
 
virtual ~RC ()=default
 
 RC (const RC &)=delete
 
RCoperator= (const RC &)=delete
 
olong use_count () const noexcept
 Delegates call to RCImpl and returns the result.
 

Static Public Member Functions

static constexpr bool is_thread_safe ()
 Delegates call to RCImpl and returns the result.
 

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::RC< RCImpl >

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

Implements basic reference counting functionality for objects.

The purpose of RC 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.

RC 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. It also prohibits copy or assignment of the inheriting object.

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

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

Definition at line 911 of file rc.hpp.

Member Typedef Documentation

◆ Ptr

template<typename RCImpl >
typedef RCPtr<RC> openvpn::RC< RCImpl >::Ptr

Definition at line 914 of file rc.hpp.

Constructor & Destructor Documentation

◆ RC() [1/2]

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

◆ ~RC()

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

◆ RC() [2/2]

template<typename RCImpl >
openvpn::RC< RCImpl >::RC ( const RC< RCImpl > &  )
delete

Member Function Documentation

◆ is_thread_safe()

template<typename RCImpl >
constexpr bool openvpn::RC< RCImpl >::is_thread_safe ( )
staticconstexpr

Delegates call to RCImpl and returns the result.

Template Parameters
RCImpla suitable ref count implementation
Returns
true if the underlying RCImpl is thread safe
false if the underlying RCImpl is not thread safe

Definition at line 948 of file rc.hpp.

◆ operator=()

template<typename RCImpl >
RC & openvpn::RC< RCImpl >::operator= ( const RC< RCImpl > &  )
delete

◆ use_count()

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

Delegates call to RCImpl and returns the result.

Template Parameters
RCImpla suitable ref count implementation
Returns
olong ref count

Definition at line 937 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::RC< RCImpl >::refcount_
private

Definition at line 929 of file rc.hpp.


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