NT4/private/utils/ulib/inc/bytestrm.hxx
2020-09-30 17:12:29 +02:00

170 lines
2.2 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*++
Copyright (c) 1991 Microsoft Corporation
Module Name:
bytestream.hxx
Abstract:
This module contains the declarations for the BYTE_STREAM class.
BYTE_STREAM is a class which contains (not derives) a normal
ULIB stream and provided fast ReadByte operations. It is designed
for those utilities that have to read files one byte at a time.
Author:
Ramon J. San Andres (ramonsa) 28-Feb-1992
Environment:
ULIB, User Mode
--*/
#if !defined( _BYTE_STREAM_ )
#define _BYTE_STREAM_
#include "stream.hxx"
DECLARE_CLASS( BYTE_STREAM );
#define DEFAULT_BUFFER_SIZE 256
class BYTE_STREAM : public OBJECT {
public:
ULIB_EXPORT
DECLARE_CONSTRUCTOR( BYTE_STREAM );
VOID
BYTE_STREAM::Construct (
);
VIRTUAL
ULIB_EXPORT
~BYTE_STREAM (
);
NONVIRTUAL
ULIB_EXPORT
BOOLEAN
Initialize (
IN PSTREAM Stream,
IN DWORD BufferSize DEFAULT DEFAULT_BUFFER_SIZE
);
NONVIRTUAL
BOOLEAN
IsAtEnd(
) CONST;
NONVIRTUAL
BOOLEAN
ReadByte(
IN PBYTE Byte
);
private:
NONVIRTUAL
ULIB_EXPORT
BOOLEAN
FillAndReadByte (
IN PBYTE Byte
);
PSTREAM _Stream;
PBYTE _Buffer;
PBYTE _NextByte;
DWORD _BufferSize;
DWORD _BytesInBuffer;
};
INLINE
BOOLEAN
BYTE_STREAM::IsAtEnd(
) CONST
/*++
Routine Description:
Determines if we're at the end of the stream
Arguments:
None
Return Value:
BOOLEAN - TRUE if at end.
--*/
{
if ( _BytesInBuffer > 0 ) {
return FALSE;
} else {
return _Stream->IsAtEnd();
}
}
INLINE
BOOLEAN
BYTE_STREAM::ReadByte(
IN PBYTE Byte
)
/*++
Routine Description:
Reads next byte
Arguments:
Byte - Supplies pointer to where to put the byte
Return Value:
BOOLEAN - TRUE if byte read.
--*/
{
if ( _BytesInBuffer > 0 ) {
*Byte = *_NextByte++;
_BytesInBuffer--;
return TRUE;
} else {
return FillAndReadByte( Byte );
}
}
#endif // _BYTE_STREAM_