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.

164 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: mfccllct.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __MFCCLLCT_H
  11. #define __MFCCLLCT_H
  12. namespace MMC // Temporary for the MFC->ATL conversion
  13. {
  14. class CPtrList
  15. {
  16. protected:
  17. struct CNode
  18. {
  19. CNode* pNext;
  20. CNode* pPrev;
  21. void* data;
  22. };
  23. public:
  24. // Construction
  25. CPtrList(int nBlockSize = 10);
  26. // Attributes (head and tail)
  27. // count of elements
  28. int GetCount() const;
  29. BOOL IsEmpty() const;
  30. // peek at head or tail
  31. void*& GetHead();
  32. void* GetHead() const;
  33. void*& GetTail();
  34. void* GetTail() const;
  35. // Operations
  36. // get head or tail (and remove it) - don't call on empty list!
  37. void* RemoveHead();
  38. void* RemoveTail();
  39. // add before head or after tail
  40. POSITION AddHead(void* newElement);
  41. POSITION AddTail(void* newElement);
  42. // add another list of elements before head or after tail
  43. void AddHead(CPtrList* pNewList);
  44. void AddTail(CPtrList* pNewList);
  45. // remove all elements
  46. void RemoveAll();
  47. // iteration
  48. POSITION GetHeadPosition() const;
  49. POSITION GetTailPosition() const;
  50. void*& GetNext(POSITION& rPosition); // return *Position++
  51. void* GetNext(POSITION& rPosition) const; // return *Position++
  52. void*& GetPrev(POSITION& rPosition); // return *Position--
  53. void* GetPrev(POSITION& rPosition) const; // return *Position--
  54. // getting/modifying an element at a given position
  55. void*& GetAt(POSITION position);
  56. void* GetAt(POSITION position) const;
  57. void SetAt(POSITION pos, void* newElement);
  58. void RemoveAt(POSITION position);
  59. // inserting before or after a given position
  60. POSITION InsertBefore(POSITION position, void* newElement);
  61. POSITION InsertAfter(POSITION position, void* newElement);
  62. // helper functions (note: O(n) speed)
  63. POSITION Find(void* searchValue, POSITION startAfter = NULL) const;
  64. // defaults to starting at the HEAD
  65. // return NULL if not found
  66. POSITION FindIndex(int nIndex) const;
  67. // get the 'nIndex'th element (may return NULL)
  68. // Implementation
  69. protected:
  70. CNode* m_pNodeHead;
  71. CNode* m_pNodeTail;
  72. int m_nCount;
  73. CNode* m_pNodeFree;
  74. struct CPlex* m_pBlocks;
  75. int m_nBlockSize;
  76. CNode* NewNode(CNode*, CNode*);
  77. void FreeNode(CNode*);
  78. public:
  79. ~CPtrList();
  80. #ifdef _DBG
  81. void AssertValid() const;
  82. #endif
  83. // local typedefs for class templates
  84. typedef void* BASE_TYPE;
  85. typedef void* BASE_ARG_TYPE;
  86. };
  87. inline int CPtrList::GetCount() const
  88. { return m_nCount; }
  89. inline BOOL CPtrList::IsEmpty() const
  90. { return m_nCount == 0; }
  91. inline void*& CPtrList::GetHead()
  92. { ASSERT(m_pNodeHead != NULL);
  93. return m_pNodeHead->data; }
  94. inline void* CPtrList::GetHead() const
  95. { ASSERT(m_pNodeHead != NULL);
  96. return m_pNodeHead->data; }
  97. inline void*& CPtrList::GetTail()
  98. { ASSERT(m_pNodeTail != NULL);
  99. return m_pNodeTail->data; }
  100. inline void* CPtrList::GetTail() const
  101. { ASSERT(m_pNodeTail != NULL);
  102. return m_pNodeTail->data; }
  103. inline POSITION CPtrList::GetHeadPosition() const
  104. { return (POSITION) m_pNodeHead; }
  105. inline POSITION CPtrList::GetTailPosition() const
  106. { return (POSITION) m_pNodeTail; }
  107. inline void*& CPtrList::GetNext(POSITION& rPosition) // return *Position++
  108. { CNode* pNode = (CNode*) rPosition;
  109. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  110. rPosition = (POSITION) pNode->pNext;
  111. return pNode->data; }
  112. inline void* CPtrList::GetNext(POSITION& rPosition) const // return *Position++
  113. { CNode* pNode = (CNode*) rPosition;
  114. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  115. rPosition = (POSITION) pNode->pNext;
  116. return pNode->data; }
  117. inline void*& CPtrList::GetPrev(POSITION& rPosition) // return *Position--
  118. { CNode* pNode = (CNode*) rPosition;
  119. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  120. rPosition = (POSITION) pNode->pPrev;
  121. return pNode->data; }
  122. inline void* CPtrList::GetPrev(POSITION& rPosition) const // return *Position--
  123. { CNode* pNode = (CNode*) rPosition;
  124. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  125. rPosition = (POSITION) pNode->pPrev;
  126. return pNode->data; }
  127. inline void*& CPtrList::GetAt(POSITION position)
  128. { CNode* pNode = (CNode*) position;
  129. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  130. return pNode->data; }
  131. inline void* CPtrList::GetAt(POSITION position) const
  132. { CNode* pNode = (CNode*) position;
  133. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  134. return pNode->data; }
  135. inline void CPtrList::SetAt(POSITION pos, void* newElement)
  136. { CNode* pNode = (CNode*) pos;
  137. ASSERT(_IsValidAddress(pNode, sizeof(CNode)));
  138. pNode->data = newElement; }
  139. } // MMC namespace
  140. #endif // __MFCCLLCT_H