Map< ValueType >::Iterator Class Reference

#include "map.h"

List of all members.

Public Member Functions

 Iterator ()
bool hasNext ()
string next ()

Friends

class Map


Detailed Description

template<typename ValueType>
class Map< ValueType >::Iterator

This interface defines a nested class within the Map template that provides iterator access to the keys contained in the Map.

The idiomatic code for accessing elements using an iterator is to create the iterator from the collection and then enter a loop that calls next() while hasNext() is true, like this:

Map<int>::Iterator itr = map.iterator(); while (itr.hasNext()) string key = itr.next();


Constructor & Destructor Documentation

template<typename ValueType>
Map< ValueType >::Iterator::Iterator (  ) 

The Iterator for Map tracks a pointer to the original Map and a vector containing of the map keys that was assembled at the time of iteration creation. The iterator tracks an index into that vector that identifies the next key to return. Each use of next() increments that index, hasNext() verifies the index < the vector's size. This is an example of an "offline" iterator because it copies the map's data, instead of accessing it in-place. This is a bit inefficient (since it copies) but it makes the iterator simplier to write and sidesteps any problems where the client is modifying the map during iteration.


Member Function Documentation

template<typename ValueType>
bool Map< ValueType >::Iterator::hasNext (  ) 

template<typename ValueType>
string Map< ValueType >::Iterator::next (  ) 


Friends And Related Function Documentation

template<typename ValueType>
friend class Map [friend]


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1