Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cUIDManagerTable Class Reference

#include <cUIDManagerTable.h>

Inheritance diagram for GrayLib::cUIDManagerTable:

Public Member Functions

 cUIDManagerTable (const cUIDRangeMask &mask, const char *pszTableName)
 
 ~cUIDManagerTable ()
 
HRESULT OpenPoolCheck (cSQLDatabase *pDB, cSQLStatementQ &rs)
 
void ClosePool (cSQLDatabasePool &dbp)
 
cString get_StatusString () const
 
bool IsFreeOrDeleted (UID_t uid) const
 
UIDINDEX_t get_UIDCount () const
 
cXObjectPtr FindObjIter (cHashIterator &e) const
 
virtual cXObjectPtr FindUIDObj (UID_t uid) const
 
HRESULT CreateUID (cSQLDatabasePool &db, cXObject *pObj)
 
HRESULT LoadUID (cSQLDatabasePool &db, cXObject *pObj, UIDINDEX_t index)
 
void DeleteUIDIndex (UID_t uid, bool bFree, bool bWasSaved)
 
void DeleteUID (cXObject *pObj, bool bFree)
 
void ClearDeletedUIDs (cSQLDatabasePool &db)
 
void SaveFreeUIDs (cSQLDatabasePool &db)
 
HRESULT RebuildFreeUIDTable (cSQLDatabasePool &db, UIDINDEX_t dwMaxQty)
 
 UNITTEST_FRIEND (cUIDManagerTable)
 

Public Attributes

const cUIDRangeMask m_UIDRange
 Mask of the range of valid UID's (allow high bits to float) More...
 
cHashTableRef< cXObject, UID_t, 9 > m_UsedUIDs
 9 bits = 512 buckets More...
 
bool m_bLogDelete
 track deletes. in log More...
 

Static Public Attributes

static const char k_FreePostfix [5] = "Free"
 

Detailed Description

Manage the list of free/used UIDs in a SQL database table. Manage a range of used UID's. Have a fast way to find a free UID. Manage multi server contention by multiple requesting nodes. Must be atomic transactions!

Note
USE_CLEAR = 0 UID is reserved. as are values outside m_Mask

Constructor & Destructor Documentation

◆ cUIDManagerTable()

GrayLib::cUIDManagerTable::cUIDManagerTable ( const cUIDRangeMask mask,
const char *  pszTableName 
)

◆ ~cUIDManagerTable()

GrayLib::cUIDManagerTable::~cUIDManagerTable ( )

This table should already be unloaded by now?!

Member Function Documentation

◆ ClearDeletedUIDs()

void GrayLib::cUIDManagerTable::ClearDeletedUIDs ( cSQLDatabasePool db)

Convert m_DeletedIndexes back to m_FreeIndexes So they may be used again. (internally on this node only)

◆ ClosePool()

void GrayLib::cUIDManagerTable::ClosePool ( cSQLDatabasePool dbp)

The app is closing or restarting.

Can't actually delete UID's without doing a proper save!

◆ CreateUID()

HRESULT GrayLib::cUIDManagerTable::CreateUID ( cSQLDatabasePool db,
cXObject pObj 
)

New Object. Try to give it a new UID. so find a free UID.

◆ DeleteUID()

void GrayLib::cUIDManagerTable::DeleteUID ( cXObject pObj,
bool  bFree 
)

This sort of deletes the object. Should NOT be actually deleted until a save is executed. Clearing the object from the DB Called by cXObject::DisposeThis() bFree = this is legit freed, (Not just unloaded or closing app)

◆ DeleteUIDIndex()

void GrayLib::cUIDManagerTable::DeleteUIDIndex ( UID_t  uid,
bool  bFree,
bool  bWasSaved 
)

Can't free up the UID until after the save ! Just put in free pool locally for now.

  • bFree = this is legit freed, (Not just unloaded or closing app) bWasSaved = i can't use this UID again until i reconcile the Save

◆ FindObjIter()

cXObjectPtr GrayLib::cUIDManagerTable::FindObjIter ( cHashIterator e) const

iterate thru the objects.

◆ FindUIDObj()

cXObjectPtr GrayLib::cUIDManagerTable::FindUIDObj ( UID_t  uid) const
virtual

find a particular object.

◆ get_StatusString()

cString GrayLib::cUIDManagerTable::get_StatusString ( ) const

◆ get_UIDCount()

UIDINDEX_t GrayLib::cUIDManagerTable::get_UIDCount ( ) const

◆ IsFreeOrDeleted()

bool GrayLib::cUIDManagerTable::IsFreeOrDeleted ( UID_t  uid) const

Test the state of this particular UID.

◆ LoadUID()

HRESULT GrayLib::cUIDManagerTable::LoadUID ( cSQLDatabasePool db,
cXObject pObj,
UIDINDEX_t  index 
)

Loading an object that wants a specific UID. nUID = Set to this UID

Returns
<0 = failed.

◆ OpenPoolCheck()

HRESULT GrayLib::cUIDManagerTable::OpenPoolCheck ( cSQLDatabase pDB,
cSQLStatementQ rs 
)

check for essential tables in M$ db. (e.g. XXX and XXXFree)

◆ RebuildFreeUIDTable()

HRESULT GrayLib::cUIDManagerTable::RebuildFreeUIDTable ( cSQLDatabasePool db,
UIDINDEX_t  dwMaxQty 
)

Wipe the free UID table and rebuild it from the current used UID table!

Note
ASSUME there are no other servers using the database right now!!
If a server resets with free UID's reserved. they will be leaked! This function can fix it.
ONLY one node may do this at a time. The others may not use the tables during that time! TODO: create a locking mechanism for the database !? rename DB ?

◆ SaveFreeUIDs()

void GrayLib::cUIDManagerTable::SaveFreeUIDs ( cSQLDatabasePool db)

Flush all unused free UID ranges back to the database. ASSUME we are closing the app gracefully.

◆ UNITTEST_FRIEND()

GrayLib::cUIDManagerTable::UNITTEST_FRIEND ( cUIDManagerTable  )

Member Data Documentation

◆ k_FreePostfix

const char GrayLib::cUIDManagerTable::k_FreePostfix = "Free"
static

◆ m_bLogDelete

bool GrayLib::cUIDManagerTable::m_bLogDelete

track deletes. in log

◆ m_UIDRange

const cUIDRangeMask GrayLib::cUIDManagerTable::m_UIDRange

Mask of the range of valid UID's (allow high bits to float)

◆ m_UsedUIDs

cHashTableRef<cXObject, UID_t, 9> GrayLib::cUIDManagerTable::m_UsedUIDs

9 bits = 512 buckets

UIDs and the objects using them.


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