Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

lrt::Map Class Template Reference

A map collection type (a.k.a. associative array). More...

#include <rtmap.h>

List of all members.

Public Types

typedef Iterator< Pair< K,
V > > 
Iterator
 The map iterator type: You can alternatively use Iterator<Map<K,V>::Pair> or Map<K,V>::Iterator (which is somewhat shorter).


Public Methods

 Map ()
 Creates a new empty map. More...

 Map (int(*compareFun)(const K &, const K &))
 Creates a new empty map, whose entries are sorted with a given comparison function.

 Map (const Map &)
 Creates a new map, copying all the contents over from the given map.

virtual ~Map ()
const Map & operator= (const Map &)
 Clears this map, then copies all the contents of the given map into it.

bool isSet (const K &) const
 Returns True if there is a mapping for the given key in this map.

const V & get (const K &) const
 Returns a constant reference to the value the given key is mapped to, or noValue.getValue() if it is not mapped to anything.

V & get (const K &)
 Returns a modifiable reference to the value the given key is mapped to, or if it was not mapped to anything, inserts the key into the map, so that the reference can be assigned to something.

Pair< K, V > & put (const K &, const V &)
 Put a new mapping of the given key and value into the map. More...

void putAll (const Map< K, V > &)
 Copies all mappings from the given map into this one. More...

bool remove (const K &)
 Removes the mapping of the given key from this map. More...

void remove (Iterator &iter)
 Removes the mapping the given iterator points to. More...

void clear ()
 Clears this map by removing and deleting all entries.

const V & operator[] (const K &) const
 Returns a constant reference to the value the given key is mapped to, or noValue.getValue() if it is not mapped to anything.

V & operator[] (const K &)
 Returns a modifiable reference to the value the given key is mapped to, or if it was not mapped to anything, inserts the key into the map, so that the reference can be assigned to something.

int length () const
 Returns the element count of this map.

Iterator begin () const
 Returns an unmodifyable iterator to the first element of the map. More...

Iterator end () const
 Returns an unmodifyable iterator to the last element of the map. More...

Iterator begin ()
 Returns a modifyable iterator to the first element of the map. More...

Iterator end ()
 Returns a modifyable iterator to the last element of the map. More...


Static Public Attributes

Pair< K, V > noValue
 The pair which is defined to be no value.


Protected Attributes

int(* compareFun )(const K &, const K &)
 The function used to compare the keys.


Detailed Description

template<class K, class V>
class lrt::Map< K, V >

A map collection type (a.k.a. associative array).

This implementation of a map uses a linked list to store its data and it therefore quite slow (for large data sets).
Note: All types which should be used as keys in a Map must implement the comparison operators < and ==!


Constructor & Destructor Documentation

template<class K, class V>
lrt::Map< K, V >::Map (    ) 
 

Creates a new empty map.

The map entries are sorted using the default stdCompare() function.


Member Function Documentation

template<class K, class V>
Map< K, V >::Iterator lrt::Map< K, V >::begin (    ) 
 

Returns a modifyable iterator to the first element of the map.

If the map is empty, the iterator points to nothing; you can use Iterator::hasElement() to check this.

template<class K, class V>
Map< K, V >::Iterator lrt::Map< K, V >::begin (    )  const
 

Returns an unmodifyable iterator to the first element of the map.

If the map is empty, the iterator points to nothing; you can use Iterator::hasElement() to check this.

template<class K, class V>
Map< K, V >::Iterator lrt::Map< K, V >::end (    ) 
 

Returns a modifyable iterator to the last element of the map.

If the map is empty, the iterator points to nothing; you can use Iterator::hasElement() to check this.

template<class K, class V>
Map< K, V >::Iterator lrt::Map< K, V >::end (    )  const
 

Returns an unmodifyable iterator to the last element of the map.

If the map is empty, the iterator points to nothing; you can use Iterator::hasElement() to check this.

template<class K, class V>
Pair< K, V > & lrt::Map< K, V >::put (  const K &   ,
const V &   
) 
 

Put a new mapping of the given key and value into the map.

If the given key was already mapped to something, the mapping is replaced.

Returns:
A reference to the inserted key-value pair.

template<class K, class V>
void lrt::Map< K, V >::putAll (  const Map< K, V > &    ) 
 

Copies all mappings from the given map into this one.

Existing mappings are replaced (if they have the same key).

template<class K, class V>
void lrt::Map< K, V >::remove (  Iterator &    iter ) 
 

Removes the mapping the given iterator points to.

Moves the iterator to the next mapping of the list.

template<class K, class V>
bool lrt::Map< K, V >::remove (  const K &    ) 
 

Removes the mapping of the given key from this map.

If the key was not mapped to anything, just does nothing.

Returns:
True if there was actually a mapping removed.


The documentation for this class was generated from the following files:
This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer