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]

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

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

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>
PSharedPtr& PSharedPtr< T >::operator= ( const PSharedPtr< T > &  c  )  [inline]

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.

template<class T>
BOOL PSharedPtr< T >::SetSize ( PINDEX   )  [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.

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

template<class T>
void PSharedPtr< T >::Reset (  )  const [inline]

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

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

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

Copy the container contents. This copies the contents from one reference to another.

No duplication of contents occurs, for instance if the container is an array, the pointer to the array memory is copied, not the array memory block itself.

This function will get called by the base assignment operator.

Reimplemented from PContainer.

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.

template<class T>
void PSharedPtr< T >::CloneContents ( const PContainer src  )  [inline, protected]

Create a duplicate of the container contents. This copies the contents from one container to another, unique container. It is automatically declared when the PDECLARE_CONTAINER()# macro is used.

This class will duplicate the contents completely, for instance if the container is an array, the actual array memory is copied, not just the pointer. If the container contains objects that descend from PObject#, they too should also be cloned and not simply copied.

This function will get called once for every class in the heirarchy, so the ancestor function should { not} be called.

{ { Note well}}, the logic of the function must be able to accept the passed in parameter to clone being the same instance as the destination object, ie during execution this == src#.

Reimplemented from PContainer.

template<class T>
void PSharedPtr< T >::CopyContents ( const PContainer c  )  [inline, protected]

Copy the container contents. This copies the contents from one reference to another. It is automatically declared when the PDECLARE_CONTAINER()# macro is used.

No duplication of contents occurs, for instance if the container is an array, the pointer to the array memory is copied, not the array memory block itself.

This function will get called once for every class in the heirarchy, so the ancestor function should { not} be called.

Reimplemented from 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 Fri Mar 7 06:25:07 2008 for PTLib by  doxygen 1.5.1