Thrill  0.1
ReferenceCounter Class Reference

Detailed Description

Provides reference counting abilities for use with CountingPtr.

Use as superclass of the actual object, this adds a reference_count_ value. Then either use CountingPtr as pointer to manage references and deletion, or just do normal new and delete.

Definition at line 337 of file counting_ptr.hpp.

+ Inheritance diagram for ReferenceCounter:

#include <counting_ptr.hpp>

Public Member Functions

 ReferenceCounter () noexcept
 new objects have zero reference count More...
 
 ReferenceCounter (const ReferenceCounter &) noexcept
 coping still creates a new object with zero reference count More...
 
 ~ReferenceCounter ()
 
bool dec_reference () const noexcept
 Call whenever resetting (i.e. More...
 
void inc_reference () const noexcept
 Call whenever setting a pointer to the object. More...
 
ReferenceCounteroperator= (const ReferenceCounter &) noexcept
 assignment operator, leaves pointers unchanged More...
 
size_t reference_count () const noexcept
 Return the number of references to this object (for debugging) More...
 
bool unique () const noexcept
 Test if the ReferenceCounter is referenced by only one CountingPtr. More...
 

Private Attributes

std::atomic< size_t > reference_count_
 

Constructor & Destructor Documentation

◆ ReferenceCounter() [1/2]

ReferenceCounter ( )
inlinenoexcept

new objects have zero reference count

Definition at line 346 of file counting_ptr.hpp.

◆ ReferenceCounter() [2/2]

ReferenceCounter ( const ReferenceCounter )
inlinenoexcept

coping still creates a new object with zero reference count

Definition at line 350 of file counting_ptr.hpp.

◆ ~ReferenceCounter()

~ReferenceCounter ( )
inline

Definition at line 359 of file counting_ptr.hpp.

Member Function Documentation

◆ dec_reference()

bool dec_reference ( ) const
inlinenoexcept

Call whenever resetting (i.e.

overwriting) a pointer to the object. IMPORTANT: In case of self-assignment, call AFTER inc_reference().

Returns
if the object has to be deleted (i.e. if it's reference count dropped to zero)

Definition at line 374 of file counting_ptr.hpp.

Referenced by file::delete_request_ref().

◆ inc_reference()

void inc_reference ( ) const
inlinenoexcept

Call whenever setting a pointer to the object.

Definition at line 364 of file counting_ptr.hpp.

Referenced by file::add_request_ref().

◆ operator=()

ReferenceCounter& operator= ( const ReferenceCounter )
inlinenoexcept

assignment operator, leaves pointers unchanged

Definition at line 354 of file counting_ptr.hpp.

Referenced by DynBlockSourceAdapter< BlockSource >::DynBlockSourceAdapter().

◆ reference_count()

size_t reference_count ( ) const
inlinenoexcept

◆ unique()

bool unique ( ) const
inlinenoexcept

Test if the ReferenceCounter is referenced by only one CountingPtr.

Definition at line 380 of file counting_ptr.hpp.

Member Data Documentation

◆ reference_count_

std::atomic<size_t> reference_count_
mutableprivate

the reference count is kept mutable for CountingPtr<const Type> to change the reference count.

Definition at line 342 of file counting_ptr.hpp.


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