Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

Handle< T > Class Template Reference
[ReferenceCounting]

A class whose instances act like pointers that manage their reference count automatically. More...

#include <IotrHandle.hh>

List of all members.

Public Methods

 Handle ()
 Default constructor; creates a Handle referring to nothing.

 operator T * ()
 Automatically convert this object into a traditional pointer to an object that may be passed in as a parameter to function or method calls.

T * ptr () const
 Call HandleAsPointer() instead; return a traditional pointer to the underlying object.

 Handle (T *t)
 Allow EXPLICIT conversion from a (T*) to a Handle to T.

 Handle (const Handle< T > &handle)
 Copy constructor; creates a new Handle referring to the same object.

T & operator * ()
 Dereferencing operation.

Handle< T > & operator= (const Handle< T > &handle)
 Assignment operator; cause this Handle to refer to the same object that handle refers to.

 ~Handle ()
 Destructor; release the object (through a call to IotrRelease()) if the object is not nil.

T * operator-> ()
 Send a message to, or access a data member of, the object to which this is a reference.


Static Public Methods

void bind (Handle< T > &handle, T **obj)
 Converts a traditional pointer to a Handle, destroying the original pointer.

void referTo (Handle< T > &handle, T *obj)
 Makes a Handle refer to the same object as a traditional pointer.


Protected Attributes

T * obj
 a traditional pointer to the object being referenced.


Detailed Description

template<class T>
class Handle< T >

A class whose instances act like pointers that manage their reference count automatically.

Use handles when you wish to keep a reference to a instance of a subclass of IotrRefCount. Do not use a handle to refer to an object passed in as a parameter to a routine, unless you intend to keep the reference after the routine has exited.

See also:
the Reference Counting section, especially the subsection discussing Handles.


Constructor & Destructor Documentation

template<class T>
Handle< T >::Handle const Handle< T > &    handle [inline]
 

Copy constructor; creates a new Handle referring to the same object.

Increments the reference count of the object.

Parameters:
handle  an existing reference to an object. This reference may be nil.

template<class T>
Handle< T >::Handle T *    t [inline]
 

Allow EXPLICIT conversion from a (T*) to a Handle to T.

Implicit conversion is not allowed, because this can have subtle, unintended consequences.


Member Function Documentation

template<class T>
T& Handle< T >::operator *   [inline]
 

Dereferencing operation.

Return a reference to the object.

template<class T>
Handle< T >::operator T *   [inline]
 

Automatically convert this object into a traditional pointer to an object that may be passed in as a parameter to function or method calls.

For most other purposes Handle::ptr() is more appropriate

template<class T>
Handle<T>& Handle< T >::operator= const Handle< T > &    handle [inline]
 

Assignment operator; cause this Handle to refer to the same object that handle refers to.

Parameters:
handle  is an existing reference to an object. This reference may be nil.

template<class T>
void Handle< T >::referTo Handle< T > &    handle,
T *    obj
[inline, static]
 

Makes a Handle refer to the same object as a traditional pointer.

It is preferable to call HandleReferTo() instead of this method.


The documentation for this class was generated from the following file:
Generated on Wed Aug 27 10:03:42 2003 for iotr by doxygen1.2.18