OpenVPN 3 Core Library
|
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. | |
RCCopyable & | operator= (const RCCopyable &) noexcept |
Ensures the new ref count is not copied with the rest of the object. | |
RCCopyable & | operator= (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. | |
Reference count base class for objects tracked by RCPtr. Allows copying and assignment.
RCImpl | The 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.
|
virtualdefault |
|
defaultnoexcept |
|
noexcept |
Construct a new RCCopyable object.
RCImpl | RC 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.
|
noexcept |
Construct a new RCCopyable object by move.
RCImpl | RC 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.
|
noexcept |
Ensures the new ref count is not copied with the rest of the object.
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.
|
noexcept |
Ensures the new ref count is not moved with the rest of the object.
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.
|
noexcept |
|
friend |
Helper to increment a ref count.
R | type that has an incrementable member refcount_ |
rcptr | pointer to instance of R |
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.
|
friend |
Helper to decrement a ref count.
R | type that has an decrementable member refcount_ |
rcptr | pointer to instance of R |
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.
|
private |