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

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

#include <safecoll.h>

Inheritance diagram for PSafeDictionaryBase< Coll, Key, Base >:
Collaboration diagram for PSafeDictionaryBase< Coll, Key, Base >:

Public Member Functions

Construction
 PSafeDictionaryBase ()
 Create a safe dictionary wrapper around the real collection. More...
 
 PSafeDictionaryBase (const PSafeDictionaryBase &other)
 Copy constructor for safe collection. More...
 
PSafeDictionaryBaseoperator= (const PSafeDictionaryBase &other)
 Assign one safe collection to another. More...
 
Operations
virtual void SetAt (const Key &key, Base *obj)
 Add an object to the collection. More...
 
virtual PBoolean RemoveAt (const Key &key)
 Remove an object to the collection. More...
 
virtual PBoolean Contains (const Key &key)
 Determine of the dictionary contains an entry for the key. More...
 
virtual PSafePtr< Base > GetAt (PINDEX idx, PSafetyMode mode=PSafeReadWrite)
 Get the instance in the collection of the index. More...
 
virtual PSafePtr< Base > Find (const Key &key, PSafetyMode mode=PSafeReadWrite) const
 Find the instance in the collection of an object with the same value. More...
 
virtual PSafePtr< Base > FindIterator (const Key &key, PSafetyMode mode=PSafeReadWrite) const
 Find instance and use PSafePtr as an iterator. More...
 
virtual P_DEPRECATED PSafePtr
< Base > 
FindWithLock (const Key &key, PSafetyMode mode=PSafeReadWrite) const
 
virtual bool Move (const Key &from, const Key &to)
 Move an object from one key location to another. More...
 
void MoveFrom (PSafeDictionaryBase &other)
 Move all objects from other dictionary to this one. More...
 
PArray< Key > GetKeys () const
 Get an array containing all the keys for the dictionary. 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
__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 PObjectPTraceObjectInstance () const
 
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 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 __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 PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (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...
 
- Protected Member Functions inherited from PSafeCollection
void CopySafeCollection (PCollection *other)
 
void CopySafeDictionary (PAbstractDictionary *other)
 
bool SafeAddObject (PSafeObject *obj, PSafeObject *old)
 
void SafeRemoveObject (PSafeObject *obj)
 
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 Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 
- Protected Attributes inherited from PSafeCollection
PCollectionm_collection
 
PMutex m_collectionMutex
 
bool m_deleteObjects
 
PList< PSafeObjectm_toBeRemoved
 
PMutex m_removalMutex
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Detailed Description

template<class Coll, class Key, class Base>
class PSafeDictionaryBase< Coll, Key, Base >

This class defines a thread-safe dictionary 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 Key, class Base>
PSafeDictionaryBase< Coll, Key, Base >::PSafeDictionaryBase ( )
inline

Create a safe dictionary wrapper around the real collection.

template<class Coll, class Key, class Base>
PSafeDictionaryBase< Coll, Key, Base >::PSafeDictionaryBase ( const PSafeDictionaryBase< Coll, Key, 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 Key, class Base>
virtual PBoolean PSafeDictionaryBase< Coll, Key, Base >::Contains ( const Key &  key)
inlinevirtual

Determine of the dictionary contains an entry for the key.

Referenced by PSafeDictionaryBase< PDictionary< K, D >, K, D >::Contains().

template<class Coll, class Key, class Base>
virtual PSafePtr<Base> PSafeDictionaryBase< Coll, Key, Base >::Find ( const Key &  key,
PSafetyMode  mode = PSafeReadWrite 
) const
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.

Referenced by PSafeDictionary< K, D >::iterator_base::SetPosition().

template<class Coll, class Key, class Base>
virtual PSafePtr<Base> PSafeDictionaryBase< Coll, Key, Base >::FindIterator ( const Key &  key,
PSafetyMode  mode = PSafeReadWrite 
) const
inlinevirtual

Find instance and use PSafePtr as an iterator.

This is not recommended for use, as the there is a true iterator class available which is much more efficient

Referenced by PSafeDictionaryBase< PDictionary< K, D >, K, D >::FindWithLock().

template<class Coll, class Key, class Base>
virtual P_DEPRECATED PSafePtr<Base> PSafeDictionaryBase< Coll, Key, Base >::FindWithLock ( const Key &  key,
PSafetyMode  mode = PSafeReadWrite 
) const
inlinevirtual
template<class Coll, class Key, class Base>
virtual PSafePtr<Base> PSafeDictionaryBase< Coll, Key, 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.

Referenced by PSafeDictionaryBase< PDictionary< K, D >, K, D >::Find(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::FindIterator(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::Move(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::RemoveAt(), and PSafeDictionaryBase< PDictionary< K, D >, K, D >::SetAt().

template<class Coll, class Key, class Base>
PArray<Key> PSafeDictionaryBase< Coll, Key, Base >::GetKeys ( ) const
inline

Get an array containing all the keys for the dictionary.

template<class Coll, class Key, class Base>
virtual bool PSafeDictionaryBase< Coll, Key, Base >::Move ( const Key &  from,
const Key &  to 
)
inlinevirtual

Move an object from one key location to another.

Parameters
fromKey to find object to move
toKey to place found object
template<class Coll, class Key, class Base>
void PSafeDictionaryBase< Coll, Key, Base >::MoveFrom ( PSafeDictionaryBase< Coll, Key, Base > &  other)
inline

Move all objects from other dictionary to this one.

This will delete all the objects from the other dictionary, but does not delete the objects themselves.

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

Assign one safe collection to another.

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

template<class Coll, class Key, class Base>
virtual PBoolean PSafeDictionaryBase< Coll, Key, Base >::RemoveAt ( const Key &  key)
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
keyKey to find object to delete
template<class Coll, class Key, class Base>
virtual void PSafeDictionaryBase< Coll, Key, Base >::SetAt ( const Key &  key,
Base *  obj 
)
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.

Referenced by PSafeDictionaryBase< PDictionary< K, D >, K, D >::Move(), and PSafeDictionaryBase< PDictionary< K, D >, K, D >::SetAt().


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