WeakHandle Class Template Reference

#include <coherence/lang/WeakHandle.hpp>

List of all members.


Detailed Description

template<class T>
class coherence::lang::WeakHandle< T >

WeakHandles are a TypedHandle like wrapper around WeakReferences.

WeakReferences allow one Object to safely reference another without blocking it from being destroyed. WeakRefere ces 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. Addionally 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 transfering their constness to their referenced Object. As with MemberHandle WeakHandles are athread-safe handle implementation. As such they require references to both the referenced "child" Object, as well as the ownening "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: Declaration of WeakHandles as "mutable" is not supported, and may result in run-time errors, if the parent object becomes only reachable via Views. If a mutable WeakHanle is needed, considering using WeakRefernece instead.

See also:
MemberHandle

WeakView

Author:
mf 2007.07.05

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 (Object &oParent)
 Default constructor.
 WeakHandle (Object &oParent, ValueHandle h, bool fMutable=false)
 Construct a WeakHandle from a normal Handle.
ValueHandle operator-> ()
 Dereference the WeakHandle returning a non-weak Handle.
ValueView operator-> () const
 Dereference the WeakHandle returning a non-weak View.
WeakHandle< T > & operator= (const ValueHandle &h)
 Re-assign the WeakHandle to weakly reference a new Object.
WeakHandle< T > & operator= (WeakHandle< T > &h)
 Re-assign the WeakHandle.
WeakHandle< T > & operator= (const WeakHandle< T > &h)
 Re-assign the 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.
 o ()
 Return a non-weak Holder to the weakly referenced Object, or a Holder to NULL if the weakly referenced Object has been destroyed.
bool operator< (const WeakHandle< T > &wThat) const
bool operator== (const WeakHandle< T > &wThat) const
 Compare two WeakHandles for equality.
bool operator!= (const WeakHandle< T > &wThat) const
 Compare two WeakHandles for inequality.
bool operator== (const ValueHandle &h) const
 Compare two handles for equality.
bool operator!= (const ValueHandle &h) const
 Compare two handles for inequality.
bool operator== (const Object *o) const
 Compare this handle with the raw pointer for equality.
bool operator!= (const Object *o) const
 Compare this handle with the raw pointer for inequality.

Protected Attributes

InnerHandle m_mhWeak
 The Handle to the assocaited WeakReference.

Constructor & Destructor Documentation

WeakHandle ( Object oParent,
ValueHandle  h,
bool  fMutable = false 
) [inline]

Construct a WeakHandle from a normal Handle.

Parameters:
oParent the self() on the object this data member is a member of
h The handle to reference
fMutable true iff the member is declared mutable


Member Function Documentation

ValueHandle operator-> (  )  [inline]

Dereference the WeakHandle returning a non-weak Handle.

If the non-weak Handle is non-NULL then it is guarenteed that the Object will continue to exist for at least the life of the returned handle.

Returns:
ValueHandle

ValueView operator-> (  )  const [inline]

Dereference the WeakHandle returning a non-weak View.

If the non-weak Handle is non-NULL then it is guarenteed that the Object will continue to exist for at least the life of the returned View.

Returns:
ValueHandle

WeakHandle<T>& operator= ( const ValueHandle h  )  [inline]

Re-assign the WeakHandle to weakly reference a new Object.

Parameters:
h a Handle to the Object to weakly reference

WeakHandle<T>& operator= ( WeakHandle< T > &  h  )  [inline]

Re-assign the WeakHandle.

Parameters:
h a WeakHandle to the Object to weakly reference

WeakHandle<T>& operator= ( const WeakHandle< T > &  h  )  [inline]

Re-assign the WeakHandle.

Parameters:
h a WeakHandle to the Object to weakly reference

operator ValueHandle (  )  [inline]

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.

Returns:
ValueHandle

operator ValueView (  )  const [inline]

Return a non-weak View to the weakly referenced Object, or a Handle to NULL if the weakly referenced Object has been destroyed.

Returns:
ValueHandle

o (  )  [inline]

Return a non-weak Holder to the weakly referenced Object, or a Holder to NULL if the weakly referenced Object has been destroyed.

Returns:
holder

bool operator< ( const WeakHandle< T > &  wThat  )  const [inline]

Compare two WeakHandles with "less-than" predicate.

bool operator== ( const Object o  )  const [inline]

Compare this handle with the raw pointer for equality.

Returns:
true iff the handle and the pointer reference the same Object

bool operator!= ( const Object o  )  const [inline]

Compare this handle with the raw pointer for inequality.

Returns:
false iff the handle and the pointer reference the same Object


The documentation for this class was generated from the following file: Copyright (c) 2000-2008 Oracle. All rights reserved.