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.

129 lines
6.1 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(ULONG cMaxItems = CLIST_DEFAULT_MAX_ITEMS, BOOL fQueue = FALSE);
  9. CList(CList *pSrc);
  10. ~CList(void);
  11. BOOL Append(LPVOID pData);
  12. BOOL Prepend(LPVOID pData);
  13. BOOL Find(LPVOID pData);
  14. BOOL Remove(LPVOID pData);
  15. LPVOID Get(void);
  16. LPVOID Iterate(void);
  17. void Reset(void) { m_nCurrOffset = CLIST_END_OF_ARRAY_MARK; };
  18. void Clear(void) { m_cEntries = 0; m_nHeadOffset = 0; m_nCurrOffset = CLIST_END_OF_ARRAY_MARK; };
  19. UINT GetCount(void) { return m_cEntries; };
  20. BOOL IsEmpty(void) { return (m_cEntries == 0); };
  21. LPVOID PeekHead(void) { return (0 != m_cEntries) ? m_aEntries[m_nHeadOffset] : NULL; }
  22. protected:
  23. ULONG m_cEntries;
  24. ULONG m_cMaxEntries;
  25. ULONG m_nHeadOffset;
  26. ULONG m_nCurrOffset;
  27. BOOL m_fQueue; // TRUE for CQueue, FALSE for CList
  28. LPVOID *m_aEntries;
  29. private:
  30. BOOL Expand(void);
  31. BOOL Init(void);
  32. };
  33. #define DEFINE_CLIST(_NewClass_,_PtrItemType_) \
  34. public: \
  35. _NewClass_(void) : CList() { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  36. _NewClass_(ULONG cMaxItems) : CList(cMaxItems) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  37. _NewClass_(_NewClass_ *pSrc) : CList((CList *) pSrc) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  38. _NewClass_(_NewClass_ &Src) : CList((CList *) &Src) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  39. BOOL Append(_PtrItemType_ pData) { return CList::Append((LPVOID) pData); } \
  40. BOOL Prepend(_PtrItemType_ pData) { return CList::Prepend((LPVOID) pData); } \
  41. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  42. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  43. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  44. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  45. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); }
  46. #define DEFINE_CLIST_(_NewClass_,_IntItemType_) \
  47. public: \
  48. _NewClass_(void) : CList() { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  49. _NewClass_(ULONG cMaxItems) : CList(cMaxItems) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  50. _NewClass_(_NewClass_ *pSrc) : CList((CList *) pSrc) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  51. _NewClass_(_NewClass_ &Src) : CList((CList *) &Src) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  52. BOOL Append(_IntItemType_ nData) { return CList::Append((LPVOID) nData); } \
  53. BOOL Prepend(_IntItemType_ nData) { return CList::Prepend((LPVOID) nData); } \
  54. BOOL Remove(_IntItemType_ nData) { return CList::Remove((LPVOID) nData); } \
  55. BOOL Find(_IntItemType_ nData) { return CList::Find((LPVOID) nData); } \
  56. _IntItemType_ Get(void) { return (_IntItemType_) (UINT_PTR) CList::Get(); } \
  57. _IntItemType_ PeekHead(void) { return (_IntItemType_) (UINT_PTR) CList::PeekHead(); } \
  58. _IntItemType_ Iterate(void) { return (_IntItemType_) (UINT_PTR) CList::Iterate(); }
  59. class CQueue : public CList
  60. {
  61. public:
  62. CQueue(ULONG cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CList(cMaxItems, TRUE) { };
  63. CQueue(CQueue *pSrc) : CList((CList *) pSrc) { };
  64. };
  65. #define DEFINE_CQUEUE(_NewClass_,_PtrItemType_) \
  66. public: \
  67. _NewClass_(void) : CQueue() { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  68. _NewClass_(ULONG cMaxItems) : CQueue(cMaxItems) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  69. _NewClass_(_NewClass_ *pSrc) : CQueue((CQueue *) pSrc) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  70. _NewClass_(_NewClass_ &Src) : CQueue((CQueue *) &Src) { ASSERT(sizeof(_PtrItemType_) == sizeof(LPVOID)); } \
  71. BOOL Append(_PtrItemType_ pData) { return CList::Append((LPVOID) pData); } \
  72. BOOL Prepend(_PtrItemType_ pData) { return CList::Prepend((LPVOID) pData); } \
  73. BOOL Remove(_PtrItemType_ pData) { return CList::Remove((LPVOID) pData); } \
  74. BOOL Find(_PtrItemType_ pData) { return CList::Find((LPVOID) pData); } \
  75. _PtrItemType_ Get(void) { return (_PtrItemType_) CList::Get(); } \
  76. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CList::PeekHead(); } \
  77. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CList::Iterate(); }
  78. #define DEFINE_CQUEUE_(_NewClass_,_IntItemType_) \
  79. public: \
  80. _NewClass_(void) : CQueue() { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  81. _NewClass_(ULONG cMaxItems) : CQueue(cMaxItems) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  82. _NewClass_(_NewClass_ *pSrc) : CQueue((CQueue *) pSrc) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  83. _NewClass_(_NewClass_ &Src) : CQueue((CQueue *) &Src) { ASSERT(sizeof(_IntItemType_) <= sizeof(LPVOID)); } \
  84. BOOL Append(_IntItemType_ nData) { return CList::Append((LPVOID) nData); } \
  85. BOOL Prepend(_IntItemType_ nData) { return CList::Prepend((LPVOID) nData); } \
  86. BOOL Remove(_IntItemType_ nData) { return CList::Remove((LPVOID) nData); } \
  87. BOOL Find(_IntItemType_ nData) { return CList::Find((LPVOID) nData); } \
  88. _IntItemType_ Get(void) { return (_IntItemType_) (UINT_PTR) CList::Get(); } \
  89. _IntItemType_ PeekHead(void) { return (_IntItemType_) (UINT_PTR) CList::PeekHead(); } \
  90. _IntItemType_ Iterate(void) { return (_IntItemType_) (UINT_PTR) CList::Iterate(); }
  91. typedef LPVOID BOOL_PTR;
  92. #define TRUE_PTR ((LPVOID) (UINT_PTR) 1)
  93. #define FALSE_PTR ((LPVOID) (UINT_PTR) -1)
  94. #define LPVOID_NULL ((LPVOID) (UINT_PTR) -1)
  95. #endif // _CONTAINED_LIST_H_
  96.