PSharedPtr< T > Class Template Reference

#include <psharedptr.h>

Inheritance diagram for PSharedPtr< T >:
PContainer PObject

List of all members.

Public Types

typedef T element_type

Public Member Functions

 PSharedPtr (element_type *_ptr=NULL)
 PSharedPtr (const PSharedPtr &c)
 PSharedPtr (std::auto_ptr< element_type > &v)
PSharedPtroperator= (const PSharedPtr &c)
virtual ~PSharedPtr ()
virtual BOOL MakeUnique ()
BOOL SetSize (PINDEX)
T * Get () const
void Reset () const
T & operator* () const
T * operator-> () const

Protected Member Functions

 PSharedPtr (int dummy, const PSharedPtr *c)
void AssignContents (const PContainer &c)
void DestroyContents ()
void CloneContents (const PContainer *src)
void CopyContents (const PContainer &c)

Protected Attributes

T * ptr

Detailed Description

template<class T>
class PSharedPtr< T >

These templates implement an pointner class with an integral reference count based on the PContainer base class. This allows the easy creation of an a reference counted ptr that will autodestruct when the last reference goes out of scope.


Member Typedef Documentation

template<class T >
typedef T PSharedPtr< T >::element_type

Constructor & Destructor Documentation

template<class T >
PSharedPtr< T >::PSharedPtr ( element_type _ptr = NULL  )  [inline]

References PSharedPtr< T >::ptr.

Referenced by PSharedPtr< T >::Reset().

template<class T >
PSharedPtr< T >::PSharedPtr ( const PSharedPtr< T > &  c  )  [inline]
template<class T >
PSharedPtr< T >::PSharedPtr ( std::auto_ptr< element_type > &  v  )  [inline]

References PSharedPtr< T >::ptr.

template<class T >
virtual PSharedPtr< T >::~PSharedPtr (  )  [inline, virtual]
template<class T >
PSharedPtr< T >::PSharedPtr ( int  dummy,
const PSharedPtr< T > *  c 
) [inline, protected]

Member Function Documentation

template<class T >
void PSharedPtr< T >::AssignContents ( const PContainer c  )  [inline, protected]
template<class T >
void PSharedPtr< T >::CloneContents ( const PContainer src  )  [inline, protected]
template<class T >
void PSharedPtr< T >::CopyContents ( const PContainer c  )  [inline, protected]
template<class T >
void PSharedPtr< T >::DestroyContents (  )  [inline, protected, virtual]

Destroy the container contents. This function must be defined by the descendent class to do the actual destruction of the contents. It is automatically declared when the PDECLARE_CONTAINER()# macro is used.

For all descendent classes not immediately inheriting off the PContainer itself, the implementation of DestroyContents() should always call its ancestors function. This is especially relevent if many of the standard container classes, such as arrays, are descended from as memory leaks will occur.

Implements PContainer.

References PSharedPtr< T >::ptr.

template<class T >
T* PSharedPtr< T >::Get (  )  const [inline]

References PSharedPtr< T >::ptr.

template<class T >
virtual BOOL PSharedPtr< T >::MakeUnique (  )  [inline, virtual]

Make this instance to be the one and only reference to the container contents. This implicitly does a clone of the contents of the container to make a unique reference. If the instance was already unique then the function does nothing.

Returns:
TRUE if the instance was already unique.

Reimplemented from PContainer.

References PSharedPtr< T >::CloneContents(), and PContainer::MakeUnique().

template<class T >
T& PSharedPtr< T >::operator* (  )  const [inline]

References PSharedPtr< T >::ptr.

template<class T >
T* PSharedPtr< T >::operator-> (  )  const [inline]

References PSharedPtr< T >::ptr.

template<class T >
PSharedPtr& PSharedPtr< T >::operator= ( const PSharedPtr< T > &  cont  )  [inline]

Assign one container reference to another. Set the current container to reference the same thing as the container specified in the parameter.

Note that the old contents of the container is dereferenced and if it was unique, destroyed using the DestroyContents() function.

Reimplemented from PContainer.

References PSharedPtr< T >::AssignContents().

template<class T >
void PSharedPtr< T >::Reset (  )  const [inline]
template<class T >
BOOL PSharedPtr< T >::SetSize ( PINDEX  newSize  )  [inline, virtual]

Set the new current size of the container. The exact behavious of this is determined by the descendent class. For instance an array class would reallocate memory to make space for the new number of elements.

Note for some types of containers this does not do anything as they inherently only contain one item. The function returns TRUE always and the new value is ignored.

Returns:
TRUE if the size was successfully changed. The value FALSE usually indicates failure due to insufficient memory.

Implements PContainer.


Member Data Documentation

template<class T >
T* PSharedPtr< T >::ptr [protected]

The documentation for this class was generated from the following file:

Generated on Sun Sep 6 03:50:37 2009 for PWLib by  doxygen 1.6.1