Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
7.9 KiB

  1. #ifndef _INC_DSKQUOTA_DYNARRAY_H
  2. #define _INC_DSKQUOTA_DYNARRAY_H
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: dynarray.h
  5. Description: Wrapper classes around the DPA_xxxxxxx and DSA_xxxxxx functions
  6. provided by the common control's library. The classes add value by
  7. providing multi-threaded protection, iterators and automatic cleanup
  8. semantics.
  9. Revision History:
  10. Date Description Programmer
  11. -------- --------------------------------------------------- ----------
  12. 06/14/96 Initial creation. BrianAu
  13. 09/03/96 Added exception handling. BrianAu
  14. */
  15. ///////////////////////////////////////////////////////////////////////////////
  16. #ifndef _WINDOWS_
  17. # include <windows.h>
  18. #endif
  19. #ifndef _INC_COMMCTRL
  20. # include <commctrl.h>
  21. #endif
  22. #ifndef _INC_COMCTRLP
  23. # include <comctrlp.h>
  24. #endif
  25. #ifndef _INC_DSKQUOTA_EXCEPT_H
  26. # include "except.h"
  27. #endif
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // CONTAINER EXCEPTIONS
  30. ///////////////////////////////////////////////////////////////////////////////
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // POINTER LIST
  33. ///////////////////////////////////////////////////////////////////////////////
  34. class PointerList
  35. {
  36. private:
  37. HDPA m_hdpa;
  38. CRITICAL_SECTION m_cs;
  39. public:
  40. PointerList(INT cItemGrow = 0);
  41. virtual ~PointerList(void);
  42. UINT Count(void);
  43. VOID Insert(LPVOID pvItem, UINT index);
  44. VOID Insert(LPVOID pvItem)
  45. { Insert(pvItem, 0); }
  46. VOID Append(LPVOID pvItem, UINT index)
  47. { Insert(pvItem, index + 1); }
  48. VOID Append(LPVOID pvItem);
  49. BOOL Remove(LPVOID *ppvItem, UINT index);
  50. BOOL RemoveFirst(LPVOID *ppvItem)
  51. { return Remove(ppvItem, 0); }
  52. BOOL RemoveLast(LPVOID *ppvItem);
  53. BOOL Retrieve(LPVOID *ppvItem, UINT index);
  54. BOOL RetrieveFirst(LPVOID *ppvItem)
  55. { return Retrieve(ppvItem, 0); }
  56. BOOL RetrieveLast(LPVOID *ppvItem);
  57. BOOL Replace(LPVOID pvItem, UINT index);
  58. BOOL FindIndex(LPVOID pvItem, INT *pIndex);
  59. BOOL Sort(PFNDPACOMPARE pfnCompare, LPARAM lParam);
  60. BOOL Search(LPVOID pvKey,
  61. PFNDPACOMPARE pfnCompare,
  62. UINT uOptions = 0,
  63. INT iStart = 0,
  64. LPARAM lParam = 0);
  65. void Lock(void)
  66. { EnterCriticalSection(&m_cs); }
  67. void ReleaseLock(void)
  68. { LeaveCriticalSection(&m_cs); }
  69. friend class PointerListIterator;
  70. friend class AutoLock;
  71. };
  72. ///////////////////////////////////////////////////////////////////////////////
  73. // POINTER LIST ITERATOR
  74. ///////////////////////////////////////////////////////////////////////////////
  75. class PointerListIterator {
  76. private:
  77. PointerList *m_pList; // Pointer to list being iterated.
  78. INT m_Index; // "Current" signed index into list.
  79. HRESULT Advance(LPVOID *ppvOut, BOOL bForward);
  80. public:
  81. enum { EndOfList = -1 };
  82. PointerListIterator(PointerList& List)
  83. : m_pList(&List),
  84. m_Index(0) { }
  85. PointerListIterator(const PointerListIterator& rhs)
  86. : m_pList(rhs.m_pList),
  87. m_Index(rhs.m_Index) { }
  88. PointerListIterator& operator = (const PointerListIterator& rhs);
  89. HRESULT Next(LPVOID *ppvOut)
  90. { return Advance(ppvOut, TRUE); }
  91. HRESULT Prev(LPVOID *ppvOut)
  92. { return Advance(ppvOut, FALSE); }
  93. BOOL AtFirst(void)
  94. { return m_Index == 0; }
  95. BOOL AtLast(void)
  96. { return m_Index >= (INT)m_pList->Count() - 1; }
  97. void GotoFirst(void)
  98. { m_Index = 0; }
  99. void GotoLast(void)
  100. { m_Index = m_pList->Count() - 1; }
  101. void LockList(void)
  102. { m_pList->Lock(); }
  103. void ReleaseListLock(void)
  104. { m_pList->ReleaseLock(); }
  105. };
  106. ///////////////////////////////////////////////////////////////////////////////
  107. // POINTER QUEUE
  108. ///////////////////////////////////////////////////////////////////////////////
  109. class PointerQueue : public PointerList
  110. {
  111. public:
  112. virtual ~PointerQueue(void) { }
  113. VOID Add(LPVOID pvItem)
  114. { PointerList::Append(pvItem); }
  115. BOOL Remove(LPVOID *ppvItem)
  116. { return PointerList::RemoveFirst(ppvItem); }
  117. };
  118. ///////////////////////////////////////////////////////////////////////////////
  119. // STRUCTURE LIST
  120. //
  121. ///////////////////////////////////////////////////////////////////////////////
  122. class StructureList
  123. {
  124. private:
  125. HDSA m_hdsa;
  126. CRITICAL_SECTION m_cs;
  127. public:
  128. StructureList(INT cbItem, INT cItemGrow);
  129. virtual ~StructureList(void);
  130. UINT Count(void);
  131. VOID Insert(LPVOID pvItem, UINT index);
  132. VOID Insert(LPVOID pvItem)
  133. { Insert(pvItem, 0); }
  134. VOID Append(LPVOID pvItem, UINT index)
  135. { Insert(pvItem, index + 1); }
  136. VOID Append(LPVOID pvItem);
  137. BOOL Remove(LPVOID pvItem, UINT index);
  138. BOOL RemoveFirst(LPVOID pvItem)
  139. { return Remove(pvItem, 0); }
  140. BOOL RemoveLast(LPVOID pvItem);
  141. BOOL Retrieve(LPVOID pvItem, UINT index);
  142. BOOL RetrieveFirst(LPVOID pvItem)
  143. { return Retrieve(pvItem, 0); }
  144. BOOL RetrieveLast(LPVOID pvItem);
  145. BOOL Replace(LPVOID pvItem, UINT index);
  146. VOID Clear(VOID);
  147. void Lock(void)
  148. { EnterCriticalSection(&m_cs); }
  149. void ReleaseLock(void)
  150. { LeaveCriticalSection(&m_cs); }
  151. friend class StructureListIterator;
  152. friend class AutoLock;
  153. };
  154. ///////////////////////////////////////////////////////////////////////////////
  155. // STRUCTURE LIST ITERATOR
  156. ///////////////////////////////////////////////////////////////////////////////
  157. class StructureListIterator {
  158. private:
  159. StructureList *m_pList; // Pointer to list being iterated.
  160. INT m_Index; // "Current" signed index into list.
  161. HRESULT Advance(LPVOID *ppvOut, BOOL bForward);
  162. public:
  163. enum { EndOfList = -1 };
  164. StructureListIterator(StructureList& List)
  165. : m_pList(&List),
  166. m_Index(0) { }
  167. StructureListIterator(const StructureListIterator& rhs)
  168. : m_pList(rhs.m_pList),
  169. m_Index(rhs.m_Index) { }
  170. StructureListIterator& operator = (const StructureListIterator& rhs);
  171. HRESULT Next(LPVOID *ppvOut)
  172. { return Advance(ppvOut, TRUE); }
  173. HRESULT Prev(LPVOID *ppvOut)
  174. { return Advance(ppvOut, FALSE); }
  175. BOOL AtFirst(void)
  176. { return m_Index == 0; }
  177. BOOL AtLast(void)
  178. { return m_Index >= (INT)m_pList->Count() - 1; }
  179. void GotoFirst(void)
  180. { m_Index = 0; }
  181. void GotoLast(void)
  182. { m_Index = m_pList->Count() - 1; }
  183. void LockList(void)
  184. { m_pList->Lock(); }
  185. void ReleaseListLock(void)
  186. { m_pList->ReleaseLock(); }
  187. };
  188. ///////////////////////////////////////////////////////////////////////////////
  189. // STRUCTURE QUEUE
  190. ///////////////////////////////////////////////////////////////////////////////
  191. class StructureQueue : public StructureList
  192. {
  193. public:
  194. StructureQueue(INT cbItem, INT cItemGrow)
  195. : StructureList(cbItem, cItemGrow) { }
  196. virtual ~StructureQueue(void) { }
  197. VOID Add(LPVOID pvItem)
  198. { StructureList::Append(pvItem); }
  199. BOOL Remove(LPVOID pvItem)
  200. { return StructureList::RemoveFirst(pvItem); }
  201. };
  202. #endif // _INC_DSKQUOTA_DYNARRAY_H