#include <coherence/lang/WeakHandle.hpp>
WeakReferences allow one Object to safely reference another without blocking it from being destroyed. WeakReferences are necessary when building Object graphs to avoid leaking the Object graph due to cyclic 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.
WeakHandles behave like MemberHandles by transferring their constness to their referenced Object. As with MemberHandle WeakHandles are 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 MemberView the parent object must inherit from Object.
If the weakly referenced Object will always be referenced as a View then using the WeakView class would be more appropriate
Note: In the rare case that a WeakHandle is declared via the mutable keyword, the WeakHandle must be informed of this fact by setting fMutable to true during construction.
Public Types | |
typedef 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 MemberHandle < WeakReference > | InnerHandle |
The MemberHandle used to hold the internal WeakReference. | |
typedef ValueHandle | GetType |
Result type for a non-const get operation. | |
typedef ValueView | ConstGetType |
Result type for a non-const get operation. | |
Public Member Functions | |
WeakHandle (const Object &oGuardian) | |
Default constructor. | |
WeakHandle (const Object &oGuardian, const TypedHandle< T > &that) | |
Construct a WeakHandle from a normal Handle. | |
WeakHandle (const Object &oGuardian, const TypedHandle< T > &that, bool fMutable) | |
Construct a WeakHandle from a normal Handle. | |
WeakHandle & | operator= (const TypedHandle< T > &that) |
Re-assign the WeakHandle to weakly reference a new Object. | |
WeakHandle & | operator= (WeakHandle &that) |
Assign this WeakHandle to reference the same Object as the specified WeakHandle. | |
operator ValueHandle () | |
Return a non-weak Handle to the weakly referenced Object, or a Handle to NULL if the weakly referenced Object has been destroyed or is now only referenced via Views. | |
operator ValueView () const | |
Return a non-weak View to the weakly referenced Object, or a Handle 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 () | |
Return a Handle to the referenced Object. | |
template<class PT> | |
o () const | |
Return a TypedHolder to the referenced Object. | |
template<class PT> | |
o () | |
Return a TypedHolder to the referenced Object. | |
ValueHandle | operator-> () |
Dereference the WeakHandle returning a non-weak Handle. | |
ValueView | operator-> () const |
Dereference the WeakHandle returning a non-weak View. | |
const T & | operator * () const |
Dereference this handle, returning T& . | |
T & | operator * () |
Dereference this handle, returning T& . | |
Protected Attributes | |
InnerHandle | m_hWeak |
The Handle to the associated WeakReference. | |
T * | m_pWeak |
Raw pointer to the weakly referenced object. |
WeakHandle | ( | const Object & | oGuardian, | |
const TypedHandle< T > & | that | |||
) | [inline] |
Construct a WeakHandle from a normal Handle.
oGuardian | the self() on the object this data member is a member of | |
that | the object to reference |
WeakHandle | ( | const Object & | oGuardian, | |
const TypedHandle< T > & | that, | |||
bool | fMutable | |||
) | [inline] |
Construct a WeakHandle from a normal Handle.
oGuardian | the self() on the object this data member is a member of | |
that | the object to reference | |
fMutable | true if the member is declared as mutable, false if declared as const |
WeakHandle& operator= | ( | const TypedHandle< T > & | that | ) | [inline] |
WeakHandle& operator= | ( | WeakHandle< T > & | that | ) | [inline] |
Assign this WeakHandle to reference the same Object as the specified WeakHandle.
that | the object to reference |
operator ValueHandle | ( | ) | [inline] |
operator ValueView | ( | ) | const [inline] |
o | ( | ) | const [inline] |
o | ( | ) | const [inline] |
o | ( | ) | [inline] |
ValueHandle operator-> | ( | ) | [inline] |
Dereference the WeakHandle returning a non-weak Handle.
If the non-weak Handle is non-NULL then it is guaranteed that the Object will continue to exist for at least the life of the returned handle.
ValueView operator-> | ( | ) | const [inline] |
Dereference the WeakHandle returning a non-weak View.
If the non-weak Handle 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 |
T& operator * | ( | ) | [inline] |
Dereference this handle, returning T&
.
T&
reference to the referenced ObjectNullPointerException | if the this handle is NULL |