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.

164 lines
4.3 KiB

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (c) 1992-2001 Microsoft Corporation, All Rights Reserved
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #ifndef __PROVCOLL_H__
  11. #define __PROVCOLL_H__
  12. #include "provstd.h"
  13. class CObArray : public CObject
  14. {
  15. public:
  16. // Construction
  17. CObArray();
  18. // Attributes
  19. int GetSize() const;
  20. int GetUpperBound() const;
  21. void SetSize(int nNewSize, int nGrowBy = -1);
  22. // Operations
  23. // Clean up
  24. void FreeExtra();
  25. void RemoveAll();
  26. // Accessing elements
  27. CObject* GetAt(int nIndex) const;
  28. void SetAt(int nIndex, CObject* newElement);
  29. CObject*& ElementAt(int nIndex);
  30. // Direct Access to the element data (may return NULL)
  31. const CObject** GetData() const;
  32. CObject** GetData();
  33. // Potentially growing the array
  34. void SetAtGrow(int nIndex, CObject* newElement);
  35. int Add(CObject* newElement);
  36. int Append(const CObArray& src);
  37. void Copy(const CObArray& src);
  38. // overloaded operator helpers
  39. CObject* operator[](int nIndex) const;
  40. CObject*& operator[](int nIndex);
  41. // Operations that move elements around
  42. void InsertAt(int nIndex, CObject* newElement, int nCount = 1);
  43. void RemoveAt(int nIndex, int nCount = 1);
  44. void InsertAt(int nStartIndex, CObArray* pNewArray);
  45. // Implementation
  46. protected:
  47. CObject** m_pData; // the actual array of data
  48. int m_nSize; // # of elements (upperBound - 1)
  49. int m_nMaxSize; // max allocated
  50. int m_nGrowBy; // grow amount
  51. public:
  52. ~CObArray();
  53. protected:
  54. // local typedefs for class templates
  55. typedef CObject* BASE_TYPE;
  56. typedef CObject* BASE_ARG_TYPE;
  57. };
  58. /////////////////////////////////////////////////////////////////////////////
  59. class CObList : public CObject
  60. {
  61. protected:
  62. struct CNode
  63. {
  64. CNode* pNext;
  65. CNode* pPrev;
  66. CObject* data;
  67. };
  68. public:
  69. // Construction
  70. CObList(int nBlockSize = 10);
  71. // Attributes (head and tail)
  72. // count of elements
  73. int GetCount() const;
  74. BOOL IsEmpty() const;
  75. // peek at head or tail
  76. CObject*& GetHead();
  77. CObject* GetHead() const;
  78. CObject*& GetTail();
  79. CObject* GetTail() const;
  80. // Operations
  81. // get head or tail (and remove it) - don't call on empty list!
  82. CObject* RemoveHead();
  83. CObject* RemoveTail();
  84. // add before head or after tail
  85. POSITION AddHead(CObject* newElement);
  86. POSITION AddTail(CObject* newElement);
  87. // add another list of elements before head or after tail
  88. void AddHead(CObList* pNewList);
  89. void AddTail(CObList* pNewList);
  90. // remove all elements
  91. void RemoveAll();
  92. // iteration
  93. POSITION GetHeadPosition() const;
  94. POSITION GetTailPosition() const;
  95. CObject*& GetNext(POSITION& rPosition); // return *Position++
  96. CObject* GetNext(POSITION& rPosition) const; // return *Position++
  97. CObject*& GetPrev(POSITION& rPosition); // return *Position--
  98. CObject* GetPrev(POSITION& rPosition) const; // return *Position--
  99. // getting/modifying an element at a given position
  100. CObject*& GetAt(POSITION position);
  101. CObject* GetAt(POSITION position) const;
  102. void SetAt(POSITION pos, CObject* newElement);
  103. void RemoveAt(POSITION position);
  104. // inserting before or after a given position
  105. POSITION InsertBefore(POSITION position, CObject* newElement);
  106. POSITION InsertAfter(POSITION position, CObject* newElement);
  107. // helper functions (note: O(n) speed)
  108. POSITION Find(CObject* searchValue, POSITION startAfter = NULL) const;
  109. // defaults to starting at the HEAD
  110. // return NULL if not found
  111. POSITION FindIndex(int nIndex) const;
  112. // get the 'nIndex'th element (may return NULL)
  113. // Implementation
  114. protected:
  115. CNode* m_pNodeHead;
  116. CNode* m_pNodeTail;
  117. int m_nCount;
  118. CNode* m_pNodeFree;
  119. struct CPlex* m_pBlocks;
  120. int m_nBlockSize;
  121. CNode* NewNode(CNode*, CNode*);
  122. void FreeNode(CNode*);
  123. public:
  124. ~CObList();
  125. // local typedefs for class templates
  126. typedef CObject* BASE_TYPE;
  127. typedef CObject* BASE_ARG_TYPE;
  128. };
  129. #endif //!__PROVCOLL_H__
  130. /////////////////////////////////////////////////////////////////////////////