Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Phx::Ptr< T > Class Template Reference

A smart-pointer class for intrusive pointers. More...

#include <PhxPtr.h>

List of all members.

Public Member Functions

 Ptr (T *p)
 Ptr (const Ptr< T > &p)
template<class Y>
 Ptr (const Ptr< Y > &p)
const Ptr< T > & operator= (const Ptr< T > &rhs)
bool operator< (const Ptr< T > &rhs)
bool operator== (const Ptr< T > &rhs) const
T * operator-> () const
T & operator * () const
bool operator! () const
 operator bool () const
T * ptr () const
 Accesses the raw pointer from within this smart-pointer.
template<class Y>
Ptr< Y > dynamicCast (void) const
 Dynamic cast convenience method.
template<class Y>
Ptr< Y > staticCast (void) const
 Static cast convenience method.


Detailed Description

template<class T>
class Phx::Ptr< T >

A smart-pointer class for intrusive pointers.

An "intrusive" pointer is one that operates by embedding the reference-count management into the object being pointed to. This is in contrast to the "non-intrusive" method that allocates a separate piece of shared data to manage the count.

As a result of this, not any class can be used as the template parameter T used by this Ptr type. There is a standard interface that the Ptr template requires of the object type.

void T::newReference(void) is called every time a new reference is created; that is, every time a new pointer to the object comes into existance.

void T::deleteReference(void) is called every time a reference is destroyed; that is, every time a pointer to the object goes out of scope and is destructed.


Member Function Documentation

template<class T>
template<class Y>
Ptr<Y> Phx::Ptr< T >::dynamicCast void   )  const [inline]
 

Dynamic cast convenience method.

Normally, to perform a dynamic cast between smart pointers, we could do the following:

 Ptr<T>  t(new T());
 Ptr<Y>  y(dynamic_cast<Y*>(t.ptr()); 

This method simplifies this expression to a single call:

 Ptr<T>  t(new T());
 Ptr<Y>  y(t.dynamicCast<Y>()); 

template<class T>
Phx::Ptr< T >::operator bool  )  const [inline]
 

Todo:
Implicit conversion to bool is unsafe. There is a safer approach, but it may be non-portable

template<class T>
T* Phx::Ptr< T >::ptr  )  const [inline]
 

Accesses the raw pointer from within this smart-pointer.

Returns:
The raw pointer contained by this Ptr object.

template<class T>
template<class Y>
Ptr<Y> Phx::Ptr< T >::staticCast void   )  const [inline]
 

Static cast convenience method.

Normally, to perform a static cast between smart pointers, we could do the following:

 Ptr<T>  t(new T());
 Ptr<Y>  y(static_cast<Y*>(t.ptr()); 

This method simplifies this expression to a single call:

 Ptr<T>  t(new T());
 Ptr<Y>  y(t.staticCast<Y>()); 


The documentation for this class was generated from the following file:
Generated on Wed Dec 21 22:05:39 2005 for Phoenix OSFS by  doxygen 1.4.2