GNU CommonC++
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ost::MapTable Class Reference

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

#include <object.h>

Inheritance diagram for ost::MapTable:
ost::Mutex

Public Member Functions

 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...
 
unsigned getSize (void)
 Return the number of object stored in 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 * getFirst ()
 Get the first element into table, it is returned as void * for easy re-cast. More...
 
void * getLast ()
 Get the last element into table, it is returned as void * for easy re-cast. More...
 
void * getEnd ()
 Get table's end, useful for cycle control; it is returned as void * for easy re-cast. 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...
 
MapTableoperator+= (MapObject &obj)
 An operator to map an object to the table. More...
 
virtual MapTableoperator-= (MapObject &obj)
 This operator is virtual in case it must also add the object to a managed free list. More...
 
- Public Member Functions inherited from ost::Mutex
 Mutex (const char *name=NULL)
 The mutex is always initialized as a recursive entity. More...
 
virtual ~Mutex ()
 Destroying the mutex removes any system resources associated with it. More...
 
void nameMutex (const char *name)
 Enable setting of mutex name for deadlock debug. More...
 
void enterMutex (void)
 Entering a Mutex locks the mutex for the current thread. More...
 
void enter (void)
 Future abi will use enter/leave/test members. More...
 
void leave (void)
 Future abi will use enter/leave/test members. More...
 
bool test (void)
 Future abi will use enter/leave/test members. More...
 
bool tryEnterMutex (void)
 Tries to lock the mutex for the current thread. More...
 
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread. More...
 

Protected Member Functions

void cleanup (void)
 

Protected Attributes

unsigned range
 
unsigned count
 
MapObject ** map
 

Friends

class MapObject
 
class MapIndex
 

Additional Inherited Members

- Static Public Member Functions inherited from ost::Mutex
static void setDebug (bool mode)
 Enable or disable deadlock debugging. More...
 

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.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Table to hold hash indexed objects.

Constructor & Destructor Documentation

◆ MapTable()

ost::MapTable::MapTable ( unsigned  size)

Create a map table with a specified number of slots.

Parameters
numberof slots.

◆ ~MapTable()

virtual ost::MapTable::~MapTable ( )
virtual

Destroy the table, calls cleanup.

Member Function Documentation

◆ addFree()

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
objectto add.

◆ addObject()

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
objectto map.

◆ cleanup()

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

◆ getEnd()

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.

◆ getFirst()

void* ost::MapTable::getFirst ( )

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

Returns
pointer to found object or NULL.

◆ getFree()

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.

◆ getIndex()

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.

◆ getLast()

void* ost::MapTable::getLast ( )

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

Returns
pointer to found object or NULL.

◆ getObject()

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.

◆ getRange()

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

Return range of this table.

Returns
table range.

◆ getSize()

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

Return the number of object stored in this table.

Returns
table size.

◆ operator+=()

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

An operator to map an object to the table.

Returns
table being used.
Parameters
objectbeing mapped.

◆ operator-=()

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.

Friends And Related Function Documentation

◆ MapIndex

friend class MapIndex
friend

◆ MapObject

friend class MapObject
friend

Member Data Documentation

◆ count

unsigned ost::MapTable::count
protected

◆ map

MapObject** ost::MapTable::map
protected

◆ range

unsigned ost::MapTable::range
protected

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