Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cUIDManagerArray.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cUIDManagerArray_H
7 #define _INC_cUIDManagerArray_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cUID.h"
13 #include "XObject/cXObjDef.h" // IXObject or IUnkObject ??
14 
19 
20 namespace GrayLib
21 {
23 
24  // class GRAYLIB_LINK cXObject;
25  // typedef cRefPtr<cXObject> cXObjectPtr;
26 
27  DECLARE_INTERFACE(IUIDManager)
28  {
29  // TODO add more
30  virtual cXObjectPtr FindUIDObj(UID_t uid) const = 0;
31  };
32 
33  class GRAYLIB_LINK cUIDManagerArray : public cThreadLockCount, public IUIDManager
34  {
40 #define UID_PLACE_HOLDER ((cXObject*)(INT_PTR)(-1)) // junk pointer
41 
42  public:
43  cUIDManagerArray(const cUIDRangeMask& mask, bool bReUseFreedUIDs = true);
44  ~cUIDManagerArray();
45 
46  UIDINDEX_t get_UIDCount() const noexcept
47  {
48  // Get Max UID.
49  return (UIDINDEX_t)m_aUIDs.GetSize();
50  }
51  virtual cXObjectPtr FindUIDObj(UID_t nUID) const
52  {
53  if (nUID == cUID::k_CLEAR)
54  return nullptr;
55  UIDINDEX_t dwIndex = m_UIDRange.U2I(nUID);
56  if (dwIndex == 0 || !m_aUIDs.IsValidIndex(dwIndex))
57  return nullptr;
58  if (m_aUIDs[dwIndex] == UID_PLACE_HOLDER) // unusable for now. (background save is going on)
59  return nullptr;
60  return m_aUIDs[dwIndex];
61  }
62  bool isIndexPlaceHolder(UIDINDEX_t dwIndex) const
63  {
64  ASSERT(m_UIDRange.IsValidIndex(dwIndex));
65  return m_aUIDs[dwIndex] == UID_PLACE_HOLDER;
66  }
67  void ClearUIDPlaceHolder(UID_t nUID);
68 
69  bool FreeUID(UID_t nUID);
70  bool FreeUID(cXObject* pObj);
71  UID_t LoadUID(cXObject* pObj, UID_t dwIndex);
72  UID_t AllocUID(cXObject* pObj);
73 
74  void FlushFreeUIDs();
75  void DisposeAllUIDs();
76  void put_ReUseFreeUIDs(bool bReUseFreeUIDs);
77 
79 
80  protected:
81  UIDINDEX_t FindFreeIndex();
82 
83  public:
85 
86  private:
87  bool m_bReUseFreedUIDs;
88  UIDINDEX_t m_nIndexLast;
89 
90  cArrayPtr<cXObject> m_aUIDs;
91  };
92 }
93 #endif // _INC_cUIDManagerArray_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define UID_PLACE_HOLDER
Definition: cUIDManagerArray.h:40
Definition: cUIDManagerArray.h:34
cUIDRangeMask m_UIDRange
Mask of the range of valid UID's (allow high bits to float)
Definition: cUIDManagerArray.h:84
UIDINDEX_t get_UIDCount() const noexcept
Definition: cUIDManagerArray.h:46
virtual cXObjectPtr FindUIDObj(UID_t nUID) const
Definition: cUIDManagerArray.h:51
bool isIndexPlaceHolder(UIDINDEX_t dwIndex) const
Definition: cUIDManagerArray.h:62
UNITTEST_FRIEND(cUIDManagerArray)
Definition: cUID.h:72
static const UID_t k_CLEAR
Hard coded UID_t values.
Definition: cUID.h:32
Definition: cXObject.h:78
Definition: cArray.h:864
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)
DECLARE_INTERFACE(IScriptableSetter)
HASHCODE32_t UID_t
Sort of the same as a HASHCODE_t. not the same as UIDINDEX_t.
Definition: cUID.h:18