ucommon
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
ost::MapTable Class Reference

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

#include <object.h>

Inherits ost::Mutex.

Collaboration diagram for ost::MapTable:
Collaboration graph
[legend]

Public Member Functions

void addFree (MapObject *obj)
 Add an object to the managed free list.
void addObject (MapObject &obj)
 Map an object to our table.
void * getEnd ()
 Get table's end, useful for cycle control; it is returned as void * for easy re-cast.
void * getFirst ()
 Get the first element into table, it is returned as void * for easy re-cast.
void * getFree (void)
 Get next object from managed free list.
virtual unsigned getIndex (const char *id)
 Get index value from id string.
void * getLast ()
 Get the last element into table, it is returned as void * for easy re-cast.
void * getObject (const char *id)
 Lookup an object by id key.
unsigned getRange (void)
 Return range of this table.
unsigned getSize (void)
 Return the number of object stored in this table.
 MapTable (unsigned size)
 Create a map table with a specified number of slots.
MapTableoperator+= (MapObject &obj)
 An operator to map an object to the table.
virtual MapTableoperator-= (MapObject &obj)
 This operator is virtual in case it must also add the object to a managed free list.
virtual ~MapTable ()
 Destroy the table, calls cleanup.

Protected Member Functions

void cleanup (void)

Protected Attributes

unsigned count
MapObject ** map
unsigned range

Friends

class MapIndex
class MapObject

Detailed Description

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

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> Table to hold hash indexed objects.

Definition at line 332 of file object.h.


Constructor & Destructor Documentation

ost::MapTable::MapTable ( unsigned  size)

Create a map table with a specified number of slots.

Parameters:
numberof slots.

Member Function Documentation

Add an object to the managed free list.

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

Parameters:
objectto add.

Map an object to our table.

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

Parameters:
objectto map.
void* ost::MapTable::getEnd ( ) [inline]

Get table's end, useful for cycle control; it is returned as void * for easy re-cast.

Returns:
pointer to found object or NULL.

Definition at line 420 of file object.h.

Get the first element into table, it is returned as void * for easy re-cast.

Returns:
pointer to found object or NULL.
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.
virtual 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:
idstring
Returns:
index slot in table.

Get the last element into table, it is returned as void * for easy re-cast.

Returns:
pointer to found object or NULL.
void* ost::MapTable::getObject ( const char *  id)

Lookup an object by id key.

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

Parameters:
keyto find.
Returns:
pointer to found object or NULL.
unsigned ost::MapTable::getRange ( void  ) [inline]

Return range of this table.

Returns:
table range.

Definition at line 371 of file object.h.

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

Return the number of object stored in this table.

Returns:
table size.

Definition at line 379 of file object.h.

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

An operator to map an object to the table.

Returns:
table being used.
Parameters:
objectbeing mapped.
virtual 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:
objectentity to remove.

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