|
Two-way mapping between strings and objects of template class T. More...
#include <Dictionary.h>
Public Types | |
typedef K | key_t |
typedef V | value_t |
typedef std::pair< K, V > | entry_t |
typedef std::list< entry_t > | container_t |
typedef std::list< key_t > | keylist_t |
typedef std::list< value_t > | valuelist_t |
Public Member Functions | |
Dictionary (const Dictionary &d) | |
Dictionary (std::initializer_list< entry_t > d) | |
const container_t & | getContainer () const |
entry_t & | add (const K &key, const V &value) |
entry_t & | set (const K &key, const V &value) |
Replaces existing or adds. | |
const V & | operator[] (const K &key) const |
const V & | operator() (const V &value) const |
container_t::const_iterator | findByKey (const K &key) const |
container_t::const_iterator | findByValue (const V &value) const |
bool | hasKey (const K &key) const |
bool | hasValue (const V &value) const |
Given a key, return the first value associated with it. | |
const V & | getValue (const K &key) const |
Given a key, return the first value associated with it. | |
const K & | getKey (const V &value) const |
Given a value, return the first key associated with it. | |
const keylist_t & | getKeys () const |
void | getKeys (keylist_t &l) const |
const valuelist_t & | getValues () const |
void | getValues (keylist_t &l) const |
Public Attributes | |
char | separator |
Protected Attributes | |
keylist_t | keyList |
valuelist_t | valueList |
Two-way mapping between strings and objects of template class T.
TODO: hide first and second so that an entry cannot be assigned to either of them Simple list based container for small dictionaries. Uses brute-force linear search.
In a way, works like std::map as each entry is a std::pair. However, no less-than relation is needed as the entries are not in order but appended sequentially.
For handling input and output, dictionary has a separator char which is a comma ',' by default.