TypedHandle Class Template Reference

#include <coherence/lang/TypedHandle.hpp>

Inherited by BoxHandle, Immutable, String::StringHandle, SubscriptHandle, and throwable_spec::hierarchy.

List of all members.


Detailed Description

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

Reference counting "smart pointer" class for use with Coherence managed objects.

Managed objects manage their own life cycle, rather the relying on user code to identify when they should be deleted. The TypedHandle class can be used with any class implementing the coherence::lang::Object interface.

By convention each Object implemention will include two typedefs for TypedHandle to make their usage easier. For instance the class "Foo" would define Foo::Handle as a TypedHandle<Foo>. The second typedef is called a View, and is analougous to a pointer to a const, that is Foo::View is TypedHandle<const Foo>.

TypedHandles are not thread-safe, and should not be used in a multi-threaded context if they will be updated. They should only be used as local variables. The most common place where thread-safe handles are needed is for object data members. For these cases the Coherence API includes two forms of thread-safe handles/views, namely MemberHandle/View and WeakHandle/View.

See also:
Object

MemberHandle

MemberView

WeakHandle

WeakView

Author:
mf 2007.07.05

Public Types

typedef T ValueType
 A concrete object type that is referenced by this handle.
typedef
value_less_functor
< T > 
value_compare
 Functor allowing handles to be used within STL sorted containers, such as std::map and std::set, and to have their equivalence checks delegated to the Objects they reference.
typedef
value_equal_functor
< T > 
value_equal
 Functor allowing handles to be used within hash containers, such as the SGI and MS style hash_map and hash_set, and to have their equivalence checks delegated to the Objects they reference.
typedef
value_hash_functor
< T > 
value_hasher
 Functor allowing handles to be used within hash containers, such as the SGI as MS style hash_map and hash_set, and to have their hash computation be based on the value of the referenced Object.
typedef
identity_hash_functor
< T > 
identity_hasher
 Functor allowing handles to be used within hash containers, such as the SGI as MS style hash_map and hash_set, and to have their hash computation be based on their identity, i.e.

Public Member Functions

 T (T *po=NULL)
 Construct a handle that references given Object.
template<class DT>
 T (const TypedHandle< DT > &h)
 Construct a handle from a handle to a derived type.
 T (const TypedHandle< T > &h)
 Construct a handle from another handle.
 ~ ()
 Destruct this handle.
T & operator * () const
 Dereference this handle, returning T&.
T * operator-> () const
 Dereference this handle, returning T*.
TypedHandle< T > & operator= (const TypedHandle< T > &h)
 Assign this TypedHandle another Object to reference.
template<class DT>
TypedHandle< T > & operator= (const TypedHandle< DT > &h)
 Assign this TypedHandle from a handle to a derived type.
template<class AT>
bool operator< (const TypedHandle< AT > &h) const
 Compare two handles with "less-than" predicate.
bool operator== (const Object *cpo) const
 Compare the supplied pointer to this handle.
bool operator!= (const Object *cpo) const
 Compare the supplied pointer to this handle.

Protected Member Functions

T * get () const
 Return pointer without null checking.
TypedHandle< T > & set (T *o)
 Set the TypedHandle to attach to the supplied pointer.

Protected Attributes

T * m_o
 Pointer to the referenced object.

Classes

class  identity_hash_functor
 Identity based hash functor which is compatible with both the SGI and MS style hash containers. More...
class  value_equal_functor
 The binary functor that compares values pointed by the handles for equality. More...
class  value_hash_functor
 Value based hash functor which is compatible with both the SGI and MS style hash containers. More...
class  value_less_functor
 The binary functor that compares objects pointed by the handles with the "less-than" operator. More...

Member Typedef Documentation

typedef identity_hash_functor<T> identity_hasher

Functor allowing handles to be used within hash containers, such as the SGI as MS style hash_map and hash_set, and to have their hash computation be based on their identity, i.e.

the reference they contain.


Member Function Documentation

T ( T *  po = NULL  )  [inline]

Construct a handle that references given Object.

Parameters:
po a pointer to the Object to reference

T ( const TypedHandle< DT > &  h  )  [inline]

Construct a handle from a handle to a derived type.

New handle will reference the same Object that the given handle.

Parameters:
h another handle

T ( const TypedHandle< T > &  h  )  [inline]

Construct a handle from another handle.

New handle will reference the same Object that the given handle.

Parameters:
h another handle

T& operator * (  )  const [inline]

Dereference this handle, returning T&.

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

T* operator-> (  )  const [inline]

Dereference this handle, returning T*.

Returns:
a raw T* pointer to the refernced Object
Exceptions:
NullPointerException if the this handle is NULL

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

Compare two handles with "less-than" predicate.

This is only an identity based comparison, and does not take the value into account.

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

Compare the supplied pointer to this handle.

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

Reimplemented in BoxHandle, and String::StringHandle.

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

Compare the supplied pointer to this handle.

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

Reimplemented in BoxHandle, and String::StringHandle.

T* get (  )  const [inline, protected]

Return pointer without null checking.

Does NOT throw NullPointerException.

One shoud use h.get() to get raw T* pointer. Please do not use neither &*h (as it may throw NullPointerException) nor (T*)h (as it may perform unsafe unchecked type cast).

TypedHandle<T>& set ( T *  o  )  [inline, protected]

Set the TypedHandle to attach to the supplied pointer.

Any existing attachment will be detatched.

Parameters:
o the address of the object to point to or NULL


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