ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for ost::MapTable:
[legend]

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 ()
 
void enterMutex (void)
 
void leaveMutex (void)
 
bool tryEnterMutex (void)
 
void enter (void)
 
void leave (void)
 
bool test (void)
 

Protected Member Functions

void cleanup (void)
 
- Protected Member Functions inherited from ucommon::RecursiveMutex
virtual void _lock (void) __OVERRIDE
 
virtual void _unlock (void) __OVERRIDE
 
 RecursiveMutex ()
 Create rexlock. More...
 
void lock (void)
 Acquire or increase locking. More...
 
bool lock (timeout_t timeout)
 Timed lock request. More...
 
void release (void)
 Release or decrease locking. More...
 

Protected Attributes

unsigned range
 
unsigned count
 
MapObject ** map
 
- Protected Attributes inherited from ucommon::RecursiveMutex
unsigned waiting
 
unsigned lockers
 
pthread_t locker
 

Private Member Functions

 __DELETE_COPY (MapTable)
 

Friends

class MapObject
 
class MapIndex
 

Additional Inherited Members

- Protected Types inherited from ucommon::RecursiveMutex
typedef autoexclusive< RecursiveMutexautolock
 

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.

Definition at line 349 of file object.h.

Constructor & Destructor Documentation

◆ MapTable()

ost::MapTable::MapTable ( unsigned  size)

Create a map table with a specified number of slots.

Parameters
numberof slots.

Definition at line 78 of file map.cpp.

References count, map, and range.

◆ ~MapTable()

ost::MapTable::~MapTable ( )
virtual

Destroy the table, calls cleanup.

Definition at line 87 of file map.cpp.

References cleanup().

Here is the call graph for this function:

Member Function Documentation

◆ __DELETE_COPY()

ost::MapTable::__DELETE_COPY ( MapTable  )
private

◆ 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.

Definition at line 171 of file map.cpp.

References ost::MapObject::detach(), ost::Mutex::enterMutex(), ost::Mutex::leaveMutex(), map, ost::MapObject::nextObject, and range.

Here is the call graph for this function:

◆ 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.

Definition at line 180 of file map.cpp.

References count, ost::MapObject::detach(), ost::Mutex::enterMutex(), getIndex(), ost::MapObject::idObject, ost::Mutex::leaveMutex(), map, ost::MapObject::nextObject, and ost::MapObject::table.

Referenced by operator+=().

Here is the call graph for this function:

◆ cleanup()

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

Definition at line 92 of file map.cpp.

References ost::Mutex::enterMutex(), ost::Mutex::leaveMutex(), and map.

Referenced by ~MapTable().

Here is the call graph for this function:

◆ 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.

Definition at line 442 of file object.h.

◆ 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.

Definition at line 128 of file map.cpp.

References ost::Mutex::enterMutex(), ost::Mutex::leaveMutex(), map, and range.

Here is the call graph for this function:

◆ 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.

Definition at line 161 of file map.cpp.

References ost::Mutex::enterMutex(), ost::Mutex::leaveMutex(), map, ost::MapObject::nextObject, and range.

Here is the call graph for this function:

◆ getIndex()

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.

Definition at line 101 of file map.cpp.

References range.

Referenced by addObject(), ost::MapObject::detach(), getObject(), and ost::MapIndex::operator++().

◆ 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.

Definition at line 143 of file map.cpp.

References ost::Mutex::enterMutex(), ost::Mutex::leaveMutex(), map, ost::MapObject::nextObject, and range.

Here is the call graph for this function:

◆ 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.

Definition at line 111 of file map.cpp.

References ost::Mutex::enterMutex(), getIndex(), ost::MapObject::idObject, ost::Mutex::leaveMutex(), map, ost::MapObject::nextObject, and stricmp().

Here is the call graph for this function:

◆ getRange()

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

Return range of this table.

Returns
table range.

Definition at line 391 of file object.h.

◆ getSize()

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

Return the number of object stored in this table.

Returns
table size.

Definition at line 400 of file object.h.

◆ operator+=()

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

An operator to map an object to the table.

Returns
table being used.
Parameters
objectbeing mapped.

Definition at line 196 of file map.cpp.

References addObject().

Here is the call graph for this function:

◆ operator-=()

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.

Definition at line 202 of file map.cpp.

References ost::MapObject::detach(), and ost::MapObject::table.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ MapIndex

friend class MapIndex
friend

Definition at line 356 of file object.h.

◆ MapObject

friend class MapObject
friend

Definition at line 355 of file object.h.

Member Data Documentation

◆ count

unsigned ost::MapTable::count
protected

Definition at line 358 of file object.h.

Referenced by addObject(), ost::MapObject::detach(), and MapTable().

◆ map

MapObject** ost::MapTable::map
protected

◆ range

unsigned ost::MapTable::range
protected

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