#include <coherence/lang/WeakView.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 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.
WeakViews are wrappers for MemberView, 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 MemberView the parent object must inherit from Object.
Note: In the rare case that a WeakView is declared via the mutable keyword, the WeakView 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. | |
Public Member Functions | |
WeakView (const Object &oGuardian) | |
Construct a WeakView referencing NULL. | |
WeakView (const Object &oGuardian, const TypedHandle< const T > &that) | |
Construct a WeakView referencing an object. | |
WeakView (const Object &oGuardian, const TypedHandle< const T > &that, bool fMutable) | |
Construct a WeakView referencing an object. | |
WeakView & | operator= (const TypedHandle< const T > &that) |
Re-assign the WeakView to weakly reference a new Object. | |
WeakView & | operator= (const WeakView &that) |
Re-assign the WeakView 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 WeakView returning a non-weak View. | |
const T & | operator * () const |
Dereference this handle, returning T& . | |
Protected Attributes | |
MemberView < WeakReference > | m_vWeak |
The View to the associated WeakReference. | |
const T * | m_cpWeak |
Raw pointer to the weakly referenced object. |
WeakView | ( | const Object & | oGuardian, | |
const TypedHandle< const T > & | that | |||
) | [inline] |
Construct a WeakView referencing an object.
oGuardian | reference to the WeakView's parent | |
that | the object to reference |
WeakView | ( | const Object & | oGuardian, | |
const TypedHandle< const T > & | that, | |||
bool | fMutable | |||
) | [inline] |
Construct a WeakView referencing an object.
oGuardian | reference to the WeakView's parent | |
that | the object to reference | |
fMutable | true if the member is declared as mutable, false if declared as const |
WeakView& operator= | ( | const TypedHandle< const T > & | that | ) | [inline] |
operator ValueView | ( | ) | const [inline] |
o | ( | ) | const [inline] |
o | ( | ) | const [inline] |
ValueView operator-> | ( | ) | const [inline] |
const T& operator * | ( | ) | const [inline] |
Dereference this handle, returning T&
.
T&
reference to the referenced ObjectNullPointerException | if the this handle is NULL |