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

CTBownedObjPtr Class Template Reference

Owned object pointer. More...

#include <CTBownedObjPtr.hxx>

Inheritance diagram for CTBownedObjPtr:

Inheritance graph
[legend]
Collaboration diagram for CTBownedObjPtr:

Collaboration graph
[legend]
List of all members.

Public Methods

 CTBownedObjPtr ()
 CTBownedObjPtr (CTBownedObjPtr< T > &rhs)
 CTBownedObjPtr (T *p)
 ~CTBownedObjPtr ()
TRelease ()
bool Equal (const CTBownedObjPtr< T > &rhs) const
void ToStream (ostream &os) const
CTBownedObjPtr< T > & operator= (CTBownedObjPtr< T > &rhs)
CTBownedObjPtr< T > & operator= (T *rhs)
Toperator * () const
Toperator-> () const
bool operator! () const
 operator void * () const

Protected Attributes

Tmp

Related Functions

(Note that these are not member functions.)

bool operator== (const CTBownedObjPtr< T > &lhs, const CTBownedObjPtr< T > &rhs)
ostream & operator<< (ostream &os, const CTBownedObjPtr< T > &obj)

Detailed Description

template<class T>
class CTBownedObjPtr< T >

Owned object pointer.

This is the base class of a set of `smart pointers' which maintain a one-to-one correspondence between a pointer and an object on the heap. The copy constructor and the assignment operator are defined as grabs, they transfer the object reference from the source pointer and clear the source pointer afterwards. The controled object is deleted when the controling pointer is destroyed or assigned with another value.

For obvious reasons there is no operator T *() method. But sometimes it is necessary to have an explicit pointer to the controlled object. Use &(*p) at your own risk, it can compromise the lifetime control of CTBownedObjPtr.

Applicability:
This pointer class should work with almost every type T. It doesn't require a copy constructor and can thus be used for abstract base classes.
Requirements:
Credits:
Inspired by the discussion of Programmer-Defined Pointer Classes in Barton & Nackman "Scientific and Engeneering C++". However, the class structure is here different to accomodate abstract base classes.

Definition at line 17 of file CTBownedObjPtr.hxx.


Constructor & Destructor Documentation

template<class T>
CTBownedObjPtr< T >::CTBownedObjPtr [inline]
 

Default constructor.

Definition at line 47 of file CTBownedObjPtr.icc.

template<class T>
CTBownedObjPtr< T >::CTBownedObjPtr CTBownedObjPtr< T > & rhs [inline]
 

Copy constructor (grab controlled object of rhs).

The reference to the object controlled by rhs is transfered and the pointer rhs is zeroed.

Definition at line 59 of file CTBownedObjPtr.icc.

template<class T>
CTBownedObjPtr< T >::CTBownedObjPtr T * p [inline]
 

Construct from pointer.

The object refered to by p becomes the controlled object.

Definition at line 72 of file CTBownedObjPtr.icc.

template<class T>
CTBownedObjPtr< T >::~CTBownedObjPtr [inline]
 

Destructor.

The controlled object will be deleted.

Definition at line 83 of file CTBownedObjPtr.icc.


Member Function Documentation

template<class T>
T * CTBownedObjPtr< T >::Release [inline]
 

Release controlled object.

Returns the pointer to the controlled object and clears the CTBownedObjPtr object. The caller is now responsible to control the lifetime of the object.

Definition at line 96 of file CTBownedObjPtr.icc.

template<class T>
bool CTBownedObjPtr< T >::Equal const CTBownedObjPtr< T > & rhs const [inline]
 

Returns true if equal to rhs.

Definition at line 107 of file CTBownedObjPtr.icc.

Referenced by operator==().

template<class T>
void CTBownedObjPtr< T >::ToStream ostream & os const [inline]
 

ostream insertion.

Definition at line 116 of file CTBownedObjPtr.icc.

template<class T>
CTBownedObjPtr< T > & CTBownedObjPtr< T >::operator= CTBownedObjPtr< T > & rhs [inline]
 

Grab controlled object of rhs.

The reference to the object controlled by rhs is transfered and the pointer rhs is zeroed.

Definition at line 130 of file CTBownedObjPtr.icc.

Referenced by CTBclonedObjPtr::operator=().

template<class T>
CTBownedObjPtr< T > & CTBownedObjPtr< T >::operator= T * rhs [inline]
 

Make rhs the controlled object.

Reimplemented in CTBclonedObjPtr.

Definition at line 144 of file CTBownedObjPtr.icc.

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

Dereference pointer (access controlled object).

Definition at line 155 of file CTBownedObjPtr.icc.

template<class T>
T * CTBownedObjPtr< T >::operator-> const [inline]
 

Access member of controlled object.

Definition at line 164 of file CTBownedObjPtr.icc.

template<class T>
bool CTBownedObjPtr< T >::operator! const [inline]
 

Returns true if pointer null.

Definition at line 172 of file CTBownedObjPtr.icc.

template<class T>
CTBownedObjPtr< T >::operator void * const [inline]
 

Returns non-zero pointer if pointer not null.

Definition at line 181 of file CTBownedObjPtr.icc.


Friends And Related Function Documentation

template<class T>
bool operator== const CTBownedObjPtr< T > & lhs,
const CTBownedObjPtr< T > & rhs
[related]
 

Returns true if lhs and rhs are equal.

Note, that the operator== isn't overly useful in practice. By construction, two CTBownedObjPtr pointer objects can be equal only if both are null. The operator is only provided so that this class can be used in containers which require an equal operator.

Definition at line 198 of file CTBownedObjPtr.icc.

template<class T>
ostream & operator<< ostream & os,
const CTBownedObjPtr< T > & obj
[related]
 

ostream insertion operator.

Definition at line 211 of file CTBownedObjPtr.icc.


Member Data Documentation

template<class T>
T* CTBownedObjPtr::mp [protected]
 

pointer to controlled object.

Definition at line 41 of file CTBownedObjPtr.hxx.


The documentation for this class was generated from the following files:
Generated at Fri Oct 24 18:13:58 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001