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.

141 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. writebuf.h
  5. Abstract:
  6. This module contains class declarations/definitions for
  7. CFlatFileWriteBuf
  8. **** Overview ****
  9. The write buffer that buffers up a batch of writes for flatfile.
  10. Using sequential scan is good for reads, but may not be sufficient
  11. for sequential writes. This buffer is only enabled when data
  12. being written to the file is not critical ( meaning losing of data
  13. is OK if the system crashes ).
  14. Author:
  15. Kangrong Yan ( KangYan ) 5-6-1999
  16. Revision History:
  17. --*/
  18. #ifndef _WRITEBUF_H_
  19. #define _WRITEBUF_H_
  20. class CFlatFile;
  21. class CFlatFileWriteBuf { //wb
  22. public:
  23. //
  24. // Constructor, destructor
  25. //
  26. CFlatFileWriteBuf( CFlatFile* pParentFile );
  27. ~CFlatFileWriteBuf();
  28. //
  29. // Write the byte range
  30. //
  31. HRESULT WriteFileBuffer(
  32. const DWORD dwOffset,
  33. const PBYTE pb,
  34. const DWORD cb,
  35. PDWORD pdwOffset,
  36. PDWORD pcbWritten );
  37. //
  38. // Flush the buffer into the file
  39. //
  40. HRESULT FlushFile();
  41. //
  42. // Tell the outside world if we are enabled
  43. //
  44. BOOL IsEnabled() const;
  45. //
  46. // Enable the write buffer and give it the buffer size
  47. //
  48. VOID Enable( const DWORD cbBuffer );
  49. //
  50. // Check to see if the buffer needs flush
  51. //
  52. BOOL NeedFlush() const;
  53. private:
  54. //
  55. // Private functions
  56. //
  57. HRESULT WriteFileReal(
  58. const DWORD dwOffset,
  59. const PBYTE pbBuffer,
  60. const DWORD cbBuffer,
  61. PDWORD pdwOffset,
  62. PDWORD pcbWritten
  63. );
  64. DWORD BufferAvail() const;
  65. VOID FillBuffer(
  66. const DWORD dwOffset,
  67. const PBYTE pbBuffer,
  68. const DWORD cbBuffer,
  69. PDWORD pdwOffset,
  70. PDWORD pcbWritten
  71. );
  72. BOOL NeedFlush(
  73. const DWORD dwOffset,
  74. const DWORD cbData
  75. ) const;
  76. //
  77. // Back pointer to parent flat file
  78. //
  79. CFlatFile* m_pParentFile;
  80. //
  81. // Buffer pointer
  82. //
  83. PBYTE m_pbBuffer;
  84. //
  85. // Buffer size
  86. //
  87. DWORD m_cbBuffer;
  88. //
  89. // Starting offset that we have buffered
  90. //
  91. DWORD m_iStart;
  92. //
  93. // Ending offset that we have buffered
  94. //
  95. DWORD m_iEnd;
  96. };
  97. #endif