Rudiments
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)
 
bool remove (keytype key)
 
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 list 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 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 >
linkedlist< dictionarynode<keytype,valuetype> *>* dictionary< keytype, valuetype >::getList ( )

Returns the list used internally.

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 >
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 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".