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.

210 lines
6.5 KiB

  1. //***************************************************************************
  2. //
  3. // (c) 1996-2001 by Microsoft Corp.
  4. //
  5. // FLEXARRY.H
  6. //
  7. // CFlexArray and CWStringArray implementation.
  8. //
  9. // This
  10. //
  11. // 15-Jul-97 raymcc This implementation is not based on arenas.
  12. //
  13. //***************************************************************************
  14. #ifndef _FLEXARRY_H_
  15. #define _FLEXARRY_H_
  16. //***************************************************************************
  17. //
  18. // class CFlexArray
  19. //
  20. // This class is a generic pointer array.
  21. //
  22. //***************************************************************************
  23. class CFlexArray
  24. {
  25. int m_nSize; // apparent size
  26. int m_nExtent; // de facto size
  27. int m_nGrowBy;
  28. void** m_pArray;
  29. public:
  30. enum { no_error, failed, out_of_memory, array_full, range_error };
  31. // Constructs a flex array at an initial size and
  32. // specifies the initial size and growth-size chunk.
  33. // =================================================
  34. CFlexArray(
  35. IN int nInitialSize = 32,
  36. IN int nGrowBy = 32
  37. );
  38. ~CFlexArray();
  39. CFlexArray(CFlexArray &);
  40. CFlexArray& operator=(CFlexArray &);
  41. // Gets an element at a particular location.
  42. // =========================================
  43. void * GetAt(int nIndex) const { return m_pArray[nIndex]; }
  44. // Returns a ptr in the array; allows use on left-hand side of assignment.
  45. // =======================================================================
  46. void * operator[](int nIndex) const { return m_pArray[nIndex]; }
  47. void *& operator[](int nIndex) { return m_pArray[nIndex]; }
  48. // Sets the element at the requested location.
  49. // ===========================================
  50. void SetAt(int nIndex, void *p) { m_pArray[nIndex] = p; }
  51. // Removes an element.
  52. // ====================
  53. int RemoveAt(int nIndex);
  54. // Inserts an element.
  55. // ===================
  56. int InsertAt(int nIndex, void *);
  57. // Removes all zero entries (null ptrs) and shrinks the array size.
  58. // ================================================================
  59. void Compress();
  60. // Adds a new element to the end of the array.
  61. // ===========================================
  62. int Add(void *pSrc) { return InsertAt(m_nSize, pSrc); }
  63. // Gets the apparent size of the array (number of used elements)
  64. // =============================================================
  65. int Size() const { return m_nSize; }
  66. // Removes all entries and reduces array size to zero. The elements
  67. // are simply removed; not deallocated (this class doesn't know what
  68. // they are).
  69. // =================================================================
  70. void Empty();
  71. // Gets a pointer to the internal array.
  72. // =====================================
  73. void** GetArrayPtr() { return m_pArray; }
  74. // Gets a pointer to the internal array and Resets the contents to none
  75. // ====================================================================
  76. void** UnbindPtr();
  77. // For debugging.
  78. // ==============
  79. void DebugDump();
  80. };
  81. //***************************************************************************
  82. //
  83. // class CWStringArray
  84. //
  85. // This class is a generic wide-string array.
  86. //
  87. //***************************************************************************
  88. class CWStringArray
  89. {
  90. CFlexArray m_Array;
  91. public:
  92. enum { no_error, failed, out_of_memory, array_full, range_error };
  93. enum { not_found = -1, no_case, with_case };
  94. CWStringArray(
  95. int nSize = 32,
  96. int nGrowBy = 32
  97. );
  98. CWStringArray(CWStringArray &Src);
  99. ~CWStringArray();
  100. CWStringArray& operator =(CWStringArray &Src);
  101. // Gets the read-only ptr to the string at the requested index.
  102. // =============================================================
  103. wchar_t *GetAt(int nIndex) { return (wchar_t *) m_Array[nIndex]; }
  104. // Same as GetAt().
  105. // ================
  106. wchar_t *operator[](int nIndex) { return (wchar_t *) m_Array[nIndex]; }
  107. // Appends a new element to the end of the array. Copies the param.
  108. // ================================================================
  109. int Add(wchar_t *pStr);
  110. // Inserts a new element within the array.
  111. // =======================================
  112. int InsertAt(int nIndex, wchar_t *pStr);
  113. // Removes an element at the specified index. Takes care of
  114. // cleanup.
  115. // =========================================================
  116. int RemoveAt(int nIndex);
  117. // Inserts a copy of <pStr> at that location after removing
  118. // the prior string and deallocating it.
  119. // ========================================================
  120. int SetAt(int nIndex, wchar_t *pStr);
  121. // Directly replaces the pointer at the specified location
  122. // with the ptr value in <pStr>. No allocs or deallocs are done.
  123. // =============================================================
  124. int ReplaceAt(int nIndex, wchar_t *pStr);
  125. // Unchecked replacement
  126. // Deletes the string at the location and sets the entry to zero
  127. // without compressing the array.
  128. // =============================================================
  129. int DeleteStr(int nIndex);
  130. // Returns the 'apparent' size of the array.
  131. // =========================================
  132. int Size() { return m_Array.Size(); }
  133. // Empties the array by cleaning up after all strings and
  134. // setting the size to zero.
  135. // ======================================================
  136. void Empty();
  137. // Locates a string or returns -1 if not found.
  138. // ============================================
  139. int FindStr(wchar_t *pTarget, int nFlags);
  140. // Compresses the array by removing all zero elements.
  141. // ===================================================
  142. void Compress() { m_Array.Compress(); }
  143. // Sorts the array according to UNICODE order.
  144. // ===========================================
  145. void Sort();
  146. // Standard set-theoretic operations.
  147. // ==================================
  148. static void Difference(
  149. CWStringArray &Src1,
  150. CWStringArray &Src2,
  151. CWStringArray &Diff
  152. );
  153. static void Intersection(
  154. CWStringArray &Src1,
  155. CWStringArray &Src2,
  156. CWStringArray &Output
  157. );
  158. static void Union(
  159. CWStringArray &Src1,
  160. CWStringArray &Src2,
  161. CWStringArray &Output
  162. );
  163. };
  164. #endif