StrongReferenceCounter Class Reference

#include <atomictypes.h>

Detailed Description

Atomic reference counter.

Public Types

using ValueType = UInt
 

Public Member Functions

 StrongReferenceCounter ()
 
 StrongReferenceCounter (const StrongReferenceCounter &)
 
void operator= (const StrongReferenceCounter &)
 
Bool Inc ()
 
Bool Dec ()
 
Bool ConditionalInc ()
 
void Add (UInt additionalReferences)
 
void SetRelaxed (UInt referenceCount)
 
 operator UInt () const
 
Bool HasMultipleReferences () const
 
Bool HasMoreReferences (Int count) const
 

Static Public Member Functions

static MAXON_ATTRIBUTE_FORCE_INLINE const StrongReferenceCounterNullValue ()
 
static StrongReferenceCounterGet (const void *object)
 

Protected Attributes

AtomicUInt _value
 

Member Typedef Documentation

◆ ValueType

using ValueType = UInt

The underlying integral type of this reference counter.

Constructor & Destructor Documentation

◆ StrongReferenceCounter() [1/2]

◆ StrongReferenceCounter() [2/2]

Member Function Documentation

◆ operator=()

void operator= ( const StrongReferenceCounter )

◆ Inc()

Bool Inc ( )

Increments reference counter (the caller acquires a strong reference).

Returns
True for the very first reference, otherwise false.

◆ Dec()

Bool Dec ( )

Decrements reference counter (the caller removes a strong reference).

Returns
True if no more strong references are held, otherwise false.

◆ ConditionalInc()

Bool ConditionalInc ( )

Adds a reference if the object is still strongly referenced.

Returns
True if a strong reference was added, false if the object is currently being destructed.

◆ Add()

void Add ( UInt  additionalReferences)

Adds references.

Parameters
[in]additionalReferencesThe number of additional references to add.

◆ SetRelaxed()

void SetRelaxed ( UInt  referenceCount)

Sets a specifc reference count - for initialization only!

Note
You must guarantee that the access is exclusive and single-threaded. Use only for initialization of static objects which are not to destructed.

◆ operator UInt()

operator UInt ( ) const

Returns the number of strong references to the object.

Returns
The number of strong references.

◆ HasMultipleReferences()

Bool HasMultipleReferences ( ) const

Returns whether an object has more than a single reference. For an object without a reference it will return false. For an object with one strong reference it will return false. For an object with a single strong reference and weak references it will return true. For an object with two strong references it will return true.

Returns
True if the object has more than a single reference, false otherwise.

◆ HasMoreReferences()

Bool HasMoreReferences ( Int  count) const

Returns whether an object has more references then the given count. For an object without weak references and with at most count strong references it will return false. Otherwise, for an object with weak references or with more than count strong references it will return true.

Returns
True if the object has more than count references, false otherwise.

◆ NullValue()

static MAXON_ATTRIBUTE_FORCE_INLINE const StrongReferenceCounter& NullValue ( )
static

◆ Get()

static StrongReferenceCounter& Get ( const void *  object)
static

Returns the reference counter for classes which do not implement custom AddReference/RemoveReference methods.

Member Data Documentation

◆ _value

AtomicUInt _value
protected