Map.h

Classes

MapRep -- Map representation class (full description)
Map -- Abstract base class for associative arrays (full description)
MapIterRep -- Abstract base class for associative array iterators (full description)
ConstMapIter -- Const associative array iterator (full description)
MapIter -- Associative array iterator (full description)

template<class key, class value> class MapRep

Types

enum

MapRepVersion = 1

Interface

Public Members
MapRep(const value &dflt) : DefaultVal(dflt)
value &operator()(const key &ky)
const value &operator()(const key &ky) const
value &defaultVal()
const value &defaultVal() const
virtual const value *isDefined(const key &) const = 0
virtual value *isDefined(const key &) = 0
virtual uInt ndefined() const = 0
virtual value &define(const key &, const value &) = 0
virtual void remove(const key &) = 0
virtual void clear() = 0
virtual MapIterRep<key,value> *getRep(value<key,value>*) const = 0
virtual MapRep<key,value> *Clone() const = 0
virtual ~MapRep()

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Member Description

MapRep(const value &dflt) : DefaultVal(dflt)

This is the only MapRep constructor. It takes as a parameter the default value for the map.

value &operator()(const key &ky)

This is the mapping function which maps keys to values. If the map from the key to a value is not defined, a mapping will be defined from the key to the default value (which is set from the constructor. The "isDefined()" member function can be used to check to see if a mapping is defined before using the "operator()()".

With a constant map in the case where the key is not defined, the mapping between key and default value is not created, but rather an exception is thrown. +grp

const value &operator()(const key &ky) const

value &defaultVal()

-grp

Returns the default value for the Map.

+grp

const value &defaultVal() const

virtual const value *isDefined(const key &) const = 0

-grp

Returns a non-zero value if a mapping is defined for the key parameter.

+grp

virtual value *isDefined(const key &) = 0

virtual uInt ndefined() const = 0

-grp

Returns the number of user defined mappings

virtual value &define(const key &, const value &) = 0

These functions allow for the definition and removal of key/value relations. The "define(key &, value &)" call defines a key/value relation, and "remove(key &)" removes a relation if it has been previously defined.

+grp

virtual void remove(const key &) = 0

virtual void clear() = 0

-grp

Clear all of the mappings.

virtual MapIterRep<key,value> *getRep(value<key,value>*) const = 0

virtual MapRep<key,value> *Clone() const = 0

virtual ~MapRep()

Does nothing.

enum


template<class key, class value> class Map

Types

enum

MapVersion = 1

Interface

value &operator()(const key &ky)
const value &operator()(const key &ky) const
value &defaultVal()
const value &defaultVal() const
const value *isDefined(const key &k) const
value *isDefined(const key &k)
uInt ndefined() const
value &define(const key &k, const value &v)
void remove(const key &k)
void clear()
MapIterRep<key,value> *getRep() const
Map(const Map<key,value> &m)
Map(const Map<key,value> *m)
Map<key,value> &operator=(const Map<key,value> &)
Map<key,value> &operator=(const Map<key,value> *)
virtual ~Map()
ConstMapIter<key,value> *getIter() const
Protected Members
Map(MapRep<key,value> *nRep)
void SetRep(MapRep<key,value> *st)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

This is the abstract class for all "Map" classes which implement the equivalent of an associative array.

Member Description

value &operator()(const key &ky)

This is the mapping function which maps keys to values. If the map from the key to a value is not defined, a mapping will be defined from the key to the default value (which is set from the constructor. The "isDefined()" member function can be used to check to see if a mapping is defined before using the "operator()()".

With a constant map in the case where the key is not defined, the mapping between key and default value is not created, but rather an exception is thrown. +grp

const value &operator()(const key &ky) const

value &defaultVal()

-grp

Returns the default value for the Map.

+grp

const value &defaultVal() const

const value *isDefined(const key &k) const

-grp

Returns a non-zero value if a mapping is defined for the key parameter.

+grp

value *isDefined(const key &k)

uInt ndefined() const

-grp

Returns the number of user defined mappings

value &define(const key &k, const value &v)

These functions allow for the definition and removal of key/value relations. The "define(key &, value &)" call defines a key/value relation, and "remove(key &)" removes a relation if it has been previously defined.

+grp

void remove(const key &k)

void clear()

-grp

Clear all of the mappings.

MapIterRep<key,value> *getRep() const

Returns the iterator rep appropriate for this particular Map

Map(const Map<key,value> &m)

This copy constructor will, for the moment, be the only way to create a map.

+grp

Map(const Map<key,value> *m)

Map<key,value> &operator=(const Map<key,value> &)

-grp

Map<key,value> &operator=(const Map<key,value> *)

virtual ~Map()

Does nothing.

enum

ConstMapIter<key,value> *getIter() const

Map(MapRep<key,value> *nRep)

Used by derived classes

void SetRep(MapRep<key,value> *st)

Used the set the representation. Always DELETES Rep if necessary.


template<class key, class value> class MapIterRep

Types

enum

MapIterRepVersion = 1

Interface

Public Members
virtual Bool isValid() const = 0
virtual Bool atEnd() const = 0
virtual Bool atStart() const = 0
virtual void toStart() = 0
virtual void operator++() = 0
virtual void operator++(int) = 0
virtual const key &getKey() const = 0
virtual value &getVal() = 0
virtual const value &getVal() const = 0
const value &defaultVal() const
value &defaultVal()
value &define(const key &ky, const value &val)
void remove(const key &ky)
void clear()
const value &operator()(const key &ky) const
value &operator()(const key &ky)
const value *isDefined(const key &ky) const
value *isDefined(const key &ky)
uInt ndefined() const
Map<key,value> &container()
const Map<key,value> &container() const
virtual MapIterRep<key,value> *Clone() = 0
MapIterRep(Map<key,value> &st)
MapIterRep(Map<key,value> *st)
virtual ~MapIterRep()

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

This is the abstract base class for all (Const)MapIter "letters". That is all Map specializations must provide a "IterRep" for the particular specialization which will allow the (Const)MapIter envelope to traverse the new type of map.

Member Description

virtual Bool isValid() const = 0

Check to see if the iterator is in a valid state.

virtual Bool atEnd() const = 0

Check to see if the iterator position is at the end or beginning of the Map.

+grp

virtual Bool atStart() const = 0

virtual void toStart() = 0

-grp

Move the iterator to the start of the Map.

virtual void operator++() = 0

Advance to the next element of the Map.

+grp

virtual void operator++(int) = 0

virtual const key &getKey() const = 0

-grp

Get the key for the current position in the Map.

virtual value &getVal() = 0

Return the value at the current location of the map iterator. Should throw an exception if the iterator is "past the end of the Map" or if the iterator is invalid.

+grp

virtual const value &getVal() const = 0

const value &defaultVal() const

-grp

This returns the default value for the map that this iterator is tracking. With a non-const iterator the default value can be changed.

+grp

value &defaultVal()

value &define(const key &ky, const value &val)

-grp

These functions allow for the definition and removal of key/value relations. The "define(key &, value &)" function defines a key/value relation, and "remove(key &)" function removes a relation if it has been previously defined.

+grp

void remove(const key &ky)

void clear()

-grp

Clear all of the mappings.

const value &operator()(const key &ky) const

Allows mapping functions to be performed with the map on which this iterator operates. If this iterator is invalid, then an exception will be thrown. With a non-const operator, the value can be changed.

+grp

value &operator()(const key &ky)

const value *isDefined(const key &ky) const

-grp

Allows one to check to see if a given key is defined in the map which this iterator tracks. If this iterator is invalid, then an exception will be thrown. With a non-const iterator the returned pointer can be used to change the value in the map.

+grp

value *isDefined(const key &ky)

uInt ndefined() const

-grp

Returns the number of user defined mappings

Map<key,value> &container()

Returns the container on which this iterator is operating.

+grp

const Map<key,value> &container() const

virtual MapIterRep<key,value> *Clone() = 0

-grp

Duplicate a map iterator

+grp

MapIterRep(Map<key,value> &st)

-grp

This allows a MapIter to be constructed from a Map. When created the new MapIter maintains a reference to the original Map. If the Map to which this MapIter points is deleted, then the MapIter is marked as invalid.

+grp

MapIterRep(Map<key,value> *st)

virtual ~MapIterRep()

-grp

enum


template<class key, class value> class ConstMapIter

Types

enum

ConstMapIterVersion = 1

Interface

virtual void toStart()
virtual void operator++()
virtual void operator++(int)
virtual const key &getKey() const
virtual const value &getVal() const
virtual Bool atEnd() const
virtual Bool atStart() const
virtual Bool isValid() const
ConstMapIter(const Map<key,value> *st)
ConstMapIter(const Map<key,value> &st)
virtual ConstMapIter<key,value> &operator=(const value<key,value> &other)
virtual ConstMapIter<key,value> &operator=(const value<key,value> *other)
ConstMapIter(const ConstMapIter<key,value> *st)
ConstMapIter(const ConstMapIter<key,value> &st)
virtual ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> &other)
virtual ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> *other)
ConstMapIter() : Rep(0)
const value &defaultVal() const
const value &operator()(const key &ky) const
const value *isDefined(const key &ky) const
uInt ndefined() const
const Map<key,value> &container() const
virtual ~ConstMapIter()
Protected Members
ConstMapIter(MapIterRep<key,value> *st) : Rep(st)
void SetRep(MapIterRep<key,value> *st)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

