Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 ( )
inlinenoexcept

new objects have zero reference count

Definition at line 346 of file counting_ptr.hpp.

ReferenceCounter ( const ReferenceCounter )
inlinenoexcept

coping still creates a new object with zero reference count

Definition at line 350 of file counting_ptr.hpp.

~ReferenceCounter ( )
inline

Definition at line 359 of file counting_ptr.hpp.

References ReferenceCounter::reference_count_.

Member Function Documentation

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.

References ReferenceCounter::reference_count_.

Referenced by file::delete_request_ref().

void inc_reference ( ) const
inlinenoexcept

Call whenever setting a pointer to the object.

Definition at line 364 of file counting_ptr.hpp.

References ReferenceCounter::reference_count_.

Referenced by file::add_request_ref().

ReferenceCounter& operator= ( const ReferenceCounter )
inlinenoexcept

assignment operator, leaves pointers unchanged

Definition at line 354 of file counting_ptr.hpp.

bool unique ( ) const
inlinenoexcept

Test if the ReferenceCounter is referenced by only one CountingPtr.

Definition at line 380 of file counting_ptr.hpp.

References ReferenceCounter::reference_count_.

Member Data Documentation

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.

Referenced by ReferenceCounter::dec_reference(), ReferenceCounter::inc_reference(), ReferenceCounter::reference_count(), ReferenceCounter::unique(), and ReferenceCounter::~ReferenceCounter().


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