Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Map Class Template Reference

Associative map, based on GenHash. More...

#include <mmap.h>

Inheritance diagram for Map:

List of all members.

Public Methods

 Map ()
 Map (int hashsize, int flags)
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 * getp (const keyclass &key) const
valueclass * getvp (const keyclass &key)
virtual DataOStream & operator>> (DataOStream &out) const
virtual ostream & operator>> (ostream &out) const
virtual TextOStreamoperator>> (TextOStream &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< keyclass, valueclass >

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 196 of file mmap.h.


Constructor & Destructor Documentation

Map   [inline]
 

Default constructor uses the default hash size of GenHash.

Definition at line 200 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 216 of file mmap.h.


Member Function Documentation

void check   const [inline]
 

Implementation for Object.

Definition at line 400 of file mmap.h.

void empty   [inline]
 

Destroys all the items from the Map.

Definition at line 391 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 425 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 409 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 417 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 290 of file mmap.h.

Referenced by Map< String, String >::getv(), and Map< String, String >::operator[]().

const GenHash* gethash   const [inline]
 

Returns the GenHash of the Map.

Definition at line 397 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 339 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 315 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 348 of file mmap.h.

bool hasKey const keyclass &    key const [inline]
 

Queries whether the given key is in the map.

Definition at line 261 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 373 of file mmap.h.

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

Copy operator.

Definition at line 379 of file mmap.h.

virtual TextOStream& operator>> TextOStream   out const [inline, virtual]
 

Implementation for Object.

Definition at line 367 of file mmap.h.

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

Implementation for Object.

Definition at line 361 of file mmap.h.

virtual DataOStream& operator>> DataOStream &    out const [inline, virtual]
 

Implementation for Object.

Definition at line 355 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 279 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 270 of file mmap.h.

void remove const keyclass &    key [inline]
 

Removes an item from the map.

Definition at line 256 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 250 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 238 of file mmap.h.


The documentation for this class was generated from the following file:
Generated on Thu Feb 10 20:06:43 2005 for LibMagiC by doxygen1.2.18