code::InitSmartPtr< X > Class Template Reference

Inheritance diagram for code::InitSmartPtr< X >:

code::SmartPtr< X > List of all members.

Detailed Description

template<class X>
class code::InitSmartPtr< X >

An InitSmartPtr is a SmartPtr.

The only difference is that on a default initialization, the InitSmartPtr does a new and thus, always creates a valid object.

Thus, many of the data accessors will be faster than SmartPtr when compiled without NDEBUG, simply because safety-assertions are not done.

See also:
: SmartPtr, InitSmartPtr, DerivedSmartPtr, InitDerivedSmartPtr
Author:
: Lakshman
Version:
:
Id
code_SmartPtr.h,v 1.31 2009/06/02 20:17:40 lakshman Exp


Public Member Functions

 InitSmartPtr (X *p)
 Initialization with a valid pointer (non-zero) is the same.
 InitSmartPtr ()
 Default initialization creates a new object.
 InitSmartPtr (const SmartPtr< X > &orig)
 Construction from a valid (non-zero) smart pointer is allowed.
bool is_ptr_valid () const
 InitSmartPointers are always valid.
bool operator< (const InitSmartPtr< X > &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< X > &other) const
 In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.
X & operator * () const
 Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid.
X * operator-> () const
 Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid.
 InitSmartPtr (X *p, int *n)
 Copy constructor out of the internal data of an already existing ptr.
bool is_unique () const
 Is the pointed-to-object unique?
int copies () const
 Returns number of references to this SmartPtr.
SmartPtr< const X > 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< X > &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< X > &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 SmartPtr< X > &other) const
 In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.
template<class D>
SmartPtr< D > recast ()
 Recast this SmartPtr to the desired type.
template<class D>
SmartPtr< const D > recast () const

Public Attributes

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


Constructor & Destructor Documentation

template<class X>
code::InitSmartPtr< X >::InitSmartPtr ( X *  p  )  [inline]

Initialization with a valid pointer (non-zero) is the same.

template<class X>
code::InitSmartPtr< X >::InitSmartPtr (  )  [inline]

Default initialization creates a new object.

A default constructor is necessary.

template<class X>
code::InitSmartPtr< X >::InitSmartPtr ( const SmartPtr< X > &  orig  )  [inline]

Construction from a valid (non-zero) smart pointer is allowed.

template<class X>
code::InitSmartPtr< X >::InitSmartPtr ( X *  p,
int *  n 
) [inline]

Copy constructor out of the internal data of an already existing ptr.


Member Function Documentation

template<class X>
SmartPtr<const X> code::SmartPtr< X >::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>.

template<class X>
int code::SmartPtr< X >::copies (  )  const [inline, inherited]

Returns number of references to this SmartPtr.

template<class X>
bool code::InitSmartPtr< X >::is_ptr_valid (  )  const [inline]

InitSmartPointers are always valid.

Reimplemented from code::SmartPtr< X >.

template<class X>
bool code::SmartPtr< X >::is_stored_before ( const SmartPtr< X > &  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.

template<class X>
bool code::InitSmartPtr< X >::is_stored_before ( const InitSmartPtr< X > &  other  )  const [inline]

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.

template<class X>
bool code::SmartPtr< X >::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 X>
X& code::InitSmartPtr< X >::operator * (  )  const [inline]

Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid.

Reimplemented from code::SmartPtr< X >.

Reimplemented in code::InitDerivedSmartPtr< BaseType, DerivedType >.

template<class X>
X* code::InitSmartPtr< X >::operator-> (  )  const [inline]

Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid.

Reimplemented from code::SmartPtr< X >.

Reimplemented in code::InitDerivedSmartPtr< BaseType, DerivedType >.

template<class X>
bool code::SmartPtr< X >::operator< ( const SmartPtr< X > &  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()

template<class X>
bool code::InitSmartPtr< X >::operator< ( const InitSmartPtr< X > &  other  )  const [inline]

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 X>
bool code::SmartPtr< X >::operator== ( const SmartPtr< X > &  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()

template<class X>
template<class D>
SmartPtr<const D> code::SmartPtr< X >::recast (  )  const [inline, inherited]

template<class X>
template<class D>
SmartPtr<D> code::SmartPtr< X >::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

template<class X>
int* code::SmartPtr< X >::numCopies [inherited]

Internal number of copies storage.

DerivedSmartPtr has access.

template<class X>
X* code::SmartPtr< X >::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