TypedHolder Class Template Reference

#include <coherence/lang/TypedHolder.hpp>

List of all members.


Detailed Description

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

A handle implementation which supports referencing Objects as either Handles or Views.

TypedHolder can safely be used in place of View but adds the ability to attempt a safe down cast to a Handle. This differs from a const_cast in that the down cast will only succeed if the TypedHolder had been assigned from a Handle, an assignment from a View results in a TypedHolder whose down cast operation will fail with a ClassCastException.

TypedHolder is not for general use, instead it is a convience handle type which can be used for container like classes, which need to be able to contain both Handles and Views.

Author:
mf 2008.01.09
See also:
MemberHolder

Public Types

typedef const T ValueType
 The type of the values the holder can reference.
typedef T::Handle ValueHandle
 The Handle type for the referenced Object.
typedef T::View ValueView
 The View type for the referenced Object.

Public Member Functions

 TypedHolder ()
 Construct a new TypedHolder referencing NULL via a handle.
 TypedHolder (const TypedHolder &that)
 Construct a new TypedHolder refrencing the same Object (and in the same manner) as the specified TypedHolder.
template<class DT>
 TypedHolder (const TypedHandle< DT > &th)
 Construct a new TypedHolder refrencing specified Object via a Handle or View.
template<class DT>
 TypedHolder (const TypedHolder< DT > &that)
 Construct a new TypedHolder refrencing the same Object (and in the same manner) as the specified TypedHolder.
 TypedHolder (T *p)
 Construct a new TypedHolder refrencing the supplied object.
 ~TypedHolder ()
 Destroy the TypedHolder.
TypedHolderoperator= (const TypedHolder &that)
 Assign this TypedHolder to refrence the same Object (and in the same manner) as the specified TypedHolder.
template<class DT>
TypedHolderoperator= (const TypedHolder< DT > &that)
 Assign this TypedHolder to refrence the same Object (and in the same manner) as the specified TypedHolder.
template<class PT>
 o () const
 Return a View to the referenced Object.
T & operator * () const
 Dereference this holder, returning T&.
const T * operator-> () const
 Derefrence the TypedHolder.
template<class AT>
bool operator== (const TypedHolder< AT > &h) const
 Compare the supplied holder to this holder.
template<class AT>
bool operator!= (const TypedHolder< AT > &h) const
 Compare the supplied holder to this holder.
template<class AT>
bool operator== (const TypedHandle< AT > &h) const
 Compare the supplied handle to this holder.
template<class AT>
bool operator!= (const TypedHandle< AT > &h) const
 Compare the supplied handle to this holder.
bool operator== (const Object *cpo) const
 Compare the supplied pointer to this holder.
bool operator!= (const Object *cpo) const
 Compare the supplied pointer to this holder.

Protected Member Functions

ValueView getView () const
 Return a View to the referenced Object.
ValueHandle getHandle () const
 Return a Handle to the referenced Object.
void setView (const ValueView &v)
 Set the Holder to reference an Object via a View.
void setHandle (const ValueHandle &h)
 Set the Holder to reference an Object via a Handle.

Constructor & Destructor Documentation

TypedHolder ( const TypedHolder< T > &  that  )  [inline]

Construct a new TypedHolder refrencing the same Object (and in the same manner) as the specified TypedHolder.

Parameters:
that the TypedHolder to initialize from

TypedHolder ( const TypedHandle< DT > &  th  )  [inline]

Construct a new TypedHolder refrencing specified Object via a Handle or View.

As a Handle is used, the TypedHolder can be used with the cast<...Handle>() method to retrieve the Handle from the Holder.

Parameters:
th a Handle or View to the Object to reference

TypedHolder ( const TypedHolder< DT > &  that  )  [inline]

Construct a new TypedHolder refrencing the same Object (and in the same manner) as the specified TypedHolder.

Parameters:
that the TypedHolder to initialize from

TypedHolder ( T *  p  )  [inline]

Construct a new TypedHolder refrencing the supplied object.

This method is primarily intended to support assignment from NULL, though it will work with other non-const pointers. To avoid introducing ambiguity in the case of NULL, there is no corresponding const T* variant. In the rare cases where one is needed the supplied const pointer should be externally wrapped in a View.

Parameters:
p pointer to the Object to reference


Member Function Documentation

TypedHolder& operator= ( const TypedHolder< T > &  that  )  [inline]

Assign this TypedHolder to refrence the same Object (and in the same manner) as the specified TypedHolder.

Parameters:
that the TypedHolder to assign from
Returns:
a reference to this TypedHolder

TypedHolder& operator= ( const TypedHolder< DT > &  that  )  [inline]

Assign this TypedHolder to refrence the same Object (and in the same manner) as the specified TypedHolder.

Parameters:
that the TypedHolder to assign from
Returns:
a reference to this TypedHolder

o (  )  const [inline]

Return a View to the referenced Object.

Returns:
a View to the referenced Object

T& operator * (  )  const [inline]

Dereference this holder, returning T&.

Returns:
a raw T& reference to the refernced Object
Exceptions:
NullPointerException if the this holder is NULL

const T* operator-> (  )  const [inline]

Derefrence the TypedHolder.

Returns:
a const pointer to the referenced Object

bool operator== ( const TypedHolder< AT > &  h  )  const [inline]

Compare the supplied holder to this holder.

Parameters:
h the holder to compare against
Returns:
true iff the same object is referenced

bool operator!= ( const TypedHolder< AT > &  h  )  const [inline]

Compare the supplied holder to this holder.

Parameters:
h the holder to compare against
Returns:
true iff different objects are referenced

bool operator== ( const TypedHandle< AT > &  h  )  const [inline]

Compare the supplied handle to this holder.

Parameters:
h the handle to compare against
Returns:
true iff the same object is referenced

bool operator!= ( const TypedHandle< AT > &  h  )  const [inline]

Compare the supplied handle to this holder.

Parameters:
h the handle to compare against
Returns:
true iff the different objects are referenced

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

Compare the supplied pointer to this holder.

Parameters:
cpo the pointer to compare against
Returns:
true iff the same object is referenced

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

Compare the supplied pointer to this holder.

Parameters:
cpo the pointer to compare against
Returns:
true iff different objects are referenced

ValueView getView (  )  const [inline, protected]

Return a View to the referenced Object.

Returns:
a View to the referenced Object

ValueHandle getHandle (  )  const [inline, protected]

Return a Handle to the referenced Object.

Returns:
a Handle to the referenced Object, or NULL if the Object is referenced via a View

void setView ( const ValueView v  )  [inline, protected]

Set the Holder to reference an Object via a View.

Parameters:
v the View to the Object to reference

void setHandle ( const ValueHandle h  )  [inline, protected]

Set the Holder to reference an Object via a Handle.

Parameters:
h the Handle to the Object to reference


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