Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

MangoPtr::CheckedPtr< T > Class Template Reference

#include <CheckedPtr.hh>

List of all members.


Detailed Description

template<typename T>
class MangoPtr::CheckedPtr< T >

Proxy class that stands for a pointer.

Its role is to check for the nullness of the pointer it contains before a dereference operation. It is used by Owned<T*> and BLink<T> when they return their pointer, so that the assertion can be done only if the pointer is dereferenced rather than just used by value (in a boolean test or comparison to other pointer etc). For instance,

    Owned<Foo*> foo;
    if ( isNull(foo()) ) doSomething(); // line 1
    foo()->callFooMethod(); // line 2
In lines 1 and 2, foo() returns a pointer, but cannot assert that it is non-null, because it doesn't know whether it is going to be used by value (line 1) or dereferenced (line 2). Therfeore, Owned<Foo*>::operator()() returns instead a CheckedPtr, and CheckedPtr provides the operator->(), in which the assert is done, and provides other operators where the pointer is used by value, where the assertion is not done.

CheckedPtr can be used as a normal pointer for almost any pointer operation. The only known case where this is not true is when giving a CheckedPtr<T> to a function template expecting a T*, since the compiler does not attempt any conversion in this case, and you must use (T*) in front of your argument.

Since:
July 2002
Author:
Oliver Schoenborn

Definition at line 59 of file CheckedPtr.hh.

Public Methods

 CheckedPtr (T *ptr)
 Construct for ptr.

 CheckedPtr (const CheckedPtr &rhs)
 Copy consructor.

template<typename T2>  CheckedPtr (const CheckedPtr< T2 > &rhs)
 Copy-convert constructor for pointer conversions.

T * operator-> () const
 dereference for access

T & operator * () const
 dereference for use

 operator T * () const
 Convert to a pointer of type T when necessary.

Comparison operators

Friends

class CheckedPtr
 All CheckedPtr are friends so pointer conversions possible.


The documentation for this class was generated from the following file:
Generated on Tue Nov 12 20:44:02 2002 for Mango-ptr Library by doxygen1.2.18