#include <coherence/lang/WeakHolder.hpp>
WeakReferences allow one Object to safely reference another without blocking it from being destroyed. WeakRefereces are necessary when building Object graphs to avoid leaking the Object graph due to cyclical references.
WeakReferences are automatically NULL'd out when their referenced Object is destroyed. Additionally if the weakly referenced Object becomes only referenced via Views, then the WeakReference and corresponding WeakHandle will only return View to the Object, if an attempt is made to obtain a Handle a NULL will be returned instead.
WeakHolders are wrappers for MemberHolder, and provide a thread-safe handle implementation. As such they require references to both the referenced "child" Object, as well as the owning "parent" Object. As with MemberHolder the parent object must inherit from Object.
Note: In the rare case that a WeakHolder is declared via the mutable keyword, the WeakHolder must be informed of this fact by setting fMutable to true during construction.
Public Types | |
typedef const T | ValueType |
The type of Object which this handle weakly references. | |
typedef T::Handle | ValueHandle |
The associated non-weak Handle type. | |
typedef T::View | ValueView |
The associated non-weak View type. | |
typedef T::Holder | ValueHolder |
The associated non-weak Holder type. | |
Public Member Functions | |
WeakHolder (const Object &oGuardian) | |
Construct a WeakHolder referencing NULL. | |
WeakHolder (const Object &oGuardian, const TypedHolder< T > &that) | |
Construct a WeakHolder referencing an object. | |
WeakHolder (const Object &oGuardian, const TypedHolder< T > &that, bool fMutable) | |
Construct a WeakHolder referencing an object. | |
WeakHolder & | operator= (const TypedHolder< T > &that) |
Re-assign the WeakHolder to weakly reference a new Object. | |
WeakHolder & | operator= (const WeakHolder &that) |
Re-assign the WeakHolder to weakly reference a new Object. | |
operator ValueView () const | |
Return a non-weak View to the weakly referenced Object, or a View to NULL if the weakly referenced Object has been destroyed. | |
template<class PT> | |
o () const | |
Return a View to the referenced Object. | |
template<class PT> | |
o () const | |
Return a TypedHolder to the referenced Object. | |
ValueView | operator-> () const |
Dereference the WeakHolder returning a non-weak View. | |
const T & | operator * () const |
Dereference this handle, returning T& . | |
Protected Attributes | |
MemberHolder < WeakReference > | m_ohWeak |
The Holder to the associated WeakReference. | |
const T * | m_cpWeak |
Raw pointer to the weakly referenced object. |
WeakHolder | ( | const Object & | oGuardian | ) | [inline] |
Construct a WeakHolder referencing NULL.
oGuardian | reference to the WeakHolder's parent |
WeakHolder | ( | const Object & | oGuardian, | |
const TypedHolder< T > & | that | |||
) | [inline] |
Construct a WeakHolder referencing an object.
oGuardian | reference to the WeakHolder's parent | |
that | the object to reference |
WeakHolder | ( | const Object & | oGuardian, | |
const TypedHolder< T > & | that, | |||
bool | fMutable | |||
) | [inline] |
Construct a WeakHolder referencing an object.
oGuardian | reference to the WeakHolder's parent | |
that | the object to reference | |
fMutable | true if the member is declared as mutable, false if declared as const |
WeakHolder& operator= | ( | const TypedHolder< T > & | that | ) | [inline] |
Re-assign the WeakHolder to weakly reference a new Object.
that | the object to reference |
WeakHolder& operator= | ( | const WeakHolder< T > & | that | ) | [inline] |
Re-assign the WeakHolder to weakly reference a new Object.
that | the object to reference |
operator ValueView | ( | ) | const [inline] |
o | ( | ) | const [inline] |
o | ( | ) | const [inline] |
Return a TypedHolder to the referenced Object.
ValueView operator-> | ( | ) | const [inline] |
Dereference the WeakHolder returning a non-weak View.
If the non-weak View is non-NULL then it is guaranteed that the Object will continue to exist for at least the life of the returned View.
const T& operator * | ( | ) | const [inline] |
Dereference this handle, returning T&
.
T&
reference to the referenced ObjectNullPointerException | if the this handle is NULL |