Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cUIDManagerTable.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cUIDManagerTable_H
7 #define _INC_cUIDManagerTable_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cUID.h"
13 #ifdef USE_SQL
14 #include "cUIDManagerArray.h"
19 
20 namespace GrayLib
21 {
23 
27 
28  class GRAYLIB_LINK cUIDManagerTable : public IUIDManager
29  {
37 
38  static const int k_RANGE_SIZE = 10000;
39 
40  public:
41  static const char k_FreePostfix[5];
42 
43  public:
44  cUIDManagerTable(const cUIDRangeMask& mask, const char* pszTableName);
46 
47  HRESULT OpenPoolCheck(cSQLDatabase* pDB, cSQLStatementQ& rs);
48  void ClosePool(cSQLDatabasePool& dbp);
49 
50  cString get_StatusString() const;
51  bool IsFreeOrDeleted(UID_t uid) const;
52 
53  UIDINDEX_t get_UIDCount() const;
54  cXObjectPtr FindObjIter(cHashIterator& e) const;
55  virtual cXObjectPtr FindUIDObj(UID_t uid) const;
56 
57  HRESULT CreateUID(cSQLDatabasePool& db, cXObject* pObj);
58  HRESULT LoadUID(cSQLDatabasePool& db, cXObject* pObj, UIDINDEX_t index);
59  void DeleteUIDIndex(UID_t uid, bool bFree, bool bWasSaved);
60  void DeleteUID(cXObject* pObj, bool bFree);
61 
62  void ClearDeletedUIDs(cSQLDatabasePool& db);
63  void SaveFreeUIDs(cSQLDatabasePool& db); // Save all free UIDs back to database.
64 
65  // Only Node 0 can do this!
66  HRESULT RebuildFreeUIDTable(cSQLDatabasePool& db, UIDINDEX_t dwMaxQty);
67 
69 
70  private:
71  const char* get_TableName() const noexcept
72  {
73  // get the name of the table that stores the full object.
74  return m_pszTableName;
75  }
76 
77  int AddFreeUIDRange(UIDINDEX_t dwIndexBegin, UIDINDEX_t dwIndexEnd);
78  HRESULT ClaimFreeUIDRangeRead(cSQLDatabasePool& db, const char* pszTable, int& nIndexes);
79  HRESULT ClaimFreeUIDRange(cSQLDatabasePool& db);
80 
81  HRESULT SaveFreeUIDRange(cSQLDatabasePool& db, UIDINDEX_t dwIndexBegin, UIDINDEX_t dwIndexEnd);
82  void Dump_DeletedUIDs();
83 
84  public:
86 
89  bool m_bLogDelete;
90 
91  private:
92  mutable cThreadLockCount m_Lock;
93  cArraySortVal<UIDINDEX_t> m_DeletedIndexes;
94  cArraySortVal<UIDINDEX_t> m_FreeIndexes;
95  const char* m_pszTableName; // get the name of the table that stores the full object. add 'Free' Postfix to this.
96  };
97 }
98 #endif // USE_SQL
99 #endif // _INC_cUIDManagerTable_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cSQLDatabasePool.h:18
Definition: cSQLDatabase.h:30
Definition: cSQLStatement.h:109
Definition: cUIDManagerTable.h:29
UNITTEST_FRIEND(cUIDManagerTable)
const cUIDRangeMask m_UIDRange
Mask of the range of valid UID's (allow high bits to float)
Definition: cUIDManagerTable.h:85
cHashTableRef< cXObject, UID_t, 9 > m_UsedUIDs
9 bits = 512 buckets
Definition: cUIDManagerTable.h:88
bool m_bLogDelete
track deletes. in log
Definition: cUIDManagerTable.h:89
Definition: cUID.h:72
Definition: cXObject.h:78
Definition: cHashTable.h:20
Definition: cHashTable.h:191
Definition: cThreadLock.h:498
Definition: cMesh.h:22
int UIDINDEX_t
non dressed (partial) UID_t. just an index in a range inside the UID_t. k_HASHCODE_CLEAR
Definition: cUID.h:69
UNITTEST2_PREDEF(cQuadtree)
HASHCODE32_t UID_t
Sort of the same as a HASHCODE_t. not the same as UIDINDEX_t.
Definition: cUID.h:18
uint16 index
Definition: sample3.cpp:29