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.

231 lines
7.3 KiB

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