PTLib
Version 2.18.8
|
These templates implement an pointner class with an integral reference count based on the PContainer base class. More...
#include <psharedptr.h>
Public Types | |
typedef T | element_type |
![]() | |
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) | |
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... | |
element_type * | get () const |
P_DEPRECATED element_type * | Get () const |
void | reset (element_type *p=NULL) |
P_DEPRECATED void | Reset () |
element_type & | operator* () const |
element_type * | operator-> () const |
![]() | |
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... | |
__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... | |
![]() | |
__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 PObject * | PTraceObjectInstance () const |
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 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) |
![]() | |
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... | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Protected Attributes | |
element_type * | ptr |
![]() | |
PContainerReference * | reference |
![]() | |
unsigned | m_traceContextIdentifier |
Additional Inherited Members | |
![]() | |
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 PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (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... | |
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.
typedef T PSharedPtr< T >::element_type |
|
inline |
Referenced by PSharedPtr< PExternalThread >::reset(), and PSharedPtr< PExternalThread >::Reset().
|
inline |
|
inline |
|
inlinevirtual |
|
inlineprotected |
|
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().
|
inlineprotected |
|
inlineprotected |
|
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.
|
inline |
|
inline |
|
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.
Reimplemented from PContainer.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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.
Implements PContainer.
|
protected |
Referenced by PSharedPtr< PExternalThread >::CloneContents(), PSharedPtr< PExternalThread >::CopyContents(), PSharedPtr< PExternalThread >::DestroyContents(), PSharedPtr< PExternalThread >::get(), PSharedPtr< PExternalThread >::Get(), PSharedPtr< PExternalThread >::operator*(), PSharedPtr< PExternalThread >::operator->(), and PSharedPtr< PExternalThread >::PSharedPtr().