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.

75 lines
1.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. aray.hxx
  5. Abstract:
  6. This header file declares Array template class.
  7. Author:
  8. JasonHa
  9. --*/
  10. #ifndef _ARRAY_HXX_
  11. #define _ARRAY_HXX_
  12. template <class T>
  13. class Array
  14. {
  15. private:
  16. void Init()
  17. {
  18. hHeap = NULL;
  19. Buffer = NULL;
  20. Size = 0;
  21. Length = 0;
  22. Dummy = (T)0;
  23. }
  24. public:
  25. Array()
  26. {
  27. Init();
  28. }
  29. Array(SIZE_T StartLength);
  30. Array(T *Data, SIZE_T Count);
  31. ~Array()
  32. {
  33. if (Buffer) HeapFree(hHeap, 0, Buffer);
  34. }
  35. SIZE_T Expand(SIZE_T NewLength);
  36. SIZE_T GetLength() const { return Length; }
  37. const T* GetBuffer() const { return Buffer; }
  38. BOOL IsEmpty() const { return Length == 0; }
  39. void Set(T *Data, SIZE_T Count, SIZE_T Start = 0);
  40. T& operator[](SIZE_T Index) {
  41. return (Index < Length) ? Buffer[Index] : Dummy;
  42. }
  43. private:
  44. HANDLE hHeap;
  45. T *Buffer;
  46. SIZE_T Size;
  47. SIZE_T Length;
  48. T Dummy;
  49. };
  50. #endif _ARRAY_HXX_