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.

135 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998
  5. //
  6. // File: mmscbuf.cxx
  7. //
  8. // Contents: Memory Mapped Stream buffer for consecutive buffer mapping
  9. //
  10. // Classes: CMmStreamConsecBuf
  11. //
  12. // History: 22-Jul-93 AmyA Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <mmscbuf.hxx>
  18. //+-------------------------------------------------------------------------
  19. //
  20. // Member: CMmStreamConsecBuf::CMmStreamConsecBuf, public
  21. //
  22. // Synopsis: Constructor
  23. //
  24. // History: 22-Jul-93 AmyA Created
  25. //
  26. //--------------------------------------------------------------------------
  27. CMmStreamConsecBuf::CMmStreamConsecBuf()
  28. : _pMmStream(0)
  29. {
  30. _liOffset.QuadPart = 0;
  31. }
  32. //+-------------------------------------------------------------------------
  33. //
  34. // Member: CMmStreamConsecBuf::Map, public
  35. //
  36. // Synopsis: Map next consecutive part of file
  37. //
  38. // Arguments: [cb] -- size of the mapped area
  39. //
  40. // History: 22-Jul-93 AmyA Created
  41. //
  42. //--------------------------------------------------------------------------
  43. void CMmStreamConsecBuf::Map( ULONG cb )
  44. {
  45. Win4Assert( 0 != _pMmStream );
  46. if ( Get() != 0 )
  47. _pMmStream->Unmap( *this );
  48. LARGE_INTEGER liNewOffset;
  49. LARGE_INTEGER liStreamSize={_pMmStream->SizeLow(), _pMmStream->SizeHigh()};
  50. liNewOffset.QuadPart = cb + _liOffset.QuadPart;
  51. if ( liNewOffset.QuadPart > liStreamSize.QuadPart )
  52. {
  53. cb = (ULONG)(liStreamSize.QuadPart - _liOffset.QuadPart);
  54. liNewOffset = liStreamSize;
  55. }
  56. _pMmStream->Map( *this,
  57. cb,
  58. _liOffset.LowPart,
  59. _liOffset.HighPart );
  60. _liOffset = liNewOffset;
  61. }
  62. //+-------------------------------------------------------------------------
  63. //
  64. // Member: CMmStreamConsecBuf::Init, public
  65. //
  66. // Synopsis: Initizializes CMmStreamConsecBuf
  67. //
  68. // Arguments: [pMmStream] -- pointer to the CMmStream from which to fill
  69. // the buffer
  70. //
  71. // History: 22-Jul-93 AmyA Created
  72. //
  73. //--------------------------------------------------------------------------
  74. void CMmStreamConsecBuf::Init( PMmStream * pMmStream )
  75. {
  76. _pMmStream = pMmStream;
  77. _liOffset.QuadPart = 0;
  78. }
  79. //+-------------------------------------------------------------------------
  80. //
  81. // Member: CMmStreamConsecBuf::Rewind, public
  82. //
  83. // Synopsis: Rewind file to beginning.
  84. //
  85. // History: 13-Dec-93 AmyA Created
  86. //
  87. //--------------------------------------------------------------------------
  88. void CMmStreamConsecBuf::Rewind()
  89. {
  90. if ( 0 != Get() )
  91. {
  92. Win4Assert( 0 != _pMmStream );
  93. _pMmStream->Unmap( *this );
  94. }
  95. _liOffset.QuadPart = 0;
  96. }
  97. //+-------------------------------------------------------------------------
  98. //
  99. // Member: CMmStreamConsecBuf::Eof, public
  100. //
  101. // Synopsis: Returns whether end of file has been hit
  102. //
  103. // Returns: FALSE if there is still more file to be mapped. TRUE
  104. // otherwise.
  105. //
  106. // History: 22-Jul-93 AmyA Created
  107. //
  108. //--------------------------------------------------------------------------
  109. BOOL CMmStreamConsecBuf::Eof()
  110. {
  111. Win4Assert( 0 != _pMmStream );
  112. return( ( (ULONG) _liOffset.HighPart == _pMmStream->SizeHigh() ) &&
  113. ( _liOffset.LowPart == _pMmStream->SizeLow() ) );
  114. }