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.

119 lines
2.7 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /* BUFFER.H -- Definition of BUFFER class.
  6. *
  7. * History:
  8. * 03/22/93 gregj Created
  9. * 03/24/93 gregj Created base class, GLOBAL_BUFFER
  10. * 10/06/93 gregj Removed LOCAL_BUFFER and GLOBAL_BUFFER because
  11. * they're incompatible with Win32.
  12. */
  13. #ifndef _INC_BUFFER
  14. #define _INC_BUFFER
  15. /*************************************************************************
  16. NAME: BUFFER_BASE
  17. SYNOPSIS: Base class for transient buffer classes
  18. INTERFACE: BUFFER_BASE()
  19. Construct with optional size of buffer to allocate.
  20. Resize()
  21. Resize buffer to specified size. Returns TRUE if
  22. successful.
  23. QuerySize()
  24. Return the current size of the buffer in bytes.
  25. QueryPtr()
  26. Return a pointer to the buffer.
  27. PARENT: None
  28. USES: None
  29. CAVEATS: This is an abstract class, which unifies the interface
  30. of BUFFER, GLOBAL_BUFFER, etc.
  31. NOTES: In standard OOP fashion, the buffer is deallocated in
  32. the destructor.
  33. HISTORY:
  34. 03/24/93 gregj Created base class
  35. **************************************************************************/
  36. class BUFFER_BASE
  37. {
  38. protected:
  39. UINT _cb;
  40. virtual BOOL Alloc( UINT cbBuffer ) = 0;
  41. virtual BOOL Realloc( UINT cbBuffer ) = 0;
  42. public:
  43. BUFFER_BASE()
  44. { _cb = 0; } // buffer not allocated yet
  45. ~BUFFER_BASE()
  46. { _cb = 0; } // buffer size no longer valid
  47. BOOL Resize( UINT cbNew );
  48. UINT QuerySize() const { return _cb; };
  49. };
  50. #define GLOBAL_BUFFER BUFFER
  51. /*************************************************************************
  52. NAME: BUFFER
  53. SYNOPSIS: Wrapper class for new and delete
  54. INTERFACE: BUFFER()
  55. Construct with optional size of buffer to allocate.
  56. Resize()
  57. Resize buffer to specified size. Only works if the
  58. buffer hasn't been allocated yet.
  59. QuerySize()
  60. Return the current size of the buffer in bytes.
  61. QueryPtr()
  62. Return a pointer to the buffer.
  63. PARENT: BUFFER_BASE
  64. CAVEATS:
  65. NOTES: In standard OOP fashion, the buffer is deallocated in
  66. the destructor.
  67. HISTORY:
  68. 03/24/93 gregj Created
  69. **************************************************************************/
  70. class BUFFER : public BUFFER_BASE
  71. {
  72. protected:
  73. CHAR *_lpBuffer;
  74. virtual BOOL Alloc( UINT cbBuffer );
  75. virtual BOOL Realloc( UINT cbBuffer );
  76. public:
  77. BUFFER( UINT cbInitial=0 );
  78. ~BUFFER();
  79. LPVOID QueryPtr() const { return (LPVOID)_lpBuffer; }
  80. operator void*() const { return (void *)_lpBuffer; }
  81. };
  82. #define LOCAL_BUFFER BUFFER
  83. #endif /* _INC_BUFFER */