StrongRefHandler Class Reference

#include <baseref.h>

Inheritance diagram for StrongRefHandler:

Detailed Description

StrongRefHandler has to be used as template argument for BaseRef to obtain a reference to objects which support reference counting. Whenever the pointer of such a BaseRef is set, the reference count of the pointee is increased by invocation of AddReference() on the pointee. If a pointer is cleared, the reference count of the pointee is decreased by means of RemoveReference(). If the reference count reaches zero, the pointee releases itself.

Classes

struct  HasAddReference< FlexibleArray< T, COUNT > >
 
struct  HasRemoveReference< FlexibleArray< T, COUNT > >
 

Static Public Member Functions

template<typename T >
static void InitialReference (const T *o)
 
template<typename T >
static void AddReference (const T *o)
 
template<typename T >
static MAXON_ATTRIBUTE_NO_INLINE void RemoveReference (const T *o)
 
template<typename T >
static void AddWeakReference (const T *o, WeakRefBase &weakRef)
 
template<typename T >
static Bool CreateStrongReference (const T *o)
 
template<typename T >
static StrongReferenceCounterGetReferenceCounter (const T *o)
 
template<typename R >
static ResultRef< typename R::ReferencedType > MakeWritable (R &ref, Bool resetOnError)
 
template<typename T >
static void ChangeTarget (T *&o, T *newTarget)
 
template<typename T >
static void ChangeTarget (T *&o, ResultMemT< T * > newTarget)
 
template<typename T >
static void MoveTarget (T *&srcReference, T *&dstReference)
 

Static Public Attributes

static constexpr VALUEKIND KIND
 

Private Member Functions

 MAXON_MEMBERFUNCTION_DETECTOR (InitialReference)
 
 MAXON_MEMBERFUNCTION_DETECTOR (AddReference)
 
 MAXON_MEMBERFUNCTION_DETECTOR (RemoveReference)
 

Static Private Member Functions

template<typename T >
static void InitialReferenceImpl (const T *obj, std::false_type *)
 
template<typename T >
static void InitialReferenceImpl (const T *obj, std::true_type *)
 
template<typename T >
static void AddReferenceImpl (const T *obj, std::false_type *)
 
template<typename T >
static void AddReferenceImpl (const T *obj, std::true_type *)
 
template<typename T >
static void RemoveReferenceImpl (const T *obj, std::false_type *)
 
template<typename T >
static void RemoveReferenceImpl (const T *obj, std::true_type *)
 
template<typename T >
static Bool CreateStrongReferenceImpl (const T *obj, std::false_type *)
 
template<typename T >
static Bool CreateStrongReferenceImpl (const T *obj, std::true_type *)
 
template<typename T >
static void AddWeakReferenceImpl (const T *obj, WeakRefBase &weakRef, std::false_type *)
 
template<typename T >
static void AddWeakReferenceImpl (const T *obj, WeakRefBase &weakRef, std::true_type *)
 
template<typename T >
static StrongReferenceCounterGetReferenceCounterImpl (const T *obj, std::false_type *)
 
template<typename T >
static StrongReferenceCounterGetReferenceCounterImpl (const T *obj, std::true_type *)
 

Member Function Documentation

◆ MAXON_MEMBERFUNCTION_DETECTOR() [1/3]

MAXON_MEMBERFUNCTION_DETECTOR ( InitialReference  )
private

◆ MAXON_MEMBERFUNCTION_DETECTOR() [2/3]

MAXON_MEMBERFUNCTION_DETECTOR ( AddReference  )
private

◆ MAXON_MEMBERFUNCTION_DETECTOR() [3/3]

MAXON_MEMBERFUNCTION_DETECTOR ( RemoveReference  )
private

◆ InitialReference()

static void InitialReference ( const T *  o)
static

Sets the initial reference to a newly allocated object (slightly more efficient than AddReference).

Parameters
[in]oPointer to the referenced object, must not be nullptr.

◆ AddReference()

static void AddReference ( const T *  o)
static

