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.

119 lines
3.3 KiB

  1. /***************************************************************************\
  2. *
  3. * File: Array.h
  4. *
  5. * Description:
  6. * Array.h defines a collection of different array classes, each designed
  7. * for specialized usage.
  8. *
  9. *
  10. * History:
  11. * 1/04/2000: JStall: Created
  12. *
  13. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  14. *
  15. \***************************************************************************/
  16. #if !defined(BASE__Array_h__INCLUDED)
  17. #define BASE__Array_h__INCLUDED
  18. /***************************************************************************\
  19. *
  20. * GArrayS implements an array that is optimized for minimum size. When no
  21. * items are allocated, the array is only 4 bytes. When any items are
  22. * allocated, an extra item is allocated BEFORE the memory location pointed
  23. * by m_aT where the size is stored.
  24. *
  25. * This array class is not designed for continuous size changing. Any time
  26. * an element is added or removed, the entire array size is reallocated.
  27. * This helps keep memory usage down, at the expense of runtime performance.
  28. *
  29. \***************************************************************************/
  30. template <class T, class heap = ContextHeap>
  31. class GArrayS
  32. {
  33. // Construction/destruction
  34. public:
  35. GArrayS();
  36. ~GArrayS();
  37. // Operations
  38. public:
  39. int GetSize() const;
  40. BOOL SetSize(int cItems);
  41. BOOL IsEmpty() const;
  42. int Add(const T & t);
  43. BOOL Remove(const T & t);
  44. BOOL RemoveAt(int idxItem);
  45. void RemoveAll();
  46. BOOL InsertAt(int idxItem, const T & t);
  47. int Find(const T & t) const;
  48. T & operator[] (int idxItem) const;
  49. T * GetData() const;
  50. // Implementation
  51. protected:
  52. void * GetRawData(BOOL fCheckNull) const;
  53. void SetRawSize(int cNewItems);
  54. BOOL Resize(int cItems, int cSize);
  55. void SetAtIndex(int idxItem, const T & t);
  56. // Data
  57. protected:
  58. T * m_aT;
  59. };
  60. /***************************************************************************\
  61. *
  62. * GArrayF implements an array that is optimized for more frequent add and
  63. * remove operations. This array class reallocates it size when the
  64. * used size is either larger or significantly smaller than the current size.
  65. * This implementation takes 12 bytes of storage, so it is more memory
  66. * expensive than GArrayS<T> when the array is usually empty.
  67. *
  68. \***************************************************************************/
  69. template <class T, class heap = ContextHeap>
  70. class GArrayF
  71. {
  72. // Construction/destruction
  73. public:
  74. GArrayF();
  75. ~GArrayF();
  76. // Operations
  77. public:
  78. int GetSize() const;
  79. BOOL SetSize(int cItems);
  80. BOOL IsEmpty() const;
  81. int Add(const T & t);
  82. BOOL Remove(const T & t);
  83. BOOL RemoveAt(int idxItem);
  84. void RemoveAll();
  85. BOOL InsertAt(int idxItem, const T & t);
  86. int Find(const T & t) const;
  87. T & operator[] (int idxItem) const;
  88. T * GetData() const;
  89. // Implementation
  90. protected:
  91. BOOL Resize(int cItems);
  92. void SetAtIndex(int idxItem, const T & t);
  93. // Data
  94. protected:
  95. T * m_aT;
  96. int m_nSize;
  97. int m_nAllocSize;
  98. };
  99. #include "Array.inl"
  100. #endif // BASE__Array_h__INCLUDED