#include <dict.h>
Public Member Functions | |
Construction | |
POrdinalDictionary () | |
Overrides from class PObject | |
virtual PObject * | Clone () const |
New functions for class | |
PINDEX | operator[] (const K &key) const |
PBoolean | Contains (const K &key) const |
virtual POrdinalKey * | GetAt (const K &key) const |
virtual PBoolean | SetDataAt (PINDEX index, PINDEX ordinal) |
virtual PBoolean | SetAt (const K &key, PINDEX ordinal) |
virtual PINDEX | RemoveAt (const K &key) |
const K & | GetKeyAt (PINDEX index) const |
PINDEX | GetDataAt (PINDEX index) const |
Protected Member Functions | |
POrdinalDictionary (int dummy, const POrdinalDictionary *c) |
This template class maps the PAbstractDictionary to a specific key type and a POrdinalKey data type. The functions in this class primarily do all the appropriate casting of types.
Note that if templates are not used the PDECLARE_ORDINAL_DICTIONARY macro will simulate the template instantiation.
POrdinalDictionary< K >::POrdinalDictionary | ( | ) | [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.
Referenced by POrdinalDictionary< K >::Clone().
POrdinalDictionary< K >::POrdinalDictionary | ( | int | dummy, | |
const POrdinalDictionary< K > * | c | |||
) | [inline, protected] |
virtual PObject* POrdinalDictionary< K >::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.
References PNEW, and POrdinalDictionary< K >::POrdinalDictionary().
PBoolean POrdinalDictionary< K >::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. |
References PHashTable::AbstractContains().
virtual POrdinalKey* POrdinalDictionary< K >::GetAt | ( | const K & | key | ) | const [inline, virtual] |
key | Key for position in dictionary to get object. |
References PAbstractDictionary::AbstractGetAt().
Referenced by POrdinalDictionary< K >::RemoveAt().
PINDEX POrdinalDictionary< K >::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. |
References PHashTable::AbstractGetDataAt().
const K& POrdinalDictionary< K >::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. |
References PHashTable::AbstractGetKeyAt().
PINDEX POrdinalDictionary< K >::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.
References PAbstractDictionary::GetRefAt().
virtual PINDEX POrdinalDictionary< K >::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. |
References PAbstractDictionary::AbstractSetAt(), and POrdinalDictionary< K >::GetAt().
virtual PBoolean POrdinalDictionary< K >::SetAt | ( | const K & | key, | |
PINDEX | ordinal | |||
) | [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.
key | Key for position in dictionary to add object. | |
ordinal | New ordinal value to put into the dictionary. |
References PAbstractDictionary::AbstractSetAt(), and PNEW.
virtual PBoolean POrdinalDictionary< K >::SetDataAt | ( | PINDEX | index, | |
PINDEX | ordinal | |||
) | [inline, virtual] |
Set the data at the specified ordinal index position in the dictionary.
The ordinal position in the dictionary is determined by the hash values of the keys and the order of insertion.
index | Ordinal index in the dictionary. | |
ordinal | New ordinal value to put into the dictionary. |
References PNEW.