Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Map Class Template Reference

Associative map, based on GenHash. More...

#include <mmap.h>

Inheritance diagram for Map::

Object List of all members.

Public Methods

 Map ()
 Map (int hashsize, int flags)
 Map (const Map &orig)
 ~Map ()
void set (const keyclass &key, const valueclass &value)
void set (const keyclass &key, const valueclass *value)
void remove (const keyclass &key)
bool hasKey (const keyclass &key) const
const valueclass& operator[] (const keyclass &key) const
valueclass& operator[] (const keyclass &key)
const valueclass& get (const keyclass &key) const
valueclass& getv (const keyclass &key)
const valueclass& getOr (const keyclass &key, const valueclass &def) const
const valueclass* getp (const keyclass &key) const
valueclass* getvp (const keyclass &key)
virtual DumpContext& operator>> (DumpContext &out) const
virtual ostream& operator>> (ostream &out) const
Map<keyclass,valueclass>& operator+= (const Map< keyclass, valueclass > &other)
Map<keyclass,valueclass>& operator= (const Map< keyclass, valueclass > &other)
void empty ()
const GenHashgethash () const
void check () const
void failByThrow (bool bythrow=true)
void failByThrowOnce (bool bythrow=true) const
void failByNullOnce (bool bynull=true) const

Detailed Description

template<class keyclass, class valueclass> class Map

Associative map, based on GenHash.

The key class has to inherit Comparable. The value class can be any inherit of Object.

The inserted objects are owned by the Map by default, and are thus destroyed along with it, or during various replacement methods. By giving the MAP_REF flag to the constructor causes the objects not to be owned by the Map.

Map<String,String> has a shorthand macro StringMap. Many Map-handling functions, especially for StringMaps, are not included in the template, but are global. Such methods include toString(), splitpairs(), and joinpairs(). See section "globals" for more information, or the header mmap.h.

Maps can be iterated using MapIter. Note also the forMap and forStringMap macros in mmap.h

Definition at line 165 of file mmap.h.


Constructor & Destructor Documentation

Map ( ) [inline]
 

Default constructor uses the default hash size of GenHash.

Definition at line 169 of file mmap.h.

Map ( int hashsize,
int flags ) [inline]
 

Constructor.

Parameters:
hashsize   Hash size, should usually be larger than 16, around is typical. Prime numbers are often recommended (which 16 and 64 are not).
flags   Mode parameters. Currently defined are: MAP_REF (causes objects to be not owned by the Map)

Definition at line 185 of file mmap.h.


Member Function Documentation

void check ( ) const [inline, virtual]
 

Implementation for Object.

Reimplemented from Object.

Definition at line 362 of file mmap.h.

void empty ( ) [inline]
 

Destroys all the items from the Map.

Definition at line 353 of file mmap.h.

void failByNullOnce ( bool bynull = true ) const [inline]
 

Same as failByThrow(false), but applies to only one access call.

Giving parameter 'false' to this method cancels a previously given failByNullOnce(true) currently in effect.

Definition at line 387 of file mmap.h.

void failByThrow ( bool bythrow = true ) [inline]
 

Should the access-methods of Map report missing elements by throwing an exception (true) or by returning a null reference (false, which is the default).

Null references to objects can be checked by the global isnull() function.

Definition at line 371 of file mmap.h.

void failByThrowOnce ( bool bythrow = true ) const [inline]
 

Same as failByThrow(true), but applies to only one access call.

Giving parameter 'false' to this method cancels a previously given failByThrowOnce(true) currently in effect.

Definition at line 379 of file mmap.h.

const valueclass & get ( const keyclass & key ) const [inline]
 

Returns a const reference to object associated to the key.

For information about error handling and exceptions, see failByThrowOnce().

See also:
getv

Definition at line 259 of file mmap.h.

Referenced by getv(), and operator[]().

const valueclass & getOr ( const keyclass & key,
const valueclass & def ) const [inline]
 

Returns a const reference to object associated to the key, OR if the key is not found from the map, returns the 'def' reference back to the caller.

For information about error handling and exceptions, see failByThrowOnce().

See also:
get

Definition at line 297 of file mmap.h.

const GenHash * gethash ( ) const [inline]
 

Returns the GenHash of the Map.

Definition at line 359 of file mmap.h.

const valueclass * getp ( const keyclass & key ) const [inline]
 

Returns a const pointer to object associated to the key, or NULL if the object was not found.

See also:
getvp

Definition at line 307 of file mmap.h.

valueclass & getv ( const keyclass & key ) [inline]
 

Returns a non-const reference to object associated to the key.

For information about error handling and exceptions, see failByThrowOnce().

See also:
get

Definition at line 284 of file mmap.h.

valueclass * getvp ( const keyclass & key ) [inline]
 

Returns a non-const pointer to object associated to the key, or NULL if the object was not found.

See also:
getp

Definition at line 316 of file mmap.h.

bool hasKey ( const keyclass & key ) const [inline]
 

Queries whether the given key is in the map.

Definition at line 230 of file mmap.h.

Map< keyclass, valueclass > & operator+= ( const Map< keyclass, valueclass > & other ) [inline]
 

Union operator; adds the other Map to self.

Definition at line 335 of file mmap.h.

Map< keyclass, valueclass > & operator= ( const Map< keyclass, valueclass > & other ) [inline]
 

Copy operator.

Definition at line 341 of file mmap.h.

ostream & operator>> ( ostream & out ) const [inline, virtual]
 

Implementation for Object.

Reimplemented from Object.

Definition at line 329 of file mmap.h.

DumpContext & operator>> ( DumpContext & out ) const [inline, virtual]
 

Implementation for Object.

Reimplemented from Object.

Definition at line 323 of file mmap.h.

valueclass & operator[] ( const keyclass & key ) [inline]
 

Returns a non-const reference to object associated to the key.

For information about error handling and exceptions, see failByThrowOnce().

Definition at line 248 of file mmap.h.

const valueclass & operator[] ( const keyclass & key ) const [inline]
 

Returns a const reference to object associated to the key.

For information about error handling and exceptions, see failByThrowOnce().

Definition at line 239 of file mmap.h.

void remove ( const keyclass & key ) [inline]
 

Removes an item from the map.

Definition at line 225 of file mmap.h.

void set ( const keyclass & key,
const valueclass * value ) [inline]
 

Sets the _key_ to _value_; takes ownership of the passed object.

Definition at line 219 of file mmap.h.

void set ( const keyclass & key,
const valueclass & value ) [inline]
 

Sets the _key_ to _value_; copies the given value object using the copy constructor.

Definition at line 207 of file mmap.h.


The documentation for this class was generated from the following file:
Generated at Tue Dec 4 19:53:30 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001