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.

169 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. bytestream.hxx
  5. Abstract:
  6. This module contains the declarations for the BYTE_STREAM class.
  7. BYTE_STREAM is a class which contains (not derives) a normal
  8. ULIB stream and provided fast ReadByte operations. It is designed
  9. for those utilities that have to read files one byte at a time.
  10. Author:
  11. Ramon J. San Andres (ramonsa) 28-Feb-1992
  12. Environment:
  13. ULIB, User Mode
  14. --*/
  15. #if !defined( _BYTE_STREAM_ )
  16. #define _BYTE_STREAM_
  17. #include "stream.hxx"
  18. DECLARE_CLASS( BYTE_STREAM );
  19. #define DEFAULT_BUFFER_SIZE 256
  20. class BYTE_STREAM : public OBJECT {
  21. public:
  22. ULIB_EXPORT
  23. DECLARE_CONSTRUCTOR( BYTE_STREAM );
  24. VOID
  25. BYTE_STREAM::Construct (
  26. );
  27. VIRTUAL
  28. ULIB_EXPORT
  29. ~BYTE_STREAM (
  30. );
  31. NONVIRTUAL
  32. ULIB_EXPORT
  33. BOOLEAN
  34. Initialize (
  35. IN PSTREAM Stream,
  36. IN DWORD BufferSize DEFAULT DEFAULT_BUFFER_SIZE
  37. );
  38. NONVIRTUAL
  39. BOOLEAN
  40. IsAtEnd(
  41. ) CONST;
  42. NONVIRTUAL
  43. BOOLEAN
  44. ReadByte(
  45. IN PBYTE Byte
  46. );
  47. private:
  48. NONVIRTUAL
  49. ULIB_EXPORT
  50. BOOLEAN
  51. FillAndReadByte (
  52. IN PBYTE Byte
  53. );
  54. PSTREAM _Stream;
  55. PBYTE _Buffer;
  56. PBYTE _NextByte;
  57. DWORD _BufferSize;
  58. DWORD _BytesInBuffer;
  59. };
  60. INLINE
  61. BOOLEAN
  62. BYTE_STREAM::IsAtEnd(
  63. ) CONST
  64. /*++
  65. Routine Description:
  66. Determines if we're at the end of the stream
  67. Arguments:
  68. None
  69. Return Value:
  70. BOOLEAN - TRUE if at end.
  71. --*/
  72. {
  73. if ( _BytesInBuffer > 0 ) {
  74. return FALSE;
  75. } else {
  76. return _Stream->IsAtEnd();
  77. }
  78. }
  79. INLINE
  80. BOOLEAN
  81. BYTE_STREAM::ReadByte(
  82. IN PBYTE Byte
  83. )
  84. /*++
  85. Routine Description:
  86. Reads next byte
  87. Arguments:
  88. Byte - Supplies pointer to where to put the byte
  89. Return Value:
  90. BOOLEAN - TRUE if byte read.
  91. --*/
  92. {
  93. if ( _BytesInBuffer > 0 ) {
  94. *Byte = *_NextByte++;
  95. _BytesInBuffer--;
  96. return TRUE;
  97. } else {
  98. return FillAndReadByte( Byte );
  99. }
  100. }
  101. #endif // _BYTE_STREAM_