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.

169 lines
9.1 KiB

  1. /* Copyright (C) Microsoft Corporation, 1998. All rights reserved. */
  2. #ifndef _CONTAINED_LIST_H_
  3. #define _CONTAINED_LIST_H_
  4. #define CLIST_DEFAULT_MAX_ITEMS 8
  5. #define CLIST_END_OF_ARRAY_MARK ((UINT) -1)
  6. class CList
  7. {
  8. public:
  9. CList(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS);
  10. CList(CList *pSrc);
  11. CList(UINT cMaxItems, UINT cSubItems);
  12. ~CList(void);
  13. BOOL Append(LPVOID pData);
  14. BOOL Prepend(LPVOID pData);
  15. BOOL Find(LPVOID pData);
  16. BOOL Remove(LPVOID pData);
  17. LPVOID Get(void);
  18. LPVOID Iterate(void);
  19. void Reset(void) { m_nCurrOffset = CLIST_END_OF_ARRAY_MARK; };
  20. void Clear(void) { m_cEntries = 0; m_nHeadOffset = 0; m_nCurrOffset = CLIST_END_OF_ARRAY_MARK; };
  21. UINT GetCount(void) { return m_cEntries; };
  22. BOOL IsEmpty(void) { return (m_cEntries == 0); };
  23. LPVOID PeekHead(void) { return (0 != m_cEntries) ? m_aEntries[m_nHeadOffset] : NULL; }
  24. protected:
  25. void CalcKeyArray(void);
  26. protected:
  27. UINT m_cEntries;
  28. UINT m_cMaxEntries;
  29. UINT m_nHeadOffset;
  30. UINT m_nCurrOffset;
  31. UINT m_cSubItems; // 1 for CList, 2 for CList2
  32. LPVOID *m_aEntries;
  33. UINT *m_aKeys; // for CList2
  34. private:
  35. BOOL Expand(void);
  36. BOOL Init(UINT cSubItems);
  37. };
  38. #define DEFINE_CLIST(_NewClass_,_PtrItemType_) \
  39. public: \
  40. _NewClass_(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList(cMaxItems) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  41. _NewClass_(_NewClass_ *pSrc) : CList((CList *) pSrc) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  42. _NewClass_(_NewClass_ &Src) : CList((CList *) &Src) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  43. BOOL Append(_PtrItemType_ pData) { return CList::Append((LPVOID) pData); } \
  44. BOOL Prepend(_PtrItemType_ pData) { return CList::Prepend((LPVOID) pData); } \
  45. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  46. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  47. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  48. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  49. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); }
  50. #define DEFINE_CLIST_(_NewClass_,_IntItemType_) \
  51. public: \
  52. _NewClass_(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList(cMaxItems) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  53. _NewClass_(_NewClass_ *pSrc) : CList((CList *) pSrc) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  54. _NewClass_(_NewClass_ &Src) : CList((CList *) &Src) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  55. BOOL Append(_IntItemType_ nData) { return CList::Append((LPVOID) nData); } \
  56. BOOL Prepend(_IntItemType_ nData) { return CList::Prepend((LPVOID) nData); } \
  57. BOOL Remove(_IntItemType_ nData) { return CList::Remove((LPVOID) nData); } \
  58. BOOL Find(_IntItemType_ nData) { return CList::Find((LPVOID) nData); } \
  59. _IntItemType_ Get(void) { return (_IntItemType_) CList::Get(); } \
  60. _IntItemType_ PeekHead(void) { return (_IntItemType_) CList::PeekHead(); } \
  61. _IntItemType_ Iterate(void) { return (_IntItemType_) CList::Iterate(); }
  62. class CList2 : public CList
  63. {
  64. public:
  65. CList2(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList(cMaxItems, 2) { }
  66. CList2(CList2 *pSrc);
  67. BOOL Append(UINT nKey, LPVOID pData);
  68. BOOL Prepend(UINT nKey, LPVOID pData);
  69. // BOOL Remove(LPVOID pData); // inherited from CList
  70. LPVOID Remove(UINT nKey);
  71. // BOOL Find(LPVOID pData); // inherited from CList
  72. LPVOID Find(UINT nKey);
  73. // LPVOID Get(void); // inheirted from CList
  74. LPVOID Get(UINT *pnKey);
  75. // LPVOID Iterate(void); // inherited from CList
  76. LPVOID Iterate(UINT *pnKey);
  77. };
  78. #define DEFINE_CLIST2(_NewClass_,_PtrItemType_,_IntKeyType_) \
  79. public: \
  80. _NewClass_(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList2(cMaxItems) { ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  81. _NewClass_(_NewClass_ *pSrc) : CList2((CList2 *) pSrc) { ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  82. _NewClass_(_NewClass_ &Src) : CList2((CList2 *) &Src) { ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); ASSERT(sizeof(_PtrItemType_) <= sizeof(LPVOID)); } \
  83. BOOL Append(_IntKeyType_ nKey, _PtrItemType_ pData) { return CList2::Append((UINT) nKey, (LPVOID) pData); } \
  84. BOOL Prepend(_IntKeyType_ nKey, _PtrItemType_ pData) { return CList2::Prepend((UINT) nKey, (LPVOID) pData); } \
  85. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  86. _PtrItemType_ Remove(_IntKeyType_ nKey) { return (_PtrItemType_) CList2::Remove((UINT) nKey); } \
  87. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  88. _PtrItemType_ Find(_IntKeyType_ nKey) { return (_PtrItemType_) CList2::Find((UINT) nKey); } \
  89. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  90. _PtrItemType_ Get(_IntKeyType_ *pnKey) { return (_PtrItemType_) CList2::Get((UINT *) pnKey); } \
  91. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  92. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); } \
  93. _PtrItemType_ Iterate(_IntKeyType_ *pnKey) { return (_PtrItemType_) CList2::Iterate((UINT *) pnKey); }
  94. #define DEFINE_CLIST2_(_NewClass_,_PtrItemType_,_ShortKeyType_) \
  95. public: \
  96. _NewClass_(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList2(cMaxItems) { ASSERT(sizeof(_ShortKeyType_) != sizeof(UINT)); ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  97. _NewClass_(_NewClass_ *pSrc) : CList2((CList2 *) pSrc) { ASSERT(sizeof(_ShortKeyType_) != sizeof(UINT)); ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  98. _NewClass_(_NewClass_ &Src) : CList2((CList2 *) &Src) { ASSERT(sizeof(_ShortKeyType_) != sizeof(UINT)); ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  99. BOOL Append(_ShortKeyType_ nKey, _PtrItemType_ pData) { return CList2::Append((UINT) nKey, (LPVOID) pData); } \
  100. BOOL Prepend(_ShortKeyType_ nKey, _PtrItemType_ pData) { return CList2::Prepend((UINT) nKey, (LPVOID) pData); } \
  101. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  102. _PtrItemType_ Remove(_ShortKeyType_ nKey) { return (_PtrItemType_) CList2::Remove((UINT) nKey); } \
  103. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  104. _PtrItemType_ Find(_ShortKeyType_ nKey) { return (_PtrItemType_) CList2::Find((UINT) nKey); } \
  105. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  106. _PtrItemType_ Get(_ShortKeyType_ *pnKey) { UINT n; _PtrItemType_ p = (_PtrItemType_) CList2::Get(&n); *pnKey = (_ShortKeyType_) n; return p; } \
  107. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  108. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); } \
  109. _PtrItemType_ Iterate(_ShortKeyType_ *pnKey) { UINT n; _PtrItemType_ p = (_PtrItemType_) CList2::Iterate(&n); *pnKey = (_ShortKeyType_) n; return p; }
  110. // both key and item are of the same type
  111. #define DEFINE_CLIST2__(_NewClass_,_IntKeyType_) \
  112. public: \
  113. _NewClass_(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList2(cMaxItems) { ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  114. _NewClass_(_NewClass_ *pSrc) : CList2((CList2 *) pSrc) { ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  115. _NewClass_(_NewClass_ &Src) : CList2((CList2 *) &Src) { ASSERT(sizeof(_IntKeyType_) == sizeof(UINT)); ASSERT(sizeof(_IntKeyType_) == sizeof(LPVOID)); } \
  116. BOOL Append(_IntKeyType_ nKey, _IntKeyType_ nData) { return CList2::Append((UINT) nKey, (LPVOID) nData); } \
  117. BOOL Prepend(_IntKeyType_ nKey, _IntKeyType_ nData) { return CList2::Prepend((UINT) nKey, (LPVOID) nData); } \
  118. _IntKeyType_ Remove(_IntKeyType_ nKey) { return (_IntKeyType_) CList2::Remove((UINT) nKey); } \
  119. _IntKeyType_ Find(_IntKeyType_ nKey) { return (_IntKeyType_) CList2::Find((UINT) nKey); } \
  120. _IntKeyType_ Get(void) { return (_IntKeyType_) CList::Get(); } \
  121. _IntKeyType_ Get(_IntKeyType_ *pnKey) { return (_IntKeyType_) CList2::Get((UINT *) pnKey); } \
  122. _IntKeyType_ PeekHead(void) { return (_IntKeyType_) CList::PeekHead(); } \
  123. _IntKeyType_ Iterate(void) { return (_IntKeyType_) CList::Iterate(); } \
  124. _IntKeyType_ Iterate(_IntKeyType_ *pnKey) { return (_IntKeyType_) CList2::Iterate((UINT *) pnKey); }
  125. typedef LPVOID BOOL_PTR;
  126. #define TRUE_PTR ((LPVOID) (UINT) 1)
  127. #define FALSE_PTR ((LPVOID) (UINT) -1)
  128. #endif // _CONTAINED_LIST_H_