Adds a reference to the referenced object.

Parameters
[in]oPointer to the referenced object, must not be nullptr.

◆ RemoveReference()

static MAXON_ATTRIBUTE_NO_INLINE void RemoveReference ( const T *  o)
static

Removes a reference to the referenced object.

Parameters
[in]oPointer to the referenced object, must not be nullptr.

◆ AddWeakReference()

static void AddWeakReference ( const T *  o,
WeakRefBase weakRef 
)
static

◆ CreateStrongReference()

static Bool CreateStrongReference ( const T *  o)
static

Tries to add a strong reference. If the object is already being released this will return false.

Parameters
[in]oWeakly referenced object (might be nullptr).
Returns
True if a strong reference could be added.

◆ GetReferenceCounter()

static StrongReferenceCounter& GetReferenceCounter ( const T *  o)
static

◆ MakeWritable()

static ResultRef<typename R::ReferencedType> MakeWritable ( R &  ref,
Bool  resetOnError 
)
static

◆ ChangeTarget() [1/2]

static void ChangeTarget ( T *&  o,
T *  newTarget 
)
static

Changes the target of the reference (removes it from the old target and adds it to the new one).

Parameters
[in]oReference to the pointer to the old object.
[in]newTargetPointer to the new target object.

◆ ChangeTarget() [2/2]

static void ChangeTarget ( T *&  o,
ResultMemT< T * >  newTarget 
)
static

Changes the target of the reference to a yet unreferenced object.

Parameters
[in]oReference to the pointer to the old object.
[in]newTargetPointer to a just allocated unreferenced target object.

◆ MoveTarget()

static void MoveTarget ( T *&  srcReference,
T *&  dstReference 
)
static

Moves a target from one BaseRef to another. This is being called when a BaseRef is moved to another BaseRef using operator =(&&).

Parameters
[in]srcReferenceReference to the source object pointer.
[in]dstReferenceReference to the destination object pointer.

◆ InitialReferenceImpl() [1/2]

static void InitialReferenceImpl ( const T *  obj,
std::false_type *   
)
staticprivate

◆ InitialReferenceImpl() [2/2]

static void InitialReferenceImpl ( const T *  obj,
std::true_type *   
)
staticprivate

◆ AddReferenceImpl() [1/2]

static void AddReferenceImpl ( const T *  obj,
std::false_type *   
)
staticprivate

◆ AddReferenceImpl() [2/2]

static void AddReferenceImpl ( const T *  obj,
std::true_type *   
)
staticprivate

◆ RemoveReferenceImpl() [1/2]

static void RemoveReferenceImpl ( const T *  obj,
std::false_type *   
)
staticprivate

◆ RemoveReferenceImpl() [2/2]

static void RemoveReferenceImpl ( const T *  obj,
std::true_type *   
)
staticprivate

◆ CreateStrongReferenceImpl() [1/2]

static Bool CreateStrongReferenceImpl ( const T *  obj,
std::false_type *   
)
staticprivate

◆ CreateStrongReferenceImpl() [2/2]

static Bool CreateStrongReferenceImpl ( const T *  obj,
std::true_type *   
)
staticprivate

◆ AddWeakReferenceImpl() [1/2]

static void AddWeakReferenceImpl ( const T *  obj,
WeakRefBase weakRef,
std::false_type *   
)
staticprivate

◆ AddWeakReferenceImpl() [2/2]

static void AddWeakReferenceImpl ( const T *  obj,
WeakRefBase weakRef,
std::true_type *   
)
staticprivate

◆ GetReferenceCounterImpl() [1/2]

static StrongReferenceCounter& GetReferenceCounterImpl ( const T *  obj,
std::false_type *   
)
staticprivate

◆ GetReferenceCounterImpl() [2/2]

static StrongReferenceCounter& GetReferenceCounterImpl ( const T *  obj,
std::true_type *   
)
staticprivate

Member Data Documentation

◆ KIND

constexpr VALUEKIND KIND
staticconstexpr