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.

117 lines
4.6 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: DynamicArray.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // This file contains related classes to manage dynamic arrays. The array is
  7. // grown as required but never shrunk. The base class handles struct arrays.
  8. // Subclasses handle special cases of these arrays (such as pointer or
  9. // CCountedObject arrays).
  10. //
  11. // History: 1999-11-16 vtan created
  12. // 2000-02-01 vtan moved from Neptune to Whistler
  13. // --------------------------------------------------------------------------
  14. #ifndef _DynamicArray_
  15. #define _DynamicArray_
  16. #include "CountedObject.h"
  17. // --------------------------------------------------------------------------
  18. // CDynamicArrayCallback
  19. //
  20. // Purpose: Abstract class definition providing a callback mechanism for
  21. // iterating the dynamic array.
  22. //
  23. // History: 1999-11-16 vtan created
  24. // 2000-02-01 vtan moved from Neptune to Whistler
  25. // --------------------------------------------------------------------------
  26. class CDynamicArrayCallback
  27. {
  28. public:
  29. virtual NTSTATUS Callback (const void *pvData, int iElementIndex) = 0;
  30. };
  31. // --------------------------------------------------------------------------
  32. // CDynamicArray
  33. //
  34. // Purpose: Base class that handles dynamic struct arrays. Allocates
  35. // memory for the array in 16 block chunks. The memory usage of
  36. // the array is never reduced.
  37. //
  38. // History: 1999-11-16 vtan created
  39. // 2000-02-01 vtan moved from Neptune to Whistler
  40. // --------------------------------------------------------------------------
  41. class CDynamicArray
  42. {
  43. private:
  44. CDynamicArray (void);
  45. public:
  46. CDynamicArray (int iElementSize);
  47. virtual ~CDynamicArray (void);
  48. virtual NTSTATUS Add (const void *pvData);
  49. virtual NTSTATUS Remove (int iElementIndex);
  50. int GetCount (void) const;
  51. NTSTATUS Get (void *pvData, int iElementIndex);
  52. NTSTATUS Set (const void* pvData, int iElementIndex);
  53. NTSTATUS Iterate (CDynamicArrayCallback *pDynamicArrayCallback);
  54. protected:
  55. int _iElementSize,
  56. _iArraySize,
  57. _iArrayAllocatedSize;
  58. void* _pvArray;
  59. };
  60. // --------------------------------------------------------------------------
  61. // CDynamicPointerArray
  62. //
  63. // Purpose: Class that subclasses CDynamicArray to implement dynamic
  64. // pointer arrays. Removing elements automatically frees the
  65. // memory block used (assuming it was allocated with LocalAlloc).
  66. //
  67. // History: 1999-11-16 vtan created
  68. // 2000-02-01 vtan moved from Neptune to Whistler
  69. // --------------------------------------------------------------------------
  70. class CDynamicPointerArray : public CDynamicArray
  71. {
  72. public:
  73. CDynamicPointerArray (void);
  74. virtual ~CDynamicPointerArray (void);
  75. virtual NTSTATUS Add (const void *pvData);
  76. virtual NTSTATUS Remove (int iElementIndex);
  77. void* Get (int iElementIndex);
  78. };
  79. // --------------------------------------------------------------------------
  80. // CDynamicCountedObjectArray
  81. //
  82. // Purpose: Class that subclasses CDynamicArray to implement dynamic
  83. // CCountedObject arrays. Removing elements automatically
  84. // releases the reference held on the dynamic object.
  85. //
  86. // History: 1999-11-16 vtan created
  87. // 2000-02-01 vtan moved from Neptune to Whistler
  88. // --------------------------------------------------------------------------
  89. class CDynamicCountedObjectArray : public CDynamicArray
  90. {
  91. public:
  92. CDynamicCountedObjectArray (void);
  93. virtual ~CDynamicCountedObjectArray (void);
  94. NTSTATUS Add (CCountedObject *pData);
  95. virtual NTSTATUS Remove (int iElementIndex);
  96. CCountedObject* Get (int iElementIndex);
  97. };
  98. #endif /* _DynamicArray_ */