#include <safecoll.h>
Inheritance diagram for PSafePtrBase:
Public Member Functions | |
void | Assign (const PSafePtrBase &ptr) |
void | Assign (const PSafeCollection &safeCollection) |
void | Assign (PSafeObject *obj) |
void | Assign (PINDEX idx) |
Overrides from class PObject | |
Comparison | Compare (const PObject &obj) const |
Operations | |
void | SetNULL () |
bool | operator! () const |
PSafetyMode | GetSafetyMode () const |
PBoolean | SetSafetyMode (PSafetyMode mode) |
const PSafeCollection * | GetCollection () const |
Protected Types | |
enum | EnterSafetyModeOption { WithReference, AlreadyReferenced } |
enum | ExitSafetyModeOption { WithDereference, NoDereference } |
Protected Member Functions | |
void | Next () |
void | Previous () |
PBoolean | EnterSafetyMode (EnterSafetyModeOption ref) |
void | ExitSafetyMode (ExitSafetyModeOption ref) |
Protected Attributes | |
const PSafeCollection * | collection |
PSafeObject * | currentObject |
PSafetyMode | lockMode |
This is part of a set of classes to solve the general problem of a collection (eg a PList or PDictionary) of objects that needs to be a made thread safe. Any thread can add, read, write or remove an object with both the object and the database of objects itself kept thread safe.
NOTE: the PSafePtr will allow safe and mutexed access to objects but is not thread safe itself! You should not share PSafePtr instances across threads. You can assign a PSafePtr to another instance across a thread boundary provided it is on a reference and no read only or read/write locks are present.
See the PSafeObject class for more details.
enum PSafePtrBase::EnterSafetyModeOption [protected] |
enum PSafePtrBase::ExitSafetyModeOption [protected] |
PSafePtrBase::PSafePtrBase | ( | PSafeObject * | obj = NULL , |
|
PSafetyMode | mode = PSafeReference | |||
) | [protected] |
Create a new pointer to a PSafeObject. An optional locking mode may be provided to lock the object for reading or writing and automatically unlock it on destruction.
Note that this version is not associated with a collection so the ++ and -- operators will not work.
obj | Physical object to point to. |
mode | Locking mode for the object |
PSafePtrBase::PSafePtrBase | ( | const PSafeCollection & | safeCollection, | |
PSafetyMode | mode, | |||
PINDEX | idx | |||
) | [protected] |
Create a new pointer to a PSafeObject. An optional locking mode may be provided to lock the object for reading or writing and automatically unlock it on destruction.
The idx'th entry of the collection is pointed to by this object. If the idx is beyond the size of the collection, the pointer is NULL.
safeCollection | Collection pointer will enumerate |
mode | Locking mode for the object |
idx | Index into collection to point to |
PSafePtrBase::PSafePtrBase | ( | const PSafeCollection & | safeCollection, | |
PSafetyMode | mode, | |||
PSafeObject * | obj | |||
) | [protected] |
Create a new pointer to a PSafeObject. An optional locking mode may be provided to lock the object for reading or writing and automatically unlock it on destruction.
The obj parameter is only set if it contained in the collection, otherwise the pointer is NULL.
safeCollection | Collection pointer will enumerate |
mode | Locking mode for the object |
obj | Inital object in collection to point to |
PSafePtrBase::PSafePtrBase | ( | const PSafePtrBase & | enumerator | ) | [protected] |
Copy the pointer to the PSafeObject. This will create a copy of the pointer with the same locking mode and lock on the PSafeObject. It will also increment the reference count on the PSafeObject as well.
enumerator | Pointer to copy |
PSafePtrBase::~PSafePtrBase | ( | ) |
Unlock and dereference the PSafeObject this is pointing to.
PSafePtrBase::PSafePtrBase | ( | PSafeObject * | obj = NULL , |
|
PSafetyMode | mode = PSafeReference | |||
) | [protected] |
Create a new pointer to a PSafeObject. An optional locking mode may be provided to lock the object for reading or writing and automatically unlock it on destruction.
Note that this version is not associated with a collection so the ++ and -- operators will not work.
obj | Physical object to point to. |
mode | Locking mode for the object |
PSafePtrBase::PSafePtrBase | ( | const PSafeCollection & | safeCollection, | |
PSafetyMode | mode, | |||
PINDEX | idx | |||
) | [protected] |
Create a new pointer to a PSafeObject. An optional locking mode may be provided to lock the object for reading or writing and automatically unlock it on destruction.
The idx'th entry of the collection is pointed to by this object. If the idx is beyond the size of the collection, the pointer is NULL.
safeCollection | Collection pointer will enumerate |
mode | Locking mode for the object |
idx | Index into collection to point to |
PSafePtrBase::PSafePtrBase | ( | const PSafeCollection & | safeCollection, | |
PSafetyMode | mode, | |||
PSafeObject * | obj | |||
) | [protected] |
Create a new pointer to a PSafeObject. An optional locking mode may be provided to lock the object for reading or writing and automatically unlock it on destruction.
The obj parameter is only set if it contained in the collection, otherwise the pointer is NULL.
safeCollection | Collection pointer will enumerate |
mode | Locking mode for the object |
obj | Inital object in collection to point to |
PSafePtrBase::PSafePtrBase | ( | const PSafePtrBase & | enumerator | ) | [protected] |
Copy the pointer to the PSafeObject. This will create a copy of the pointer with the same locking mode and lock on the PSafeObject. It will also increment the reference count on the PSafeObject as well.
enumerator | Pointer to copy |
PSafePtrBase::~PSafePtrBase | ( | ) |
Unlock and dereference the PSafeObject this is pointing to.
Comparison PSafePtrBase::Compare | ( | const PObject & | obj | ) | const [virtual] |
Compare the pointers. Note this is not a value comparison and will only return EqualTo if the two PSafePtrBase instances are pointing to the same instance.
obj | Other instance to compare against |
Reimplemented from PObject.
void PSafePtrBase::SetNULL | ( | ) |
Set the pointer to NULL, unlocking/dereferencing existing pointer value.
bool PSafePtrBase::operator! | ( | ) | const [inline] |
Return PTrue if pointer is NULL.
PSafetyMode PSafePtrBase::GetSafetyMode | ( | ) | const [inline] |
Get the locking mode used by this pointer.
PBoolean PSafePtrBase::SetSafetyMode | ( | PSafetyMode | mode | ) |
Change the locking mode used by this pointer.
mode | New locking mode |
const PSafeCollection* PSafePtrBase::GetCollection | ( | ) | const [inline] |
Get the associated collection this pointer may be contained in.
void PSafePtrBase::Assign | ( | const PSafePtrBase & | ptr | ) |
void PSafePtrBase::Assign | ( | const PSafeCollection & | safeCollection | ) |
void PSafePtrBase::Assign | ( | PSafeObject * | obj | ) |
void PSafePtrBase::Assign | ( | PINDEX | idx | ) |
void PSafePtrBase::Next | ( | ) | [protected] |
void PSafePtrBase::Previous | ( | ) | [protected] |
PBoolean PSafePtrBase::EnterSafetyMode | ( | EnterSafetyModeOption | ref | ) | [protected] |
void PSafePtrBase::ExitSafetyMode | ( | ExitSafetyModeOption | ref | ) | [protected] |
const PSafeCollection* PSafePtrBase::collection [protected] |
PSafeObject* PSafePtrBase::currentObject [protected] |
PSafetyMode PSafePtrBase::lockMode [protected] |