PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSharedPtr< T > Class Template Reference

These templates implement an pointner class with an integral reference count based on the PContainer base class. More...

#include <psharedptr.h>

Inheritance diagram for PSharedPtr< T >:
Collaboration diagram for PSharedPtr< T >:

Public Types

typedef T element_type
 

Public Member Functions

 PSharedPtr (element_type *p=NULL)
 
 PSharedPtr (const PSharedPtr &c)
 
 PSharedPtr (std::auto_ptr< element_type > &v)
 
PSharedPtroperator= (const PSharedPtr &c)
 
virtual ~PSharedPtr ()
 
virtual PBoolean MakeUnique ()
 Make this instance to be the one and only reference to the container contents. More...
 
PBoolean SetSize (PINDEX)
 Set the new current size of the container. More...
 
T * Get () const
 
void Reset () const
 
T & operator* () const
 
T * operator-> () const
 
- Public Member Functions inherited from PContainer
 PContainer (PINDEX initialSize=0)
 Create a new unique container. More...
 
 PContainer (const PContainer &cont)
 Create a new refernce to container. More...
 
PContaineroperator= (const PContainer &cont)
 Assign one container reference to another. More...
 
virtual ~PContainer ()
 Destroy the container class. More...
 
virtual PINDEX GetSize () const
 Get the current size of the container. More...
 
__inline size_t size () const
 
PBoolean SetMinSize (PINDEX minSize)
 Set the minimum size of container. More...
 
virtual PBoolean IsEmpty () const
 Determine if the container is empty. More...
 
__inline bool empty () const
 
PBoolean IsUnique () const
 Determine if container is unique reference. More...
 
- Public Member Functions inherited from PObject
unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
void SetTraceContextIdentifier (unsigned id)
 
void GetTraceContextIdentifier (PObject &obj)
 
void GetTraceContextIdentifier (PObject *obj)
 
void SetTraceContextIdentifier (const PObject &obj)
 
void SetTraceContextIdentifier (const PObject *obj)
 
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
__inline const PObjectPTraceObjectInstance () const
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Member Functions

 PSharedPtr (int dummy, const PSharedPtr *c)
 
void AssignContents (const PContainer &c)
 Copy the container contents. More...
 
void DestroyContents ()
 Destroy the container contents. More...
 
void CloneContents (const PContainer *src)
 
void CopyContents (const PContainer &c)
 
- Protected Member Functions inherited from PContainer
 PContainer (int dummy, const PContainer *cont)
 Constructor used in support of the Clone() function. More...
 
 PContainer (PContainerReference &reference)
 Construct using static PContainerReference. More...
 
void CopyContents (const PContainer &c)
 Copy the container contents. More...
 
void CloneContents (const PContainer *src)
 Create a duplicate of the container contents. More...
 
void Destruct ()
 Internal function called from container destructors. More...
 
virtual void DestroyReference ()
 Destroy the PContainerReference instance. More...
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

T * ptr
 
- Protected Attributes inherited from PContainer
PContainerReferencereference
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Additional Inherited Members

- Static Public Member Functions inherited from PObject
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Friends inherited from PObject

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 p = 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 ( )
inlinevirtual
template<class T >
PSharedPtr< T >::PSharedPtr ( int  dummy,
const PSharedPtr< T > *  c 
)
inlineprotected

Member Function Documentation

template<class T >
void PSharedPtr< T >::AssignContents ( const PContainer c)
inlineprotectedvirtual

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.

References PContainer::AssignContents(), and PSharedPtr< T >::CopyContents().

Referenced by PSharedPtr< T >::operator=(), and PSharedPtr< T >::Reset().

template<class T >
void PSharedPtr< T >::CloneContents ( const PContainer src)
inlineprotected
template<class T >
void PSharedPtr< T >::CopyContents ( const PContainer c)
inlineprotected
template<class T >
void PSharedPtr< T >::DestroyContents ( )
inlineprotectedvirtual

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 PCONTAINERINFO() 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 PBoolean PSharedPtr< T >::MakeUnique ( )
inlinevirtual

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 > &  c)
inline
template<class T >
void PSharedPtr< T >::Reset ( ) const
inline
template<class T >
PBoolean PSharedPtr< T >::SetSize ( PINDEX  newSize)
inlinevirtual

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


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