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.

98 lines
3.2 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  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. int Remove( void* p );
  59. // Inserts an element.
  60. // ===================
  61. int InsertAt(int nIndex, void *);
  62. // Removes all zero entries (null ptrs) and shrinks the array size.
  63. // ================================================================
  64. void Compress();
  65. // Adds a new element to the end of the array.
  66. // ===========================================
  67. int Add(void *pSrc) { return InsertAt(m_nSize, pSrc); }
  68. // Gets the apparent size of the array (number of used elements)
  69. // =============================================================
  70. int Size() const { return m_nSize; }
  71. // Removes all entries and reduces array size to zero. The elements
  72. // are simply removed; not deallocated (this class doesn't know what
  73. // they are).
  74. // =================================================================
  75. void Empty();
  76. // Gets a pointer to the internal array.
  77. // =====================================
  78. void** GetArrayPtr() { return m_pArray; }
  79. };
  80. #endif // __cplusplus
  81. #endif // not defined