Leaked source code of windows server 2003
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.

349 lines
20 KiB

  1. #ifndef _CONTAINED_LIST_H_
  2. #define _CONTAINED_LIST_H_
  3. #define CLIST_DEFAULT_MAX_ITEMS 4
  4. #define CLIST_END_OF_ARRAY_MARK ((UINT) -1)
  5. class CList
  6. {
  7. public:
  8. CList(void);
  9. CList(ULONG cMaxItems);
  10. CList(ULONG cMaxItems, ULONG cSubItems);
  11. CList(ULONG cMaxItems, ULONG cSubItems, BOOL fQueue);
  12. CList(CList *pSrc);
  13. ~CList(void);
  14. BOOL Append(LPVOID pData);
  15. BOOL Prepend(LPVOID pData);
  16. BOOL Find(LPVOID pData);
  17. BOOL Remove(LPVOID pData);
  18. LPVOID Get(void);
  19. LPVOID Iterate(void);
  20. void Reset(void) { m_nCurrOffset = CLIST_END_OF_ARRAY_MARK; };
  21. void Clear(void) { m_cEntries = 0; m_nHeadOffset = 0; m_nCurrOffset = CLIST_END_OF_ARRAY_MARK; };
  22. UINT GetCount(void) { return m_cEntries; };
  23. BOOL IsEmpty(void) { return (m_cEntries == 0); };
  24. LPVOID PeekHead(void) { return (0 != m_cEntries) ? m_aEntries[m_nHeadOffset] : NULL; }
  25. protected:
  26. void CalcKeyArray(void);
  27. protected:
  28. ULONG m_cEntries;
  29. ULONG m_cMaxEntries;
  30. ULONG m_nHeadOffset;
  31. ULONG m_nCurrOffset;
  32. ULONG m_cSubItems; // 1 for CList, 2 for CList2
  33. BOOL m_fQueue; // TRUE for CQueue, FALSE for CList
  34. LPVOID *m_aEntries;
  35. UINT_PTR *m_aKeys; // for CList2
  36. private:
  37. BOOL Expand(void);
  38. BOOL Init(ULONG cSubItems);
  39. };
  40. #define DEFINE_CLIST(_NewClass_,_PtrItemType_) \
  41. public: \
  42. _NewClass_(void) : CList() { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  43. _NewClass_(ULONG cMaxItems) : CList(cMaxItems) { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  44. _NewClass_(_NewClass_ *pSrc) : CList((CList *) pSrc) { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  45. _NewClass_(_NewClass_ &Src) : CList((CList *) &Src) { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  46. BOOL Append(_PtrItemType_ pData) { return CList::Append((LPVOID) pData); } \
  47. BOOL Prepend(_PtrItemType_ pData) { return CList::Prepend((LPVOID) pData); } \
  48. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  49. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  50. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  51. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  52. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); }
  53. #define DEFINE_CLIST_(_NewClass_,_IntItemType_) \
  54. public: \
  55. _NewClass_(void) : CList() { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  56. _NewClass_(ULONG cMaxItems) : CList(cMaxItems) { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  57. _NewClass_(_NewClass_ *pSrc) : CList((CList *) pSrc) { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  58. _NewClass_(_NewClass_ &Src) : CList((CList *) &Src) { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  59. BOOL Append(_IntItemType_ nData) { return CList::Append((LPVOID) nData); } \
  60. BOOL Prepend(_IntItemType_ nData) { return CList::Prepend((LPVOID) nData); } \
  61. BOOL Remove(_IntItemType_ nData) { return CList::Remove((LPVOID) nData); } \
  62. BOOL Find(_IntItemType_ nData) { return CList::Find((LPVOID) nData); } \
  63. _IntItemType_ Get(void) { return (_IntItemType_) (UINT_PTR) CList::Get(); } \
  64. _IntItemType_ PeekHead(void) { return (_IntItemType_) (UINT_PTR) CList::PeekHead(); } \
  65. _IntItemType_ Iterate(void) { return (_IntItemType_) (UINT_PTR) CList::Iterate(); }
  66. class CList2 : public CList
  67. {
  68. public:
  69. CList2(ULONG cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList(cMaxItems, 2) { }
  70. CList2(ULONG cMaxItems, BOOL fQueue) : CList(cMaxItems, 2, fQueue) { }
  71. CList2(CList2 *pSrc);
  72. BOOL Append(UINT_PTR nKey, LPVOID pData);
  73. BOOL Prepend(UINT_PTR nKey, LPVOID pData);
  74. // BOOL Remove(LPVOID pData); // inherited from CList
  75. LPVOID Remove(UINT_PTR nKey);
  76. // BOOL Find(LPVOID pData); // inherited from CList
  77. LPVOID Find(UINT_PTR nKey);
  78. // LPVOID Get(void); // inheirted from CList
  79. LPVOID Get(UINT_PTR *pnKey);
  80. // LPVOID Iterate(void); // inherited from CList
  81. LPVOID Iterate(UINT_PTR *pnKey);
  82. LPVOID PeekHead(UINT_PTR *pnKey);
  83. };
  84. #define DEFINE_CLIST2(_NewClass_,_PtrItemType_,_IntKeyType_) \
  85. public: \
  86. _NewClass_(void) : CList2() { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  87. _NewClass_(ULONG cMaxItems) : CList2(cMaxItems) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  88. _NewClass_(_NewClass_ *pSrc) : CList2((CList2 *) pSrc) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  89. _NewClass_(_NewClass_ &Src) : CList2((CList2 *) &Src) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  90. BOOL Append(_IntKeyType_ nKey, _PtrItemType_ pData) { return CList2::Append((UINT_PTR) nKey, (LPVOID) pData); } \
  91. BOOL Prepend(_IntKeyType_ nKey, _PtrItemType_ pData) { return CList2::Prepend((UINT_PTR) nKey, (LPVOID) pData); } \
  92. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  93. _PtrItemType_ Remove(_IntKeyType_ nKey) { return (_PtrItemType_) (UINT_PTR) CList2::Remove((UINT_PTR) nKey); } \
  94. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  95. _PtrItemType_ Find(_IntKeyType_ nKey) { return (_PtrItemType_) (UINT_PTR) CList2::Find((UINT_PTR) nKey); } \
  96. _PtrItemType_ Get(void) { return (_PtrItemType_) (UINT_PTR) CList::Get(); } \
  97. _PtrItemType_ Get(_IntKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) (UINT_PTR) CList2::Get(&n); *pnKey = (_IntKeyType_) n; return p; } \
  98. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) (UINT_PTR) CList::PeekHead(); } \
  99. _PtrItemType_ PeekHead(_IntKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) (UINT_PTR) CList2::PeekHead(&n); *pnKey = (_IntKeyType_) n; return p; } \
  100. _PtrItemType_ Iterate(void) { return (_PtrItemType_) (UINT_PTR) CList::Iterate(); } \
  101. _PtrItemType_ Iterate(_IntKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) (UINT_PTR) CList2::Iterate(&n); *pnKey = (_IntKeyType_) n; return p; }
  102. #define DEFINE_CLIST2_(_NewClass_,_PtrItemType_,_ShortKeyType_) \
  103. DEFINE_CLIST2(_NewClass_,_PtrItemType_,_ShortKeyType_)
  104. #define DEFINE_CLIST2__(_NewClass_,_IntKeyType_) \
  105. public: \
  106. _NewClass_(void) : CList2() { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) <= sizeof(LPVOID)); } \
  107. _NewClass_(ULONG cMaxItems) : CList2(cMaxItems) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) <= sizeof(LPVOID)); } \
  108. _NewClass_(_NewClass_ *pSrc) : CList2((CList2 *) pSrc) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) <= sizeof(LPVOID)); } \
  109. _NewClass_(_NewClass_ &Src) : CList2((CList2 *) &Src) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) <= sizeof(LPVOID)); } \
  110. BOOL Append(_IntKeyType_ nKey, _IntKeyType_ nData) { return CList2::Append((UINT_PTR) nKey, (LPVOID) nData); } \
  111. BOOL Prepend(_IntKeyType_ nKey, _IntKeyType_ nData) { return CList2::Prepend((UINT_PTR) nKey, (LPVOID) nData); } \
  112. _IntKeyType_ Remove(_IntKeyType_ nKey) { return (_IntKeyType_) (UINT_PTR) CList2::Remove((UINT_PTR) nKey); } \
  113. _IntKeyType_ Find(_IntKeyType_ nKey) { return (_IntKeyType_) (UINT_PTR) CList2::Find((UINT_PTR) nKey); } \
  114. _IntKeyType_ Get(void) { return (_IntKeyType_) (UINT_PTR) CList::Get(); } \
  115. _IntKeyType_ Get(_IntKeyType_ *pnKey) { UINT_PTR n; _IntKeyType_ p = (_IntKeyType_) (UINT_PTR) CList2::Get(&n); *pnKey = (_IntKeyType_) n; return p; } \
  116. _IntKeyType_ PeekHead(void) { return (_IntKeyType_) (UINT_PTR) CList::PeekHead(); } \
  117. _IntKeyType_ PeekHead(_IntKeyType_ *pnKey) { UINT_PTR n; _IntKeyType_ p = (_IntKeyType_) (UINT_PTR) CList2::PeekHead(&n); *pnKey = (_IntKeyType_) n; return p; } \
  118. _IntKeyType_ Iterate(void) { return (_IntKeyType_) (UINT_PTR) CList::Iterate(); } \
  119. _IntKeyType_ Iterate(_IntKeyType_ *pnKey) { UINT_PTR n; _IntKeyType_ p = (_IntKeyType_) (UINT_PTR) CList2::Iterate(&n); *pnKey = (_IntKeyType_) n; return p; }
  120. #define DEFINE_CLIST2___(_NewClass_,_ShortKeyType_) \
  121. DEFINE_CLIST2__(_NewClass_,_ShortKeyType_)
  122. class CQueue : public CList
  123. {
  124. public:
  125. CQueue(ULONG cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList(cMaxItems, 1, TRUE) { };
  126. CQueue(CQueue *pSrc) : CList((CList *) pSrc) { };
  127. };
  128. #define DEFINE_CQUEUE(_NewClass_,_PtrItemType_) \
  129. public: \
  130. _NewClass_(void) : CQueue() { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  131. _NewClass_(ULONG cMaxItems) : CQueue(cMaxItems) { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  132. _NewClass_(_NewClass_ *pSrc) : CQueue((CQueue *) pSrc) { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  133. _NewClass_(_NewClass_ &Src) : CQueue((CQueue *) &Src) { C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  134. BOOL Append(_PtrItemType_ pData) { return CList::Append((LPVOID) pData); } \
  135. BOOL Prepend(_PtrItemType_ pData) { return CList::Prepend((LPVOID) pData); } \
  136. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  137. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  138. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  139. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  140. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); }
  141. #define DEFINE_CQUEUE_(_NewClass_,_IntItemType_) \
  142. public: \
  143. _NewClass_(void) : CQueue() { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  144. _NewClass_(ULONG cMaxItems) : CQueue(cMaxItems) { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  145. _NewClass_(_NewClass_ *pSrc) : CQueue((CQueue *) pSrc) { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  146. _NewClass_(_NewClass_ &Src) : CQueue((CQueue *) &Src) { C_ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  147. BOOL Append(_IntItemType_ nData) { return CList::Append((LPVOID) nData); } \
  148. BOOL Prepend(_IntItemType_ nData) { return CList::Prepend((LPVOID) nData); } \
  149. BOOL Remove(_IntItemType_ nData) { return CList::Remove((LPVOID) nData); } \
  150. BOOL Find(_IntItemType_ nData) { return CList::Find((LPVOID) nData); } \
  151. _IntItemType_ Get(void) { return (_IntItemType_) (UINT_PTR) CList::Get(); } \
  152. _IntItemType_ PeekHead(void) { return (_IntItemType_) (UINT_PTR) CList::PeekHead(); } \
  153. _IntItemType_ Iterate(void) { return (_IntItemType_) (UINT_PTR) CList::Iterate(); }
  154. class CQueue2 : public CList2
  155. {
  156. public:
  157. CQueue2(ULONG cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList2(cMaxItems, TRUE) { };
  158. CQueue2(CQueue2 *pSrc) : CList2((CList2 *) pSrc) { };
  159. };
  160. #define DEFINE_CQUEUE2(_NewClass_,_PtrItemType_,_IntKeyType_) \
  161. public: \
  162. _NewClass_(void) : CQueue2() { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  163. _NewClass_(ULONG cMaxItems) : CQueue2(cMaxItems) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  164. _NewClass_(_NewClass_ *pSrc) : CQueue2((CQueue2 *) pSrc) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  165. _NewClass_(_NewClass_ &Src) : CQueue2((CQueue2 *) &Src) { C_ASSERT(sizeof(_IntKeyType_) <= sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  166. BOOL Append(_IntKeyType_ nKey, _PtrItemType_ pData) { return CList2::Append((UINT_PTR) nKey, (LPVOID) pData); } \
  167. BOOL Prepend(_IntKeyType_ nKey, _PtrItemType_ pData) { return CList2::Prepend((UINT_PTR) nKey, (LPVOID) pData); } \
  168. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  169. _PtrItemType_ Remove(_IntKeyType_ nKey) { return (_PtrItemType_) (UINT_PTR) CList2::Remove((UINT_PTR) nKey); } \
  170. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  171. _PtrItemType_ Find(_IntKeyType_ nKey) { return (_PtrItemType_) (UINT_PTR) CList2::Find((UINT_PTR) nKey); } \
  172. _PtrItemType_ Get(void) { return (_PtrItemType_) (UINT_PTR) CList::Get(); } \
  173. _PtrItemType_ Get(_IntKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) (UINT_PTR) CList2::Get(&n); *pnKey = (_IntKeyType_) n; return p; } \
  174. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) (UINT_PTR) CList::PeekHead(); } \
  175. _PtrItemType_ PeekHead(_IntKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) (UINT_PTR) CList2::PeekHead(&n); *pnKey = (_IntKeyType_) n; return p; } \
  176. _PtrItemType_ Iterate(void) { return (_PtrItemType_) (UINT_PTR) CList::Iterate(); } \
  177. _PtrItemType_ Iterate(_IntKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) (UINT_PTR) CList2::Iterate(&n); *pnKey = (_IntKeyType_) n; return p; }
  178. #define DEFINE_CQUEUE2_(_NewClass_,_PtrItemType_,_ShortKeyType_) \
  179. DEFINE_CQUEUE2(_NewClass_,_PtrItemType_,_ShortKeyType_)
  180. // both key and item are of the same type
  181. #define DEFINE_CQUEUE2__(_NewClass_,_IntKeyType_) \
  182. public: \
  183. _NewClass_(void) : CQueue2() { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  184. _NewClass_(ULONG cMaxItems) : CQueue2(cMaxItems) { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  185. _NewClass_(_NewClass_ *pSrc) : CQueue2((CQueue2 *) pSrc) { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  186. _NewClass_(_NewClass_ &Src) : CQueue2((CQueue2 *) &Src) { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT_PTR)); C_ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  187. BOOL Append(_IntKeyType_ nKey, _IntKeyType_ nData) { return CList2::Append((UINT_PTR) nKey, (LPVOID) nData); } \
  188. BOOL Prepend(_IntKeyType_ nKey, _IntKeyType_ nData) { return CList2::Prepend((UINT_PTR) nKey, (LPVOID) nData); } \
  189. _IntKeyType_ Remove(_IntKeyType_ nKey) { return (_IntKeyType_) CList2::Remove((UINT_PTR) nKey); } \
  190. _IntKeyType_ Find(_IntKeyType_ nKey) { return (_IntKeyType_) CList2::Find((UINT_PTR) nKey); } \
  191. _IntKeyType_ Get(void) { return (_IntKeyType_) CList::Get(); } \
  192. _IntKeyType_ Get(_IntKeyType_ *pnKey) { return (_IntKeyType_) CList2::Get((UINT_PTR *) pnKey); } \
  193. _IntKeyType_ PeekHead(void) { return (_IntKeyType_) CList::PeekHead(); } \
  194. _IntKeyType_ PeekHead(_IntKeyType_ *pnKey) { return (_IntKeyType_) CList2::PeekHead((UINT_PTR *) pnKey); } \
  195. _IntKeyType_ Iterate(void) { return (_IntKeyType_) CList::Iterate(); } \
  196. _IntKeyType_ Iterate(_IntKeyType_ *pnKey) { return (_IntKeyType_) CList2::Iterate((UINT_PTR *) pnKey); }
  197. #define HASHED_LIST_DEFAULT_BUCKETS 16
  198. #ifdef ENABLE_HASHED_LIST2
  199. class CHashedList2
  200. {
  201. public:
  202. CHashedList2(ULONG cBuckets = HASHED_LIST_DEFAULT_BUCKETS, ULONG cInitItemsPerBucket = CLIST_DEFAULT_MAX_ITEMS);
  203. CHashedList2(CHashedList2 *pSrc);
  204. ~CHashedList2(void);
  205. BOOL Insert(UINT nKey, LPVOID pData);
  206. LPVOID Remove(UINT nKey);
  207. LPVOID Find(UINT nKey);
  208. LPVOID Get(void);
  209. LPVOID Get(UINT *pnKey);
  210. LPVOID Iterate(UINT *pnKey);
  211. LPVOID Iterate(void) { UINT n; return Iterate(&n); }
  212. void Reset(void);
  213. void Clear(void);
  214. ULONG GetCount(void) { return m_cEntries; };
  215. BOOL IsEmpty(void) { return (m_cEntries == 0); };
  216. private:
  217. ULONG GetHashValue(UINT nKey);
  218. ULONG m_cBuckets;
  219. ULONG m_cInitItemsPerBucket;
  220. CList2 **m_aBuckets;
  221. ULONG m_cEntries;
  222. ULONG m_nCurrBucket;
  223. };
  224. #else // ! ENABLE_HASHED_LIST2
  225. class CHashedList2 : public CList2
  226. {
  227. public:
  228. CHashedList2(ULONG cBuckets = HASHED_LIST_DEFAULT_BUCKETS, ULONG cInitItemsPerBucket = CLIST_DEFAULT_MAX_ITEMS)
  229. : CList2(cInitItemsPerBucket) { }
  230. CHashedList2(CHashedList2 *pSrc) : CList2((CList2 *) pSrc) { }
  231. BOOL Insert(UINT_PTR nKey, LPVOID pData) { return CList2::Append(nKey, pData); }
  232. LPVOID Get(void) { return CList::Get(); }
  233. LPVOID Get(UINT_PTR *pnKey) { return CList2::Get(pnKey); }
  234. LPVOID Iterate(void) { return CList::Iterate(); }
  235. LPVOID Iterate(UINT_PTR *pnKey) { return CList2::Iterate(pnKey); }
  236. };
  237. #endif // ENABLE_HASHED_LIST2
  238. #define DEFINE_HLIST2(_NewClass_,_PtrItemType_,_IntKeyType_) \
  239. public: \
  240. _NewClass_(ULONG cBuckets = HASHED_LIST_DEFAULT_BUCKETS, ULONG cInitItemsPerBucket = CLIST_DEFAULT_MAX_ITEMS) \
  241. : CHashedList2(cBuckets, cInitItemsPerBucket) { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  242. _NewClass_(_NewClass_ *pSrc) : CHashedList2((CHashedList2 *) pSrc) { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  243. _NewClass_(_NewClass_ &Src) : CHashedList2((CHashedList2 *) &Src) { C_ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  244. BOOL Insert(_IntKeyType_ nKey, _PtrItemType_ pData) { return CHashedList2::Insert((UINT) nKey, (LPVOID) pData); } \
  245. _PtrItemType_ Remove(_IntKeyType_ nKey) { return (_PtrItemType_) CHashedList2::Remove((UINT) nKey); } \
  246. _PtrItemType_ Find(_IntKeyType_ nKey) { return (_PtrItemType_) CHashedList2::Find((UINT) nKey); } \
  247. _PtrItemType_ Get(_IntKeyType_ *pnKey) { return (_PtrItemType_) CHashedList2::Get((UINT *) pnKey); } \
  248. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CHashedList2::Iterate(); } \
  249. _PtrItemType_ Iterate(_IntKeyType_ *pnKey) { return (_PtrItemType_) CHashedList2::Iterate((UINT *) pnKey); }
  250. #define DEFINE_HLIST2_(_NewClass_,_PtrItemType_,_ShortKeyType_) \
  251. public: \
  252. _NewClass_(ULONG cBuckets = HASHED_LIST_DEFAULT_BUCKETS, ULONG cInitItemsPerBucket = CLIST_DEFAULT_MAX_ITEMS) \
  253. : CHashedList2(cBuckets, cInitItemsPerBucket) { C_ASSERT(sizeof(_ShortKeyType_) < sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  254. _NewClass_(_NewClass_ *pSrc) : CHashedList2((CHashedList2 *) pSrc) { C_ASSERT(sizeof(_ShortKeyType_) < sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  255. _NewClass_(_NewClass_ &Src) : CHashedList2((CHashedList2 *) &Src) { C_ASSERT(sizeof(_ShortKeyType_) < sizeof(UINT_PTR)); C_ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  256. BOOL Insert(_ShortKeyType_ nKey, _PtrItemType_ pData) { return CHashedList2::Insert((UINT_PTR) nKey, (LPVOID) pData); } \
  257. _PtrItemType_ Remove(_ShortKeyType_ nKey) { return (_PtrItemType_) CHashedList2::Remove((UINT_PTR) nKey); } \
  258. _PtrItemType_ Find(_ShortKeyType_ nKey) { return (_PtrItemType_) CHashedList2::Find((UINT_PTR) nKey); } \
  259. _PtrItemType_ Get(_ShortKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) CHashedList2::Get(&n); *pnKey = (_ShortKeyType_) n; return p; } \
  260. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CHashedList2::Iterate(); } \
  261. _PtrItemType_ Iterate(_ShortKeyType_ *pnKey) { UINT_PTR n; _PtrItemType_ p = (_PtrItemType_) CHashedList2::Iterate(&n); *pnKey = (_ShortKeyType_) n; return p; }
  262. typedef LPVOID BOOL_PTR;
  263. #define TRUE_PTR ((LPVOID) (UINT_PTR) 1)
  264. #define FALSE_PTR ((LPVOID) (UINT_PTR) -1)
  265. #define LPVOID_NULL ((LPVOID) (UINT_PTR) -1)
  266. #endif // _CONTAINED_LIST_H_
  267.