#include <dict.h>
Inheritance diagram for PDictionary< K, D >:
Public Types | |
typedef std::pair< K, D * > | value_type |
Public Member Functions | |
Construction | |
PDictionary () | |
Overrides from class PObject | |
virtual PObject * | Clone () const |
New functions for class | |
D & | operator[] (const K &key) const |
PBoolean | Contains (const K &key) const |
virtual D * | RemoveAt (const K &key) |
virtual PBoolean | SetAt (const K &key, D *obj) |
virtual D * | GetAt (const K &key) const |
const K & | GetKeyAt (PINDEX index) const |
D & | GetDataAt (PINDEX index) const |
Protected Member Functions | |
PDictionary (int dummy, const PDictionary *c) |
Note that if templates are not used the PDECLARE_DICTIONARY macro will simulate the template instantiation.
typedef std::pair<K, D *> PDictionary< K, D >::value_type |
PDictionary< K, D >::PDictionary | ( | ) | [inline] |
Create a new, empty, dictionary.
Note that by default, objects placed into the dictionary will be deleted when removed or when all references to the dictionary are destroyed.
PDictionary< K, D >::PDictionary | ( | int | dummy, | |
const PDictionary< K, D > * | c | |||
) | [inline, protected] |
virtual PObject* PDictionary< K, D >::Clone | ( | ) | const [inline, virtual] |
Make a complete duplicate of the dictionary. Note that all objects in the array are also cloned, so this will make a complete copy of the dictionary.
Reimplemented from PObject.
PBoolean PDictionary< K, D >::Contains | ( | const K & | key | ) | const [inline] |
Determine if the value of the object is contained in the hash table. The object values are compared, not the pointers. So the objects in the collection must correctly implement the PObject::Compare() function. The hash table is used to locate the entry.
key | Key to look for in the dictionary. |
virtual D* PDictionary< K, D >::GetAt | ( | const K & | key | ) | const [inline, virtual] |
Get the object at the specified key position. If the key was not in the collection then NULL is returned.
D& PDictionary< K, D >::GetDataAt | ( | PINDEX | index | ) | const [inline] |
Get the data in the dictionary at the ordinal index position.
The ordinal position in the dictionary is determined by the hash values of the keys and the order of insertion.
The last key/data pair is remembered by the class so that subseqent access is very fast.
index | Ordinal position in dictionary for data. |
const K& PDictionary< K, D >::GetKeyAt | ( | PINDEX | index | ) | const [inline] |
Get the key in the dictionary at the ordinal index position.
The ordinal position in the dictionary is determined by the hash values of the keys and the order of insertion.
The last key/data pair is remembered by the class so that subseqent access is very fast.
index | Ordinal position in dictionary for key. |
D& PDictionary< K, D >::operator[] | ( | const K & | key | ) | const [inline] |
Get the object contained in the dictionary at the key
position. The hash table is used to locate the data quickly via the hash function provided by the key
.
The last key/data pair is remembered by the class so that subseqent access is very fast.
key | Key to look for in the dictionary. |
virtual D* PDictionary< K, D >::RemoveAt | ( | const K & | key | ) | [inline, virtual] |
Remove an object at the specified key
. The returned pointer is then removed using the SetAt() function to set that key value to NULL. If the AllowDeleteObjects option is set then the object is also deleted.
key | Key for position in dictionary to get object. |
virtual PBoolean PDictionary< K, D >::SetAt | ( | const K & | key, | |
D * | obj | |||
) | [inline, virtual] |
Add a new object to the collection. If the objects value is already in the dictionary then the object is overrides the previous value. If the AllowDeleteObjects option is set then the old object is also deleted.
The object is placed in the an ordinal position dependent on the keys hash function. Subsequent searches use the hash function to speed access to the data item.