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.

82 lines
1.5 KiB

  1. #pragma once
  2. #include <ComDef.h>
  3. //---------------------------------------------------------------------------
  4. // C Array Class
  5. //
  6. // Implements a very simple heap based array. Replaces stack based arrays
  7. // in order to reduce stack space used when long string arrays are declared.
  8. //---------------------------------------------------------------------------
  9. template<class T>
  10. struct c_array
  11. {
  12. //
  13. // Constructors and Destructors
  14. //
  15. c_array(size_t s) :
  16. s(s),
  17. p(new T[s])
  18. {
  19. if (p == NULL)
  20. {
  21. _com_issue_error(E_OUTOFMEMORY);
  22. }
  23. }
  24. c_array(const c_array& a) :
  25. s(a.s),
  26. p(new T[a.s])
  27. {
  28. if (p != NULL)
  29. {
  30. memcpy(p, a.p, a.s * sizeof(T));
  31. }
  32. else
  33. {
  34. _com_issue_error(E_OUTOFMEMORY);
  35. }
  36. }
  37. ~c_array()
  38. {
  39. delete [] p;
  40. }
  41. //
  42. // Access Operators
  43. //
  44. // Note that defining array operators was creating an ambiguity for
  45. // the compiler therefore only the pointer operator is defined.
  46. //
  47. operator T*()
  48. {
  49. return p;
  50. }
  51. //T& operator[](ptrdiff_t i)
  52. //{
  53. // return p[i];
  54. //}
  55. //const T& operator[](ptrdiff_t i) const
  56. //{
  57. // return p[i];
  58. //}
  59. //
  60. // Properties
  61. //
  62. size_t size() const
  63. {
  64. return s;
  65. }
  66. T* p;
  67. size_t s;
  68. };