Source code of Windows XP (NT5)
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.

187 lines
3.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1999
  3. Module Name:
  4. buffers
  5. Abstract:
  6. This header file provides dynamic buffer and string classes for general use.
  7. Author:
  8. Doug Barlow (dbarlow) 10/5/1995
  9. Environment:
  10. Win32, C++ w/ Exception Handling
  11. Notes:
  12. --*/
  13. #ifndef _BUFFERS_H_
  14. #define _BUFFERS_H_
  15. //
  16. //==============================================================================
  17. //
  18. // CBuffer
  19. //
  20. class CBuffer
  21. {
  22. public:
  23. // Constructors & Destructor
  24. CBuffer() // Default Initializer
  25. { Initialize(); };
  26. CBuffer( // Initialize with starting length.
  27. IN DWORD cbLength)
  28. { Initialize();
  29. Presize(cbLength, FALSE); };
  30. CBuffer( // Initialize with starting data.
  31. IN const BYTE * const pbSource,
  32. IN DWORD cbLength)
  33. { Initialize();
  34. Set(pbSource, cbLength); };
  35. virtual ~CBuffer() // Tear down.
  36. { Clear(); };
  37. // Properties
  38. // Methods
  39. void
  40. Clear(void); // Free up any allocated memory.
  41. LPBYTE
  42. Reset(void); // Return to default state (don't loose memory.)
  43. LPBYTE
  44. Presize( // Make sure the buffer is big enough.
  45. IN DWORD cbLength,
  46. IN BOOL fPreserve = FALSE);
  47. LPBYTE
  48. Resize( // Make sure the buffer & length are the right size.
  49. DWORD cbLength,
  50. BOOL fPreserve = FALSE);
  51. LPBYTE
  52. Set( // Load a value.
  53. IN const BYTE * const pbSource,
  54. IN DWORD cbLength);
  55. LPBYTE
  56. Append( // Append more data to the existing data.
  57. IN const BYTE * const pbSource,
  58. IN DWORD cbLength);
  59. DWORD
  60. Length( // Return the length of the data.
  61. void) const
  62. { return m_cbDataLength; };
  63. DWORD
  64. Space( // Return the length of the buffer.
  65. void) const
  66. { return m_cbBufferLength; };
  67. LPBYTE
  68. Access( // Return the data, starting at an offset.
  69. DWORD offset = 0)
  70. const
  71. {
  72. if (m_cbBufferLength <= offset)
  73. return (LPBYTE)TEXT("\x00");
  74. else
  75. return &m_pbBuffer[offset];
  76. };
  77. int
  78. Compare(
  79. const CBuffer &bfSource)
  80. const;
  81. // Operators
  82. CBuffer &
  83. operator=(
  84. IN const CBuffer &bfSource)
  85. { Set(bfSource.m_pbBuffer, bfSource.m_cbDataLength);
  86. return *this; };
  87. CBuffer &
  88. operator+=(
  89. IN const CBuffer &bfSource)
  90. { Append(bfSource.m_pbBuffer, bfSource.m_cbDataLength);
  91. return *this; };
  92. BYTE &
  93. operator[](
  94. DWORD offset)
  95. const
  96. { return *Access(offset); };
  97. int
  98. operator==(
  99. IN const CBuffer &bfSource)
  100. const
  101. { return 0 == Compare(bfSource); };
  102. int
  103. operator!=(
  104. IN const CBuffer &bfSource)
  105. const
  106. { return 0 != Compare(bfSource); };
  107. operator LPCBYTE(void)
  108. { return (LPCBYTE)Access(); };
  109. operator LPCTSTR(void)
  110. { return (LPCTSTR)Access(); };
  111. protected:
  112. // Properties
  113. LPBYTE m_pbBuffer;
  114. DWORD m_cbDataLength;
  115. DWORD m_cbBufferLength;
  116. // Methods
  117. void
  118. Initialize(void)
  119. {
  120. m_pbBuffer = NULL;
  121. m_cbDataLength = 0;
  122. m_cbBufferLength = 0;
  123. };
  124. CBuffer( // Object assignment constructor.
  125. IN const CBuffer &bfSourceOne,
  126. IN const CBuffer &bfSourceTwo);
  127. friend
  128. CBuffer &
  129. operator+(
  130. IN const CBuffer &bfSourceOne,
  131. IN const CBuffer &bfSourceTwo);
  132. };
  133. #endif // _BUFFERS_H_