PTLib  Version 2.18.8
 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 Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 

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...
 
element_typeget () const
 
P_DEPRECATED element_typeGet () const
 
void reset (element_type *p=NULL)
 
P_DEPRECATED void Reset ()
 
element_typeoperator* () const
 
element_typeoperator-> () 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
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
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 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

element_typeptr
 
- 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 __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 

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
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 ( )
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.

Referenced by PSharedPtr< PExternalThread >::operator=(), PSharedPtr< PExternalThread >::reset(), and PSharedPtr< PExternalThread >::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.

template<class T>
element_type* PSharedPtr< T >::get ( ) const
inline
template<class T>
P_DEPRECATED element_type* PSharedPtr< T >::Get ( ) const
inline
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.

template<class T>
element_type& PSharedPtr< T >::operator* ( ) const
inline
template<class T>
element_type* PSharedPtr< T >::operator-> ( ) const
inline
template<class T>
PSharedPtr& PSharedPtr< T >::operator= ( const PSharedPtr< T > &  c)
inline
template<class T>
void PSharedPtr< T >::reset ( element_type p = NULL)
inline
template<class T>
P_DEPRECATED void PSharedPtr< T >::Reset ( )
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: