OrderedMap.h

Classes

OrderedMapNotice -- Message used for OrderedMap notification (full description)
OrderedMapRep -- Representation class for an Ordered Map (full description)
OrderedMap -- Map with keys ordered (full description)
OrderedMapIterRep -- OrderedMap iterator "letter" (full description)

template<class t,class v> class OrderedMapNotice : public Notice

Types

enum NoticeType

CLEAR
DEFINE
REMOVE
DELETE

Interface

Private Members
OrderedMapNotice(uInt pos, NoticeType typ) : changeType(typ), modPos(pos)
Public Members
uInt type() const
int operator==(const Notice &op) const

Description

Review Status

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

This is the message that flows between the OrderedMap and the OrderedMap iterators. It allows OrderedMap iterators to react to changes as they occur to the OrderedMap.

Member Description

enum NoticeType

OrderedMapNotice(uInt pos, NoticeType typ) : changeType(typ), modPos(pos)

This is used to construct a list notice. The parameters are: the change modification position the change type

uInt type() const

This function returns the "Notice" type, retrieved from the "type registry".

int operator==(const Notice &op) const

This operator can be used to compare two "OrderedMapNotice"s.


template<class key, class value> class OrderedMapRep : public NoticeSource, public MapRep<key,value>

Types

enum

OrderedMapRepVersion = 1

Interface

OrderedMapRep (const value&, uInt size)
OrderedMapRep (const value&)
value *isDefined(const key&)
const value *isDefined(const key&) const
uInt ndefined() const
value &define (const key&, const value&)
void remove (const key&)
void clear ()
MapIterRep<key,value> *getRep(value<key,value> *) const
MapRep<key,value> *Clone() const
uInt nused() const
uInt ntot() const
uInt incr() const
uInt incr(uInt nri)
~OrderedMapRep ()
Protected Members
Int findKey (const key&, Bool&) const

Description

Review Status

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

Member Description

OrderedMapRep (const value&, uInt size)

Creates a map with the specified default value, "value", and the internal block size.

OrderedMapRep (const value&)

Creates a map with the specified default value, "value".

value *isDefined(const key&)

These functions check to see if a mapping is defined between the specified key and some value. If one is, a pointer to the value is returned, otherwise 0 is returned.

+grp

const value *isDefined(const key&) const

uInt ndefined() const

-grp

Returns the number of user defined mappings

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

Defines a mapping (ie. create a key value mapping)

void remove (const key&)

Undefines a mapping (ie. remove a key value mapping).

void clear ()

Clear the entire map (ie. remove all mappings).

MapIterRep<key,value> *getRep(value<key,value> *) const

MapRep<key,value> *Clone() const

uInt nused() const

Get the number of mappings.

uInt ntot() const

uInt incr() const

Get or set the Block allocation increment.

+grp

uInt incr(uInt nri)

~OrderedMapRep ()

-grp

Removes a map.

enum

Int findKey (const key&, Bool&) const

Binary search for the key.


template<class key, class value> class OrderedMap : public Map<key,value>

Types

enum

OrderedMapVersion = 1

Interface

void throwgetKey(uInt) const
void throwgetValue(uInt) const
value &getVal(uInt inx)
const value &getVal(uInt inx) const
key &getKey (uInt inx)
const key &getKey (uInt inx) const
Public Members
OrderedMap (const value& dflt, uInt size) : Map<key,value>(new OrderedMapRep<key,value>(dflt,size))
explicit OrderedMap (const value& dflt) : Map<key,value>(new OrderedMapRep<key,value>(dflt))
OrderedMap (const OrderedMap<key,value>& other) : Map<key,value>(other.Rep->Clone())
~OrderedMap()
OrderedMap<key,value>& operator= (const OrderedMap<key,value>& other)
uInt nused() const
uInt ntot() const
uInt incr() const
uInt incr(uInt nri)

Description

Review Status

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

OrderedMap is a template class derived from Map. It is similar to ListMap, but the keys are kept in order and they have to be unique.

It uses a Block to store an array of pointers to the keys and the associated values. The keys and values themselves are stored on the heap. The keys are kept in order to allow a binary search through the keys for rapid access.

