code::InitDerivedSmartPtr< BaseType, DerivedType > Class Template Reference

Inheritance diagram for code::InitDerivedSmartPtr< BaseType, DerivedType >:

code::InitSmartPtr< BaseType > code::SmartPtr< BaseType > List of all members.

Detailed Description

template<class BaseType, class DerivedType>
class code::InitDerivedSmartPtr< BaseType, DerivedType >

An Initialized Derived Pointer, where the object pointed to is always valid.

See also:
: SmartPtr, InitSmartPtr, DerivedSmartPtr, InitDerivedSmartPtr
Author:
: Lakshman :
Id
code_DerivedSmartPtr.h,v 1.9 2009/06/02 20:17:39 lakshman Exp


Public Member Functions

 InitDerivedSmartPtr (DerivedType *p)
 Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.
 InitDerivedSmartPtr (InitSmartPtr< DerivedType > orig)
 Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.
 InitDerivedSmartPtr ()
 Default initialization creates a new object.
InitSmartPtr< DerivedType > getDerivedType ()
 To obtain a derived object pointer.
bool operator< (const InitDerivedSmartPtr< BaseType, DerivedType > &other) const
 To enable easy mapping of SmartPtrs to STL containers, we overload the < operator.
DerivedType & operator * () const
 Like a regular pointer; an InitSmartPtr is always valid, no assertions are done.
DerivedType * operator-> () const
 Like a regular pointer; an InitSmartPtr is always valid, no assertions are done.
bool is_ptr_valid () const
 InitSmartPointers are always valid.
bool operator< (const InitSmartPtr< BaseType > &other) const
 To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to.
bool operator< (const SmartPtr< BaseType > &other) const
 To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to.
bool is_stored_before (const InitSmartPtr< BaseType > &other) const
 In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.
bool is_stored_before (const SmartPtr< BaseType > &other) const
 In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.
bool is_unique () const
 Is the pointed-to-object unique?
int copies () const
 Returns number of references to this SmartPtr.
SmartPtr< const BaseType > const_ptr () const
 Will return a reference-counted pointer to const X, so that functions that promise not to change the object can ask for, and receive, SmartPtr<const X>.
bool operator== (const SmartPtr< BaseType > &other) const
 To enable easy mapping of SmartPtrs of ordered objects to STL containers, the == operator is overloaded to compare the objects being pointed to.
SmartPtr< D > recast ()
 Recast this SmartPtr to the desired type.
SmartPtr< const D > recast () const

Public Attributes

BaseType * ptr
 Internal pointer storage.
int * numCopies
 Internal number of copies storage.


Constructor & Destructor Documentation

template<class BaseType, class DerivedType>
code::InitDerivedSmartPtr< BaseType, DerivedType >::InitDerivedSmartPtr ( DerivedType *  p  )  [inline]

Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.

as a InitSmartPtr< DerivedType >

A DerivedType* is a BaseType* also.

It is implemented as a subclass of BaseType to make virtual overloading possible.

template<class BaseType, class DerivedType>
code::InitDerivedSmartPtr< BaseType, DerivedType >::InitDerivedSmartPtr ( InitSmartPtr< DerivedType >  orig  )  [inline]

Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.

as a InitSmartPtr< DerivedType >

A DerivedType* is a BaseType* also.

It is implemented as a subclass of BaseType to make virtual overloading possible.

template<class BaseType, class DerivedType>
code::InitDerivedSmartPtr< BaseType, DerivedType >::InitDerivedSmartPtr (  )  [inline]

Default initialization creates a new object.

A default constructor is necessary.


Member Function Documentation

SmartPtr<const BaseType > code::SmartPtr< BaseType >::const_ptr (  )  const [inline, inherited]

Will return a reference-counted pointer to const X, so that functions that promise not to change the object can ask for, and receive, SmartPtr<const X>.

int code::SmartPtr< BaseType >::copies (  )  const [inline, inherited]

Returns number of references to this SmartPtr.

template<class BaseType, class DerivedType>
InitSmartPtr< DerivedType > code::InitDerivedSmartPtr< BaseType, DerivedType >::getDerivedType (  )  [inline]

To obtain a derived object pointer.

This is faster than keeping around the DerivedSmartPtr object.

bool code::InitSmartPtr< BaseType >::is_ptr_valid (  )  const [inline, inherited]

InitSmartPointers are always valid.