This class implements the mechanism for traversing constant associative arrays, i.e. "Map"s. This allows one to move the cursor to the beginning of the map and serially traverse the map. The key and value elements can be extracted at each position in the Map. For example: template void print(const Map &xx){ ConstMapIter x(xx); x.toStart(); while (!x.atEnd()) { cout << "(" << x.getKey() << "," << x.getVal() << ")" << " "; x++; } cout << endl; } This example declares a templated function which accepts a const Map as a parameter, and iterates through the map displaying the key/value pairs at each positon.

Member Description

virtual void toStart()

Move the iterator to the start of the Map.

virtual void operator++()

Advance to the next element of the Map.

+grp

virtual void operator++(int)

virtual const key &getKey() const

-grp

Get the key or value for the current position in the Map.

+grp

virtual const value &getVal() const

virtual Bool atEnd() const

-grp

Check to see if the iterator position is at the end or beginning of the Map.

+grp

virtual Bool atStart() const

virtual Bool isValid() const

-grp

Check to see if the iterator is in a valid state.

ConstMapIter(const Map<key,value> *st)

Constructs a Map iterator from a Map (with reference semantics).

+grp

ConstMapIter(const Map<key,value> &st)

virtual ConstMapIter<key,value> &operator=(const value<key,value> &other)

-grp

Assign one map iterator to a map (with reference semantics).

+grp

virtual ConstMapIter<key,value> &operator=(const value<key,value> *other)

ConstMapIter(const ConstMapIter<key,value> *st)

-grp

Constructs a Map iterator from another iterator (with reference semantics).

+grp

ConstMapIter(const ConstMapIter<key,value> &st)

virtual ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> &other)

-grp

Assign one map iterator to another iterator (with reference semantics).

+grp

virtual ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> *other)

ConstMapIter() : Rep(0)

-grp

Default constructor creates an invalid Map iterator.

const value &defaultVal() const

Returns the default value for the Map on which this iterator is operating if it is a valid iterator, otherwise it throws an exception.

const value &operator()(const key &ky) const

Allows mapping functions to be performed with the map on which this iterator operates. If this iterator is invalid, then an exception will be thrown.

const value *isDefined(const key &ky) const

Allows one to check to see if a given key is defined in the map which this iterator tracks. If this iterator is invalid, then an exception will be thrown.

uInt ndefined() const

Returns the number of user defined mappings

const Map<key,value> &container() const

Returns the container on which this iterator is operating.

virtual ~ConstMapIter()

enum

ConstMapIter(MapIterRep<key,value> *st) : Rep(st)

Dummy used to initialization by derived classes.

void SetRep(MapIterRep<key,value> *st)

Always DELETES Rep if necessary


template<class key, class value> class MapIter : virtual public ConstMapIter<key,value>

Types

enum

MapIterVersion = 1

Interface