This is one (simple) implementation of an ordered map. It is not suitable for large arrays of keys, since the overhead of keeping the keys in order would get too big. For large arrays a red-black tree implementation would be better.

Exceptions are raised when new[] is failing, when the next() getKey() or getValue() function is failing or when a duplicate key is defined.

The AipsIO >> and << operators are defined in .

Member Description

void throwgetKey(uInt) const

void throwgetValue(uInt) const

value &getVal(uInt inx)

const value &getVal(uInt inx) const

key &getKey (uInt inx)

const key &getKey (uInt inx) const

OrderedMap (const value& dflt, uInt size) : Map<key,value>(new OrderedMapRep<key,value>(dflt,size))

Creates a map with the specified default value, "value", and the internal block size.

explicit OrderedMap (const value& dflt) : Map<key,value>(new OrderedMapRep<key,value>(dflt))

Creates a map with the specified default value, "value".

OrderedMap (const OrderedMap<key,value>& other) : Map<key,value>(other.Rep->Clone())

Creates a map from another one; use copy semantics.

~OrderedMap()

Does nothing, the destruction is taken care of in the base class, i.e. the letter contains the guts.

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

Assigns this OrderedMap to another with copy semantics.

uInt nused() const

Get the number of mappings.

uInt ntot() const

uInt incr() const

Get or set the Block allocation increment.

+grp

uInt incr(uInt nri)

enum

-grp


template<class key, class value> class OrderedMapIterRep : virtual public MapIterRep<key,value>, public NoticeTarget

Types

enum

OrderedMapIterRepVersion = 1

Interface

Protected Members
void thrownext() const
void throwInvalidIter() const
Public Members
Bool isValid() const
Bool atEnd() const
Bool atStart() const
void toStart()
void operator++()
void operator++(int)
const key &getKey () const
const key &getKey (uInt inx) const
value &getVal(uInt inx)
const value &getVal() const
const value &getVal(uInt inx) const
value &getVal()
MapIterRep<key,value> *Clone()
void notify(const Notice &)
OrderedMapIterRep(OrderedMap<key,value> *st) : MapIterRep<key,value>(st), st((MapIterRep *)((OrderedMapRep<key,value> *) st->Rep)), container(st), CurIndex(0)
OrderedMapIterRep(OrderedMap<key,value> &st) : MapIterRep<key,value>(st), st((MapIterRep *)((OrderedMapRep<key,value> *) st.Rep)), container(&st), CurIndex(0)

Description

Review Status

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

This is the "letter" which when paired (Const)MapIter "envelope" allows traversal of "OrderedMap"s.

Member Description

void thrownext() const

Throw exceptions on behalf of inline functions.

+grp

void throwInvalidIter() const

Bool isValid() const

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

Bool atEnd() const

Checks to see if the iterator is at one of the map extremes, "atEnd()" or "atStart()".

+grp

Bool atStart() const

void toStart()

-grp

Move the iterator to the beginning of the Map.

void operator++()

Advance the iterator to the next key.

+grp

void operator++(int)

const key &getKey () const

-grp

Retrieve the key at the current iterator position.

+grp

const key &getKey (uInt inx) const

value &getVal(uInt inx)

-grp

Retrieve the value at the given index in the internal block which stores the representation of the OrderedMap.

This should typically not be used.

+grp

const value &getVal() const

-grp

Retrieve the value at the current iterator position.

+grp

const value &getVal(uInt inx) const

value &getVal()

MapIterRep<key,value> *Clone()

-grp

void notify(const Notice &)

This function is the hook through which OrderedMap iterators are notified of changes to the OrderedMap which they observe, i.e. changes which may cause require iterator update.

OrderedMapIterRep(OrderedMap<key,value> *st) : MapIterRep<key,value>(st), st((MapIterRep *)((OrderedMapRep<key,value> *) st->Rep)), container(st), CurIndex(0)

These constructors allow a ListMapIter to be constructed from a ListMap.

+grp

OrderedMapIterRep(OrderedMap<key,value> &st) : MapIterRep<key,value>(st), st((MapIterRep *)((OrderedMapRep<key,value> *) st.Rep)), container(&st), CurIndex(0)

enum

-grp