Reimplemented from code::SmartPtr< BaseType >.

bool code::SmartPtr< BaseType >::is_stored_before ( const SmartPtr< BaseType > &  other  )  const [inline, inherited]

In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.

In that case, pointers need to be compared using is_stored_before()

When the objects themselves are ordered, you should be using the < operator.

bool code::InitSmartPtr< BaseType >::is_stored_before ( const InitSmartPtr< BaseType > &  other  )  const [inline, inherited]

In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.

In that case, pointers need to be compared using is_stored_before()

When the objects themselves are ordered, you should be using the < operator.

bool code::SmartPtr< BaseType >::is_unique (  )  const [inline, inherited]

Is the pointed-to-object unique?

You can use this function to determine whether there is anybody else holding references to this object.

Returns:
true if the pointed-to-object is unique and false if there are one or more other modules/classes holding references to this object.

template<class BaseType, class DerivedType>
DerivedType& code::InitDerivedSmartPtr< BaseType, DerivedType >::operator * (  )  const [inline]

Like a regular pointer; an InitSmartPtr is always valid, no assertions are done.

Reimplemented from code::InitSmartPtr< BaseType >.

template<class BaseType, class DerivedType>
DerivedType* code::InitDerivedSmartPtr< BaseType, DerivedType >::operator-> (  )  const [inline]

Like a regular pointer; an InitSmartPtr is always valid, no assertions are done.

Reimplemented from code::InitSmartPtr< BaseType >.

bool code::SmartPtr< BaseType >::operator< ( const SmartPtr< BaseType > &  other  )  const [inline, inherited]

To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to.

Hence, for this to be usable, the class X should have a < operator defined.

The behavior of the < and == operators is as follows:

  1. when neither pointer is valid, == would return true.
  2. when only one pointer is valid, the invalid pointer is always less than the valid pointer.
  3. when both pointers are valid, the objects pointed to are compared.

In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. In that case, pointers need to be compared. Use is_stored_before()

bool code::InitSmartPtr< BaseType >::operator< ( const InitSmartPtr< BaseType > &  other  )  const [inline, inherited]

To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to.

Hence, for this to be usable, the class X should have a < operator defined.

In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. In that case, pointers need to be compared. Use is_stored_before()

template<class BaseType, class DerivedType>
bool code::InitDerivedSmartPtr< BaseType, DerivedType >::operator< ( const InitDerivedSmartPtr< BaseType, DerivedType > &  other  )  const [inline]

To enable easy mapping of SmartPtrs to STL containers, we overload the < operator.

The meaning of < is to compare the objects being pointed to. Hence, for this to be usable, the class X should have a < operator defined.

bool code::SmartPtr< BaseType >::operator== ( const SmartPtr< BaseType > &  other  )  const [inline, inherited]

To enable easy mapping of SmartPtrs of ordered objects to STL containers, the == operator is overloaded to compare the objects being pointed to.

Hence, for this to be usable, the class X should have a == operator defined.

The behavior of the < and == operators is as follows:

  1. when neither pointer is valid, == would return true.
  2. when only one pointer is valid, the invalid pointer is always less than the valid pointer.
  3. when both pointers are valid, the objects pointed to are compared.

In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. In that case, pointers need to be compared. Use is_stored_before()

SmartPtr<const D> code::SmartPtr< BaseType >::recast (  )  const [inline, inherited]

SmartPtr<D> code::SmartPtr< BaseType >::recast (  )  [inline, inherited]

Recast this SmartPtr to the desired type.

An empty SmartPtr is returned if type conversion fails.

class A { ... }; class B: public A { ... }; class C: public B { ... }; class Unrelated { ... };

SmartPtr b = new C (); SmartPtr a = b.recast<A>(); // upcast SmartPtr<C> c = b.recast<C>(); // downcast assert (a.copies() == 3);

SmartPtr<Unrelated> u = b.recast<Unrelated>(); assert (!u.is_ptr_valid()); assert (a.copies() == 3);


Member Data Documentation

int* code::SmartPtr< BaseType >::numCopies [inherited]

Internal number of copies storage.

DerivedSmartPtr has access.

BaseType * code::SmartPtr< BaseType >::ptr [inherited]

Internal pointer storage.

DerivedSmartPtr has access.


Generated on Fri May 4 13:40:13 2012 for WDSS-IIw2 by  doxygen 1.4.7