PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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 >:
[legend]
Collaboration diagram for PSharedPtr< T >:
[legend]

## 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)
PSharedPtr & | operator= (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...
PContainer & | operator= (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...
PBoolean | SetMinSize (PINDEX minSize)
| Set the minimum size of container. More...
virtual PBoolean | IsEmpty () const
| Determine if the container is empty. More...
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 PObject * | Clone () 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 PObject * | PTraceObjectInstance () 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
PContainerReference * | reference
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 PObject * | PTraceObjectInstance (const char *)
static __inline const PObject * | PTraceObjectInstance (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

References PSharedPtr< T >::CopyContents().

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

References PContainer::Destruct().

template<class T >

PSharedPtr< T >::PSharedPtr | ( | int | dummy,
|  | const PSharedPtr< T > * | c
| ) |  |
| inline protected

References PSharedPtr< T >::CloneContents().

## Member Function Documentation

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.

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 | ) |
| inline protected

References PSharedPtr< T >::ptr.

Referenced by PSharedPtr< T >::MakeUnique(), and PSharedPtr< T >::PSharedPtr().

template<class T >

void PSharedPtr< T >::CopyContents | ( | const PContainer & | c | ) |
| inline protected

References PSharedPtr< T >::ptr.

Referenced by PSharedPtr< T >::AssignContents(), and PSharedPtr< T >::PSharedPtr().

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 `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 | ( |  | ) |
| 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 > & | c | ) |
| inline

References PSharedPtr< T >::AssignContents().

template<class T >

void PSharedPtr< T >::Reset | ( |  | ) | const
| inline

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

template<class T >

PBoolean 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

Referenced by PSharedPtr< T >::CloneContents(), PSharedPtr< T >::CopyContents(), PSharedPtr< T >::DestroyContents(), PSharedPtr< T >::Get(), PSharedPtr< T >::operator*(), PSharedPtr< T >::operator->(), and PSharedPtr< T >::PSharedPtr().

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

- psharedptr.h