WeakRef< REFERENCE > Class Template Reference

#include <weakref.h>

Inheritance diagram for WeakRef< REFERENCE >:

Detailed Description

template<typename REFERENCE>
class maxon::WeakRef< REFERENCE >

A WeakRef points to a target object as long as there are strong references which also point to it. When an object has no more strong references it will be destructed and all weak references to it will return a null reference from then on.

Public Member Functions

 WeakRef ()
 
MAXON_IMPLICIT WeakRef (const REFERENCE &strongReference)
 
 WeakRef (const WeakRef &src)
 
 ~WeakRef ()
 
 WeakRef (WeakRef &&src)
 
WeakRefoperator= (const REFERENCE &strongReference)
 
WeakRefoperator= (const WeakRef &src)
 
 MAXON_OPERATOR_MOVE_ASSIGNMENT (WeakRef)
 
WeakRefoperator= (std::nullptr_t t)
 
 operator REFERENCE () const
 
REFERENCE GetReference () const
 
Bool operator== (const WeakRef &other) const
 
Bool operator!= (const WeakRef &other) const
 
 operator Bool () const
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
HashInt GetHashCode () const
 
UniqueHash GetUniqueHashCode () const
 
- Public Member Functions inherited from WeakRefBase
 WeakRefBase ()
 
 WeakRefBase (WeakRefTargetBase *targetData)
 
 ~WeakRefBase ()
 
 WeakRefBase (const WeakRefBase &src)
 
 WeakRefBase (WeakRefBase &&src)
 
WeakRefBaseoperator= (const WeakRefBase &src)
 
 MAXON_OPERATOR_MOVE_ASSIGNMENT (WeakRefBase)
 

Protected Member Functions

 WeakRef (WeakRefTargetBase *data)
 
const void * GetCurrent () const
 

Private Member Functions

const void * Lock () const
 
void Unlock (const void *target) const
 

Static Private Member Functions

template<typename REFERENCETYPE >
static REFERENCETYPE::BaseRefType & GetBaseRef (const REFERENCETYPE &strongReference)
 
template<typename T , typename HANDLER >
static BaseRef< T, HANDLER > & GetBaseRef (const BaseRef< T, HANDLER > &strongReference)
 

Additional Inherited Members

- Public Attributes inherited from WeakRefBase
WeakRefTargetBasedata
 

Constructor & Destructor Documentation

◆ WeakRef() [1/5]

WeakRef ( )

◆ WeakRef() [2/5]

MAXON_IMPLICIT WeakRef ( const REFERENCE &  strongReference)

Adds a weak reference. If memory allocation fails the weak reference will be nullptr.

Parameters
[in]strongReferenceBaseRef with strong reference to an object.

◆ WeakRef() [3/5]

WeakRef ( const WeakRef< REFERENCE > &  src)

Copy constructs a weak reference.

Parameters
[in]srcSource weak reference.

◆ ~WeakRef()

~WeakRef ( )

Removes a weak reference.

◆ WeakRef() [4/5]

WeakRef ( WeakRef< REFERENCE > &&  src)

Moves a weak reference.

Parameters
[in]srcSource weak reference, will be nulled.

◆ WeakRef() [5/5]

WeakRef ( WeakRefTargetBase data)
explicitprotected

Member Function Documentation

◆ operator=() [1/3]

WeakRef& operator= ( const REFERENCE &  strongReference)

Adds a strong reference.

Parameters
[in]strongReferenceBaseRef with strong reference to an object.
Returns
*this.

◆ operator=() [2/3]

WeakRef& operator= ( const WeakRef< REFERENCE > &  src)

Copies a weak reference.

Parameters
[in]srcSource weak reference.
Returns
*this.

◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( WeakRef< REFERENCE >  )

Moves a weak reference.

Parameters
[in]srcSource weak reference.
Returns
*this.

◆ operator=() [3/3]

WeakRef& operator= ( std::nullptr_t  t)

◆ operator REFERENCE()

operator REFERENCE ( ) const

Returns a strong reference. If the weak referenced object was already released a null reference will be returned.

Returns
Strong reference to the target or null.

◆ GetReference()

REFERENCE GetReference ( ) const

Returns a strong reference. If the weak referenced object was already released a null reference will be returned.

Returns
Strong reference to the target or null.

◆ operator==()

Bool operator== ( const WeakRef< REFERENCE > &  other) const

Compares WeakRefs for equality.

Parameters
[in]otherThe other comparand.
Returns
True if equal.

◆ operator!=()

Bool operator!= ( const WeakRef< REFERENCE > &  other) const

Compares WeakRefs for inequality.

Parameters
[in]otherThe other comparand.
Returns
True if not equal.

◆ operator Bool()

operator Bool ( ) const
explicit

Checks if the weak reference points to a strong reference (non-blocking check).

Returns
True if there currently is a strong reference, otherwise false.

◆ IsEmpty()

Bool IsEmpty ( ) const

Checks if the weak reference is empty.

Returns
True if the weak reference is empty.

◆ IsPopulated()

Bool IsPopulated ( ) const

Checks if this weak reference contains anything.

Returns
True if the weak reference points to an object.

◆ GetHashCode()

HashInt GetHashCode ( ) const

Compute hash code based on the targeted object's pointer. WeakRefs pointing to the same target will have the same hash code. When the target object is removed the hash code will change to the hash code of nullptr, this means two WeakRefs which initially pointed to different objects will have the same hash code after the target objects were destructed.

Returns
Hash code of the pointer of the referenced object, or the hash code of nullptr if the object doesn't exist.

◆ GetUniqueHashCode()

UniqueHash GetUniqueHashCode ( ) const

Compute hash value based on the targeted object's pointer. WeakRefs pointing to the same target will have the same hash value. When the target object is removed the hash value will change to the hash value of nullptr, this means two WeakRefs which initially pointed to different objects will have the same hash value after the target objects were destructed.

Returns
Hash value of the pointer of the referenced object, or the hash value of nullptr if the object doesn't exist.

◆ GetCurrent()

const void* GetCurrent ( ) const
protected

◆ Lock()

const void* Lock ( ) const
private

Locks the WeakRefTarget.

◆ Unlock()

void Unlock ( const void *  target) const
private

Unlocks the WeakRefTarget.

◆ GetBaseRef() [1/2]

static REFERENCETYPE::BaseRefType& GetBaseRef ( const REFERENCETYPE &  strongReference)
staticprivate

◆ GetBaseRef() [2/2]

static BaseRef<T, HANDLER>& GetBaseRef ( const BaseRef< T, HANDLER > &  strongReference)
staticprivate