Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

ost::MapTable Class Reference

A map table allows for entities to be mapped (hash index) onto it. Table to hold hash indexed objects. More...

#include <object.h>

Inheritance diagram for ost::MapTable::

ost::Mutex List of all members.

Public Methods

 MapTable (unsigned size)
 Create a map table with a specified number of slots. More...

virtual ~MapTable ()
 Destroy the table, calls cleanup. More...

virtual unsigned getIndex (const char *id)
 Get index value from id string. More...

unsigned getRange (void)
 Return range of this table. More...

void* getObject (const char *id)
 Lookup an object by id key. More...

void addObject (MapObject &obj)
 Map an object to our table. More...

void* getFree (void)
 Get next object from managed free list. More...

void addFree (MapObject *obj)
 Add an object to the managed free list. More...

MapTable& operator+= (MapObject &obj)
 An operator to map an object to the table. More...

virtual MapTable& operator-= (MapObject &obj)
 This operator is virtual in case it must also add the object to a managed free list. More...


Protected Methods

void cleanup (void)

Protected Attributes

unsigned range
MapObject** map

Friends

class  MapObject

Detailed Description

A map table allows for entities to be mapped (hash index) onto it. Table to hold hash indexed objects.

Unlike with Assoc, This form of map table also allows objects to be removed from the table. This table also includes a mutex lock for thread safety. A free list is also optionally maintained for reusable maps.

Author:
David Sugar <dyfet@gnutelephony.org>


Constructor & Destructor Documentation

ost::MapTable::MapTable ( unsigned size )
 

Create a map table with a specified number of slots.

Parameters:
number   of slots.

ost::MapTable::~MapTable ( ) [virtual]
 

Destroy the table, calls cleanup.


Member Function Documentation

void ost::MapTable::addFree ( MapObject * obj )
 

Add an object to the managed free list.

Some MapObject's may override delete operator to detach and do this.

Parameters:
object   to add.

void ost::MapTable::addObject ( MapObject & obj )
 

Map an object to our table.

If it is in another table already, it is removed there first.

Parameters:
object   to map.

void ost::MapTable::cleanup ( void ) [protected]
 

void * ost::MapTable::getFree ( void )
 

Get next object from managed free list.

This returns as a void so it can be recast into the actual type being used in derived MapObject's. A derived version of MapTable may well offer an explicit type version of this. Some derived MapObject's may override new to use managed list.

Returns:
next object on free list.

unsigned ost::MapTable::getIndex ( const char * id ) [virtual]
 

Get index value from id string.

This function can be changed as needed to provide better collision avoidence for specific tables.

Parameters:
id   string
Returns:
index slot in table.

void * ost::MapTable::getObject ( const char * id )
 

Lookup an object by id key.

It is returned as void * for easy re-cast.

Parameters:
key   to find.
Returns:
pointer to found object or NULL.

unsigned ost::MapTable::getRange ( void ) [inline]
 

Return range of this table.

Returns:
table range.

MapTable & ost::MapTable::operator+= ( MapObject & obj )
 

An operator to map an object to the table.

Returns:
table being used.
Parameters:
object   being mapped.

MapTable & ost::MapTable::operator-= ( MapObject & obj ) [virtual]
 

This operator is virtual in case it must also add the object to a managed free list.

Returns:
current table.
Parameters:
object   entity to remove.


Friends And Related Function Documentation

class MapObject [friend]
 


Member Data Documentation

MapObject ** ost::MapTable::map [protected]
 

unsigned ost::MapTable::range [protected]
 


The documentation for this class was generated from the following file:
Generated at Sat May 12 18:59:42 2007 for GNU CommonC++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001