PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSafeColl< Coll, Base > Class Template Reference

This class defines a thread-safe collection of objects. More...

#include <safecoll.h>

Inheritance diagram for PSafeColl< Coll, Base >:
Collaboration diagram for PSafeColl< Coll, Base >:

Public Member Functions

Construction
 PSafeColl ()
 Create a safe list collection wrapper around the real collection. More...
 
 PSafeColl (const PSafeColl &other)
 Copy constructor for safe collection. More...
 
PSafeColloperator= (const PSafeColl &other)
 Assign one safe collection to another. More...
 
Operations
virtual PSafePtr< Base > Append (Base *obj, PSafetyMode mode=PSafeReference)
 Add an object to the collection. More...
 
virtual PBoolean Remove (Base *obj)
 Remove an object to the collection. More...
 
virtual PBoolean RemoveAt (PINDEX idx)
 Remove an object to the collection. More...
 
virtual PSafePtr< Base > GetAt (PINDEX idx, PSafetyMode mode=PSafeReadWrite)
 Get the instance in the collection of the index. More...
 
virtual PSafePtr< Base > FindWithLock (const Base &value, PSafetyMode mode=PSafeReadWrite)
 Find the instance in the collection of an object with the same value. More...
 
- Public Member Functions inherited from PSafeCollection
 PSafeCollection (PCollection *collection)
 Create a thread safe collection of objects. More...
 
 ~PSafeCollection ()
 Destroy the thread safe collection. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void RemoveAll (PBoolean synchronous=false)
 Remove all objects in collection. More...
 
void AllowDeleteObjects (PBoolean yes=true)
 Disallow the automatic delete any objects that have been removed. More...
 
void DisallowDeleteObjects ()
 Disallow the automatic delete any objects that have been removed. More...
 
virtual PBoolean DeleteObjectsToBeRemoved ()
 Delete any objects that have been removed. More...
 
virtual void DeleteObject (PObject *object) const
 Delete an objects that has been removed. More...
 
virtual void SetAutoDeleteObjects ()
 Start a timer to automatically call DeleteObjectsToBeRemoved(). More...
 
PINDEX GetSize () const
 Get the current size of the collection. More...
 
PBoolean IsEmpty () const
 Determine if the collection is empty. More...
 
const PMutexGetMutex () const
 Get the mutex for the collection. More...
 
PMutexGetMutex ()
 
- 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 PObjectClone () 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 PObjectPTraceObjectInstance () 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 ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

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 PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (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 PSafeCollection
void CopySafeCollection (PCollection *other)
 
void CopySafeDictionary (PAbstractDictionary *other)
 
bool SafeAddObject (PSafeObject *obj, PSafeObject *old)
 
void SafeRemoveObject (PSafeObject *obj)
 
 PDECLARE_NOTIFIER (PTimer, PSafeCollection, DeleteObjectsTimeout)
 
virtual PBoolean SafeRemove (PSafeObject *obj)
 Remove an object to the collection. More...
 
virtual PBoolean SafeRemoveAt (PINDEX idx)
 Remove an object to the collection. More...
 
- Protected Attributes inherited from PSafeCollection
PCollectioncollection
 
PMutex collectionMutex
 
bool deleteObjects
 
PList< PSafeObjecttoBeRemoved
 
PMutex removalMutex
 
PTimerm_deleteObjectsTimer
 
- Friends inherited from PObject

Detailed Description

template<class Coll, class Base>
class PSafeColl< Coll, Base >

This class defines a thread-safe collection of objects.

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.

See the PSafeObject class for more details. Especially in regard to enumeration of collections.

Constructor & Destructor Documentation

template<class Coll, class Base>
PSafeColl< Coll, Base >::PSafeColl ( )
inline

Create a safe list collection wrapper around the real collection.

template<class Coll, class Base>
PSafeColl< Coll, Base >::PSafeColl ( const PSafeColl< Coll, Base > &  other)
inline

Copy constructor for safe collection.

Note the left hand side will always have DisallowDeleteObjects() set.

Member Function Documentation

template<class Coll, class Base>
virtual PSafePtr<Base> PSafeColl< Coll, Base >::Append ( Base *  obj,
PSafetyMode  mode = PSafeReference 
)
inlinevirtual

Add an object to the collection.

This uses the PCollection::Append() function to add the object to the collection, with full mutual exclusion locking on the collection.

Parameters
objObject to add to safe collection.
modeSafety mode for returned locked PSafePtr
template<class Coll, class Base>
virtual PSafePtr<Base> PSafeColl< Coll, Base >::FindWithLock ( const Base &  value,
PSafetyMode  mode = PSafeReadWrite 
)
inlinevirtual

Find the instance in the collection of an object with the same value.

The returned safe pointer will increment the reference count on the PSafeObject and lock to the object in the mode specified. The lock will remain until the PSafePtr goes out of scope.

template<class Coll, class Base>
virtual PSafePtr<Base> PSafeColl< Coll, Base >::GetAt ( PINDEX  idx,
PSafetyMode  mode = PSafeReadWrite 
)
inlinevirtual

Get the instance in the collection of the index.

The returned safe pointer will increment the reference count on the PSafeObject and lock to the object in the mode specified. The lock will remain until the PSafePtr goes out of scope.

template<class Coll, class Base>
PSafeColl& PSafeColl< Coll, Base >::operator= ( const PSafeColl< Coll, Base > &  other)
inline

Assign one safe collection to another.

Note the left hand side will always have DisallowDeleteObjects() set.

template<class Coll, class Base>
virtual PBoolean PSafeColl< Coll, Base >::Remove ( Base *  obj)
inlinevirtual

Remove an object to the collection.

This function removes the object from the collection itself, but does not actually delete the object. It simply moves the object to a list of objects to be garbage collected at a later time.

As for Append() full mutual exclusion locking on the collection itself is maintained.

Parameters
objObject to remove from safe collection
template<class Coll, class Base>
virtual PBoolean PSafeColl< Coll, Base >::RemoveAt ( PINDEX  idx)
inlinevirtual

Remove an object to the collection.

This function removes the object from the collection itself, but does not actually delete the object. It simply moves the object to a list of objects to be garbage collected at a later time.

As for Append() full mutual exclusion locking on the collection itself is maintained.

Parameters
idxIndex to remove

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