Public Members
virtual value &getVal()
virtual const value &getVal() const
value &define(const key &ky, const value &val)
void remove(const key &ky)
const value &defaultVal() const
value &defaultVal()
void clear()
const value &operator()(const key &ky) const
value &operator()(const key &ky)
const value *isDefined(const key &ky) const
value *isDefined(const key &ky)
MapIter(Map<key,value> *other) : ConstMapIter<key,value>(other ? other->getRep() : 0)
MapIter(Map<key,value> &st) : ConstMapIter<key,value>(st.getRep())
MapIter(const MapIter<key,value> &other) : ConstMapIter<key,value>(other.isValid() ? other.Rep->Clone() : 0)
MapIter(const MapIter<key,value> *other) : ConstMapIter<key,value>(other && (*other).isValid() ? other->Rep->Clone() : 0)
MapIter() : ConstMapIter<key,value>()
virtual MapIter<key,value> &operator=(value<key,value> &other)
virtual MapIter<key,value> &operator=(value<key,value> *other)
virtual MapIter<key,value> &operator=(const MapIter<key,value> &other)
virtual MapIter<key,value> &operator=(const MapIter<key,value> *other)
Map<key,value> &container()
const Map<key,value> &container() const
~MapIter()
Protected Members
ConstMapIter<key,value> &operator=(const value<key,value> &)
ConstMapIter<key,value> &operator=(const value<key,value> *)
ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> &)
ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> *)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

This class implements the mechanism for traversing associative arrays, i.e. "Map"s. It provides the traversal mechanisms of the ConstMapIter, but adds the mechansims to modify the values, and perform other modification functions which the Maps provide, e.g. define().

Member Description

virtual value &getVal()

Return the value at the current location of the map iterator. Should throw an exception if the iterator is "past the end of the Map" or if the iterator is invalid.

+grp

virtual const value &getVal() const

value &define(const key &ky, const value &val)

-grp

These functions allow for the definition and removal of key/value relations. The "define(key &, value &)" function defines a key/value relation, and "remove(key &)" function removes a relation if it has been previously defined.

+grp

void remove(const key &ky)

const value &defaultVal() const

-grp

This returns the default value for the map that this iterator is tracking. With a non-const iterator the default value can be changed.

+grp

value &defaultVal()

void clear()

-grp

Clear all of the mappings.

const value &operator()(const key &ky) const

Allows mapping functions to be performed with the map on which this iterator operates. If this iterator is invalid, then an exception will be thrown. With a non-const operator, the value can be changed.

+grp

value &operator()(const key &ky)

const value *isDefined(const key &ky) const

-grp

Allows one to check to see if a given key is defined in the map which this iterator tracks. If this iterator is invalid, then an exception will be thrown. With a non-const iterator the returned pointer can be used to change the value in the map.

+grp

value *isDefined(const key &ky)

MapIter(Map<key,value> *other) : ConstMapIter<key,value>(other ? other->getRep() : 0)

-grp

This allows a MapIter to be constructed from a Map. When created the new MapIter maintains a reference to the original Map. If the Map to which this MapIter points is deleted, then the MapIter is marked as invalid.

+grp

MapIter(Map<key,value> &st) : ConstMapIter<key,value>(st.getRep())

MapIter(const MapIter<key,value> &other) : ConstMapIter<key,value>(other.isValid() ? other.Rep->Clone() : 0)

-grp

This allows a MapIter to be constructed from another MapIter. When created the new MapIter maintains a reference to the Map which the MapIter parameter tracked. If this Map is deleted, then this MapIter is marked as invalid.

+grp

MapIter(const MapIter<key,value> *other) : ConstMapIter<key,value>(other && (*other).isValid() ? other->Rep->Clone() : 0)

MapIter() : ConstMapIter<key,value>()

-grp

Default constructor creates an invalid Map iterator.

virtual MapIter<key,value> &operator=(value<key,value> &other)

This assignment operator allows the Map which this MapIter tracks to be changed. After a call to this operator, the MapIter will track the Map parameter.

+grp

virtual MapIter<key,value> &operator=(value<key,value> *other)

virtual MapIter<key,value> &operator=(const MapIter<key,value> &other)

-grp

This assignment operator allows the Map which this MapIter tracks to be changed. After a call to this operator, this MapIter will track the Map which the MapIter parameter trackes, i.e. it will contain a reference to this new Map.

+grp

virtual MapIter<key,value> &operator=(const MapIter<key,value> *other)

Map<key,value> &container()

-grp

Returns the container on which this iterator is operating.

+grp

const Map<key,value> &container() const

~MapIter()

-grp

enum

ConstMapIter<key,value> &operator=(const value<key,value> &)

These assignment operators are private and ONLY throw an exception to prevent incorrect assignments to a non-const iterator.

+grp

ConstMapIter<key,value> &operator=(const value<key,value> *)

ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> &)

ConstMapIter<key,value> &operator=(const ConstMapIter<key,value> *)