Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Attributes | List of all members
drwnOrderedMap< KeyType, ValueType > Class Template Reference

Provides a datastructure for that can be indexed by a KeyType (usually a string) or unsigned integer, i.e., the index. More...

Public Member Functions

 drwnOrderedMap ()
 default constructor
 
 drwnOrderedMap (const drwnOrderedMap< KeyType, ValueType > &m)
 copy constructor
 
 ~drwnOrderedMap ()
 destructor
 
void clear ()
 clear all entries from the map
 
size_t size () const
 returns the number of entries in the map
 
void insert (const KeyType &key, const ValueType &v)
 Inserts value v into the map at the end position with key key. If the key already exists then the value for the entry is replaced and it's index is unchanged.
 
void erase (const KeyType &key)
 remove the entry in the map corresponding to key key
 
int find (const KeyType &key) const
 find the index of an entry in the map (-1 if the key does not exist)
 
drwnOrderedMap< KeyType,
ValueType > & 
operator= (const drwnOrderedMap< KeyType, ValueType > &m)
 assignment operator
 
const ValueType & operator[] (unsigned int indx) const
 index the indx-th entry in the map
 
ValueType & operator[] (unsigned int indx)
 index the indx-th entry in the map
 
const ValueType & operator[] (const KeyType &key) const
 index the entry in the map with key key
 
ValueType & operator[] (const KeyType &key)
 index the entry in the map with key key
 

Protected Attributes

vector< pair< KeyType,
ValueType > * > 
_data
 
map< KeyType, unsigned > _index
 

Detailed Description

template<typename KeyType, typename ValueType>
class drwnOrderedMap< KeyType, ValueType >

Provides a datastructure for that can be indexed by a KeyType (usually a string) or unsigned integer, i.e., the index.

The unsigned integer variant indexes entries by insertion order. KeyType must be default constructable and cannot be an unsigned integer.

Example usage:

map.insert(string("bart"), 100);
map.insert(string("lisa"), 20);
map.insert(string("maggie"), 300);
cout << "'bart' has value " << map[string("bart")] << endl;
cout << "first entry has value " << map[0] << endl;
cout << "first entry has key " << map.find(string("bart")) << endl;

The documentation for this class was generated from the following file: