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
Protected Attributes | List of all members
PSmartPointer Class Reference

This is the class for pointers to objects that use the smart pointer system. More...

`#include <smartptr.h>`

Inheritance diagram for PSmartPointer:
[legend]
Collaboration diagram for PSmartPointer:
[legend]

## Public Member Functions
Construction
| PSmartPointer (PSmartObject *obj=NULL)
| Create a new smart pointer instance and have it point to the specified `PSmartObject` instance. More...
| PSmartPointer (const PSmartPointer &ptr)
| Create a new smart pointer and point it at the data pointed to by the `ptr` parameter. More...
virtual | ~PSmartPointer ()
| Destroy the smart pointer and decrement the reference count on the object being pointed to. More...
PSmartPointer & | operator= (const PSmartPointer &ptr)
| Assign this pointer to the value specified in the `ptr` parameter. More...
Overrides from class PObject
virtual Comparison | Compare (const PObject &obj) const
| Determine the relative rank of the pointers. More...
Pointer access functions
PBoolean | IsNULL () const
| Determine if the smart pointer has been set to point to an actual object instance. More...
PSmartObject * | GetObject () const
| Get the current value if the internal smart object pointer. 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 | 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 Attributes
PSmartObject * | object
| Object the smart pointer points to. More...
Protected Attributes inherited from PObject
unsigned | m_traceContextIdentifier

## Additional Inherited Members
Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...
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...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...
Friends inherited from PObject

## Detailed Description

This is the class for pointers to objects that use the smart pointer system.

In conjunction with the `PSmartObject` class, this class references objects that can have the automatic deletion of the object instance when there are no more smart pointer instances pointing to it.

A PSmartPointer carries the pointer to a `PSmartObject` instance which contains a reference count. Assigning or copying instances of smart pointers will automatically increment and decrement the reference count. When the last instance that references a `PSmartObject` instance is destroyed or overwritten, the `PSmartObject` is deleted.

A NULL value is possible for a smart pointer. It can be detected via the `IsNULL()` function.

## Constructor & Destructor Documentation

PSmartPointer::PSmartPointer | ( | PSmartObject * | obj = `NULL` | ) |
| inline

Create a new smart pointer instance and have it point to the specified `PSmartObject` instance.

Parameters

  obj | Smart object to point to.

PSmartPointer::PSmartPointer | ( | const PSmartPointer & | ptr | ) |

Create a new smart pointer and point it at the data pointed to by the `ptr` parameter.

The reference count for the object being pointed at is incremented.

Parameters

  ptr | Smart pointer to make a copy of.

virtual PSmartPointer::~PSmartPointer | ( |  | ) |
| virtual

Destroy the smart pointer and decrement the reference count on the object being pointed to.

If there are no more references then the object is deleted.

## Member Function Documentation

virtual Comparison PSmartPointer::Compare | ( | const PObject & | obj | ) | const
| virtual

Determine the relative rank of the pointers.

This is identical to determining the relative rank of the integer values represented by the memory pointers.

Returns
  `EqualTo` if objects point to the same object instance, otherwise `LessThan` and `GreaterThan` may be returned depending on the relative values of the memory pointers.

Parameters

  obj | Other smart pointer to compare against.

Reimplemented from PObject.

PSmartObject* PSmartPointer::GetObject | ( |  | ) | const
| inline

Get the current value if the internal smart object pointer.

Returns
  pointer to object instance.

References object.

Referenced by PNotifierTemplate< PChannel::AsyncContext & >::GetTarget(), PNotifierTemplate< PChannel::AsyncContext & >::operator()(), and PNotifierListTemplate< ParamType >::IsObj::operator()().

PBoolean PSmartPointer::IsNULL | ( |  | ) | const
| inline

Determine if the smart pointer has been set to point to an actual object instance.

Returns
  true if the pointer is NULL.

PSmartPointer& PSmartPointer::operator= | ( | const PSmartPointer & | ptr | ) |

Assign this pointer to the value specified in the `ptr` parameter.

The previous object being pointed to has its reference count decremented as this will no longer point to it. If there are no more references then the object is deleted.

The new object being pointed to after the assignment has its reference count incremented.

Parameters

  ptr | Smart pointer to assign.

## Member Data Documentation

PSmartObject* PSmartPointer::object
| protected

Object the smart pointer points to.

Referenced by GetObject(), and PSmartPtr< T >::operator T *().

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

- smartptr.h