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.

105 lines
3.3 KiB

  1. //***************************************************************************
  2. //
  3. // (c) 1998-1999 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. // 8-Jun-98 bobw cleaned up for use with WBEMPERF provider
  13. //
  14. //***************************************************************************
  15. #ifndef _FLEXARRY_H_
  16. #define _FLEXARRY_H_
  17. #ifdef __cplusplus
  18. //***************************************************************************
  19. //
  20. // class CFlexArray
  21. //
  22. // This class is a generic pointer array.
  23. //
  24. //***************************************************************************
  25. class CFlexArray
  26. {
  27. private:
  28. int m_nSize; // apparent size
  29. int m_nExtent; // de facto size
  30. int m_nGrowBy;
  31. HANDLE m_hHeap; // heap to hold array
  32. void** m_pArray;
  33. public:
  34. enum { no_error, failed, out_of_memory, array_full, range_error };
  35. // Constructs a flex array at an initial size and
  36. // specifies the initial size and growth-size chunk.
  37. // =================================================
  38. CFlexArray(
  39. IN int nInitialSize = 32,
  40. IN int nGrowBy = 32
  41. );
  42. ~CFlexArray();
  43. CFlexArray(CFlexArray &);
  44. CFlexArray& operator=(CFlexArray &);
  45. // Gets an element at a particular location.
  46. // =========================================
  47. void * GetAt(int nIndex) const { return m_pArray[nIndex]; }
  48. // Returns a ptr in the array; allows use on left-hand side of assignment.
  49. // =======================================================================
  50. void * operator[](int nIndex) const { return m_pArray[nIndex]; }
  51. void *& operator[](int nIndex) { return m_pArray[nIndex]; }
  52. // Sets the element at the requested location.
  53. // ===========================================
  54. void SetAt(int nIndex, void *p) { m_pArray[nIndex] = p; }
  55. // Removes an element.
  56. // ====================
  57. int RemoveAt(int nIndex);
  58. // Inserts an element.
  59. // ===================
  60. int InsertAt(int nIndex, void *);
  61. // Removes all zero entries (null ptrs) and shrinks the array size.
  62. // ================================================================
  63. void Compress();
  64. // Adds a new element to the end of the array.
  65. // ===========================================
  66. int Add(void *pSrc) { return InsertAt(m_nSize, pSrc); }
  67. // Gets the apparent size of the array (number of used elements)
  68. // =============================================================
  69. int Size() const { return m_nSize; }
  70. // Removes all entries and reduces array size to zero. The elements
  71. // are simply removed; not deallocated (this class doesn't know what
  72. // they are).
  73. // =================================================================
  74. void Empty();
  75. // Gets a pointer to the internal array.
  76. // =====================================
  77. void** GetArrayPtr() { return m_pArray; }
  78. // Gets a pointer to the internal array and Resets the contents to none
  79. // ====================================================================
  80. void** UnbindPtr();
  81. // For debugging.
  82. // ==============
  83. void DebugDump();
  84. };
  85. #endif // __cplusplus
  86. #endif // not defined