casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
casacore::SimpleOrderedMap< K, V > Class Template Reference

Simple map with keys ordered. More...

#include <SimOrdMap.h>

Public Member Functions

 SimpleOrderedMap (const V &defaultValue, uInt size)
 Creates a map with the specified default value, "value", and the internal block size. More...
 
 SimpleOrderedMap (const V &defaultValue)
 Creates a map with the specified default value, "value". More...
 
 SimpleOrderedMap (const SimpleOrderedMap< K, V > &)
 Creates a map from another one; use copy semantics. More...
 
 ~SimpleOrderedMap ()
 Removes a map. More...
 
SimpleOrderedMap< K, V > & operator= (const SimpleOrderedMap< K, V > &)
 Assigns this SimpleOrderedMap to another with copy semantics. More...
 
V & define (const K &, const V &)
 Defines a mapping (ie. More...
 
V & operator() (const K &ky)
 This is the mapping function which maps keys to values. More...
 
const V & operator() (const K &ky) const
 
V & defaultVal ()
 Returns the default value for the Map. More...
 
const V & defaultVal () const
 
V * isDefined (const K &)
 These functions check to see if a mapping is defined between the specified key and some value. More...
 
const V * isDefined (const K &k) const
 
uInt ndefined () const
 Get the number of elements in the map. More...
 
const K & getKey (uInt inx) const
 Get the i-th key in the map. More...
 
const V & getVal (uInt inx) const
 Get the i-th value in the map. More...
 
V & getVal (uInt inx)
 
void rename (const K &newkey, const K &oldkey)
 Rename a key. More...
 
void remove (const K &)
 Undefines a mapping (ie. More...
 
void clear ()
 Clear the entire map (ie. More...
 
uInt ntot () const
 Get the total size of the block in use. More...
 
uInt incr () const
 Get or set the Block allocation increment. More...
 
uInt incr (uInt nri)
 
Bool ok () const
 Check the internal state. More...
 

Static Public Member Functions

static uInt Version ()
 Version for major change (used by SimOrdMapIO). More...
 

Protected Member Functions

uInt findKey (const K &, Bool &) const
 Binary search for the key. More...
 
void copyBlock (const SimpleOrderedMap< K, V > &)
 Copy from another Block of OrderedPair's. More...
 

Protected Attributes

Block< void * > kvblk
 The blocks to hold the keys and values and the total, used and increment size of these blocks. More...
 
uInt nrused
 
uInt nrincr
 
DefaultVal
 

Detailed Description

template<class K, class V>
class casacore::SimpleOrderedMap< K, V >

Simple map with keys ordered.

Review Status

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

SimpleOrderedMap<key,value> is a template class. It is similar to OrderedMap<key,value>, but lacks its sophisticated iterator capability. Instead iteration can be done using the getKey and getVal function with a simple index. The function ndefined() gives the number of key,value pairs in the map.

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.

Exceptions are raised when new[] is failing or when the next() getKey() or getValue() function is failing.

The AipsIO >> and << operators are defined in <aips/SimOrdMapIO.h>.

Definition at line 73 of file SimOrdMap.h.

Constructor & Destructor Documentation

template<class K, class V>
casacore::SimpleOrderedMap< K, V >::SimpleOrderedMap ( const V &  defaultValue,
uInt  size 
)

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

template<class K, class V>
casacore::SimpleOrderedMap< K, V >::SimpleOrderedMap ( const V &  defaultValue)
explicit

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

template<class K, class V>
casacore::SimpleOrderedMap< K, V >::SimpleOrderedMap ( const SimpleOrderedMap< K, V > &  )

Creates a map from another one; use copy semantics.

template<class K, class V>
casacore::SimpleOrderedMap< K, V >::~SimpleOrderedMap ( )

Removes a map.

Member Function Documentation

template<class K, class V>
void casacore::SimpleOrderedMap< K, V >::clear ( )

Clear the entire map (ie.

remove all mappings).

template<class K, class V>
void casacore::SimpleOrderedMap< K, V >::copyBlock ( const SimpleOrderedMap< K, V > &  )
protected

Copy from another Block of OrderedPair's.

template<class K, class V>
V& casacore::SimpleOrderedMap< K, V >::defaultVal ( )
inline

Returns the default value for the Map.

Definition at line 118 of file SimOrdMap.h.

References casacore::SimpleOrderedMap< K, V >::DefaultVal.

template<class K, class V>
const V& casacore::SimpleOrderedMap< K, V >::defaultVal ( ) const
inline

Definition at line 119 of file SimOrdMap.h.

References casacore::SimpleOrderedMap< K, V >::DefaultVal.

template<class K, class V>
V& casacore::SimpleOrderedMap< K, V >::define ( const K &  ,
const V &   
)

Defines a mapping (ie.

create a key value mapping) The value is replaced if the key already exists.

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::findKey ( const K &  ,
Bool  
) const
protected

Binary search for the key.

template<class K, class V>
const K& casacore::SimpleOrderedMap< K, V >::getKey ( uInt  inx) const
inline

Get the i-th key in the map.

It can be used to iterate through the keys as: for (uInt i=0; i<map.ndefined(); i++) { cout << map.getKey(i) << " " << map.getVal(i) << endl; } Index checking is only done if Block is doing it.

Definition at line 142 of file SimOrdMap.h.

References KVBLKpair.

template<class K, class V>
const V& casacore::SimpleOrderedMap< K, V >::getVal ( uInt  inx) const
inline

Get the i-th value in the map.

It can be used to iterate through the keys as: for (uInt i=0; i<map.ndefined(); i++) { cout << map.getKey(i) << " " << map.getVal(i) << endl; } Index checking is only done if Block is doing it.

Definition at line 154 of file SimOrdMap.h.

References KVBLKpair.

template<class K, class V>
V& casacore::SimpleOrderedMap< K, V >::getVal ( uInt  inx)
inline

Definition at line 156 of file SimOrdMap.h.

References KVBLKpair.

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::incr ( ) const
inline

Get or set the Block allocation increment.

Definition at line 182 of file SimOrdMap.h.

References casacore::SimpleOrderedMap< K, V >::nrincr.

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::incr ( uInt  nri)
inline

Definition at line 183 of file SimOrdMap.h.

References casacore::SimpleOrderedMap< K, V >::nrincr.

template<class K, class V>
V* casacore::SimpleOrderedMap< K, V >::isDefined ( const K &  )

These functions check to see if a mapping is defined between the specified key and some value.

If defined, a pointer to the value is returned, otherwise 0 is returned.

template<class K, class V>
const V* casacore::SimpleOrderedMap< K, V >::isDefined ( const K &  k) const
inline

Definition at line 127 of file SimOrdMap.h.

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::ndefined ( ) const
inline

Get the number of elements in the map.

Definition at line 132 of file SimOrdMap.h.

References casacore::SimpleOrderedMap< K, V >::nrused.

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::ntot ( ) const
inline

Get the total size of the block in use.

Definition at line 178 of file SimOrdMap.h.

References casacore::SimpleOrderedMap< K, V >::kvblk, and casacore::Block< T >::nelements().

template<class K, class V>
Bool casacore::SimpleOrderedMap< K, V >::ok ( ) const

Check the internal state.

Thrown Exceptions

template<class K, class V>
V& casacore::SimpleOrderedMap< K, V >::operator() ( const K &  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()()".


Note: 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;

template<class K, class V>
const V& casacore::SimpleOrderedMap< K, V >::operator() ( const K &  ky) const

Thrown Exceptions

  • indexError<K>
template<class K, class V>
SimpleOrderedMap<K,V>& casacore::SimpleOrderedMap< K, V >::operator= ( const SimpleOrderedMap< K, V > &  )

Assigns this SimpleOrderedMap to another with copy semantics.

template<class K, class V>
void casacore::SimpleOrderedMap< K, V >::remove ( const K &  )

Undefines a mapping (ie.

remove a key value mapping).

Thrown Exceptions

  • indexError<K>
template<class K, class V>
void casacore::SimpleOrderedMap< K, V >::rename ( const K &  newkey,
const K &  oldkey 
)

Rename a key.

If the new key already exists, the existing key will be removed.

Thrown Exceptions

  • indexError<K>
template<class K, class V>
static uInt casacore::SimpleOrderedMap< K, V >::Version ( )
inlinestatic

Version for major change (used by SimOrdMapIO).

enum did not work properly with cfront 3.0.1), so replaced by a static inline function. Users won't normally use this. display 8

Definition at line 196 of file SimOrdMap.h.

Member Data Documentation

template<class K, class V>
V casacore::SimpleOrderedMap< K, V >::DefaultVal
protected

Definition at line 204 of file SimOrdMap.h.

Referenced by casacore::SimpleOrderedMap< K, V >::defaultVal().

template<class K, class V>
Block<void*> casacore::SimpleOrderedMap< K, V >::kvblk
protected

The blocks to hold the keys and values and the total, used and increment size of these blocks.

Definition at line 201 of file SimOrdMap.h.

Referenced by casacore::SimpleOrderedMap< K, V >::ntot().

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::nrincr
protected

Definition at line 203 of file SimOrdMap.h.

Referenced by casacore::SimpleOrderedMap< K, V >::incr().

template<class K, class V>
uInt casacore::SimpleOrderedMap< K, V >::nrused
protected

Definition at line 202 of file SimOrdMap.h.

Referenced by casacore::SimpleOrderedMap< K, V >::ndefined().


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