Rudiments: dictionary< keytype, valuetype > Class Template Reference

Rudiments

- Main Page
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
dictionary< keytype, valuetype > Class Template Reference

## Public Member Functions
| dictionary ()
virtual | ~dictionary ()
void | setValue (keytype key, valuetype value)
bool | getValue (keytype key, valuetype *value)
dictionarynode< keytype, valuetype > * | getNode (keytype key)
valuetype | getValue (keytype key)
bool | remove (keytype key)
dictionarynode< keytype, valuetype > * | detach (keytype key)
linkedlist< keytype > * | getKeys ()
linkedlist< dictionarynode< keytype, valuetype > * > * | getList ()
void | clear ()
void | print ()

## Detailed Description

### template<class keytype, class valuetype>
class dictionary< keytype, valuetype >

The dictionary class allows you to store arbitrary numbers of key/value pairs.

Each dictionary is composed of a set of dictionarynodes. Each dictionarynode contains the key and value.

Internally, the dictionary class uses a linkedlist to store the values though this is potentially inefficient though, and may change in a future version.

## Constructor & Destructor Documentation

template<class keytype , class valuetype >

dictionary< keytype, valuetype >::dictionary | ( |  | ) |

Creates an empty instance of the dictionary class.

template<class keytype , class valuetype >

virtual dictionary< keytype, valuetype >::~dictionary | ( |  | ) |
| virtual

Deletes this instance of the dictionary class and all of its dictionarynodes. Note however, that neither the key nor value stored in each dictionarynode are deleted by this call.

## Member Function Documentation

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clear | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary.

template<class keytype , class valuetype >

dictionarynode<keytype,valuetype>* dictionary< keytype, valuetype >::detach | ( | keytype | key | ) |

Detaches the dictionarynode associated with "key". Returns the node on success or NULL if "key" wasn't found.

template<class keytype , class valuetype >

linkedlist< keytype >* dictionary< keytype, valuetype >::getKeys | ( |  | ) |

Returns a list of the keys in the dictionary.

Note that the linkedlist returned is allocated internally and returned. The calling program must delete the linkedlist.

template<class keytype , class valuetype >

linkedlist< dictionarynode<keytype,valuetype> *>* dictionary< keytype, valuetype >::getList | ( |  | ) |

Returns the list used internally.

template<class keytype , class valuetype >

dictionarynode<keytype,valuetype>* dictionary< keytype, valuetype >::getNode | ( | keytype | key | ) |

Returns the node associated with "key" or NULL if "key" wasn't found.

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::getValue | ( | keytype | key,
|  | valuetype * | value
| ) |  |

Sets "value" to the value associated with "key". Returns true on success or false if "key" wasn't found.

template<class keytype , class valuetype >

valuetype dictionary< keytype, valuetype >::getValue | ( | keytype | key | ) |

Returns the value associated with "key" or NULL if "key" wasn't found. Note that there is no way to distinguish between failure to find "key" and a valid value of NULL associated with "key".

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::print | ( |  | ) |

Prints out a representation of the dictionary.

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::remove | ( | keytype | key | ) |

Removes the dictionarynode associated with "key". Returns true on success or false if "key" wasn't found.

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::setValue | ( | keytype | key,
|  | valuetype | value
| ) |  |

Sets the value associated with "key" to "value". If "key" already exists, the value currently accociated with it is replaced with "value".