tlx
ReferenceCounter Class Reference

Provides reference counting abilities for use with CountingPtr. More...

#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...
 
ReferenceCounteroperator= (const ReferenceCounter &) noexcept
 assignment operator, leaves pointers unchanged More...
 
 ~ReferenceCounter ()
 
void inc_reference () const noexcept
 Call whenever setting a pointer to the object. More...
 
bool dec_reference () const noexcept
 Call whenever resetting (i.e. More...
 
bool unique () const noexcept
 Test if the ReferenceCounter is referenced by only one CountingPtr. More...
 
size_t reference_count () const noexcept
 Return the number of references to this object (for debugging) More...
 

Private Attributes

std::atomic< size_t > reference_count_
 the reference count is kept mutable for CountingPtr<const Type> to change the reference count. More...
 

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.

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.

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.

void inc_reference ( ) const
inlinenoexcept

Call whenever setting a pointer to the object.

Definition at line 364 of file counting_ptr.hpp.

ReferenceCounter& operator= ( const ReferenceCounter )
inlinenoexcept

assignment operator, leaves pointers unchanged

Definition at line 354 of file counting_ptr.hpp.

size_t reference_count ( ) const
inlinenoexcept

Return the number of references to this object (for debugging)

Definition at line 384 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.

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.


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