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