#include <object.h>
Public Member Functions | |
MapTable (unsigned size) | |
Create a map table with a specified number of slots. | |
virtual | ~MapTable () |
Destroy the table, calls cleanup. | |
virtual unsigned | getIndex (const char *id) |
Get index value from id string. | |
unsigned | getRange (void) |
Return range of this table. | |
void * | getObject (const char *id) |
Lookup an object by id key. | |
void | addObject (MapObject &obj) |
Map an object to our table. | |
void * | getFree (void) |
Get next object from managed free list. | |
void | addFree (MapObject *obj) |
Add an object to the managed free list. | |
MapTable & | operator+= (MapObject &obj) |
An operator to map an object to the table. | |
virtual MapTable & | operator-= (MapObject &obj) |
This operator is virtual in case it must also add the object to a managed free list. | |
Protected Member Functions | |
void | cleanup (void) |
Protected Attributes | |
unsigned | range |
MapObject ** | map |
Friends | |
class | MapObject |
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.
ost::MapTable::MapTable | ( | unsigned | size | ) |
Create a map table with a specified number of slots.
number | of slots. |
virtual ost::MapTable::~MapTable | ( | ) | [virtual] |
Destroy the table, calls cleanup.
void ost::MapTable::cleanup | ( | void | ) | [protected] |
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.
id | string |
unsigned ost::MapTable::getRange | ( | void | ) | [inline] |
Return range of this table.
void* ost::MapTable::getObject | ( | const char * | id | ) |
Lookup an object by id key.
It is returned as void * for easy re-cast.
key | to find. |
void ost::MapTable::addObject | ( | MapObject & | obj | ) |
Map an object to our table.
If it is in another table already, it is removed there first.
object | to map. |
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.
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.
object | to add. |
An operator to map an object to the table.
object | being mapped. |
This operator is virtual in case it must also add the object to a managed free list.
object | entity to remove. |
friend class MapObject [friend] |
unsigned ost::MapTable::range [protected] |
MapObject** ost::MapTable::map [protected] |