ScummVM API documentation
Common::SeekableReadStream Class Referenceabstract

#include <stream.h>

Inheritance diagram for Common::SeekableReadStream:
Common::ReadStream Common::Stream Common::SeekableReadStreamEndian

Public Member Functions

virtual int32 pos () const =0
 
virtual int32 size () const =0
 
virtual bool seek (int32 offset, int whence=SEEK_SET)=0
 
virtual bool skip (uint32 offset)
 
virtual char * readLine (char *s, size_t bufSize, bool handleCR=true)
 
virtual String readLine (bool handleCR=true)
 
void hexdump (int len, int bytesPerLine=16, int startOffset=0)
 
- Public Member Functions inherited from Common::ReadStream
virtual bool eos () const =0
 
virtual uint32 read (void *dataPtr, uint32 dataSize)=0
 
byte readByte ()
 
FORCEINLINE int8 readSByte ()
 
uint16 readUint16LE ()
 
uint32 readUint32LE ()
 
uint64 readUint64LE ()
 
uint16 readUint16BE ()
 
uint32 readUint32BE ()
 
uint64 readUint64BE ()
 
FORCEINLINE int16 readSint16LE ()
 
FORCEINLINE int32 readSint32LE ()
 
FORCEINLINE int64 readSint64LE ()
 
FORCEINLINE int16 readSint16BE ()
 
FORCEINLINE int32 readSint32BE ()
 
FORCEINLINE int64 readSint64BE ()
 
FORCEINLINE float readFloatLE ()
 
FORCEINLINE float readFloatBE ()
 
FORCEINLINE double readDoubleLE ()
 
FORCEINLINE double readDoubleBE ()
 
SeekableReadStreamreadStream (uint32 dataSize)
 
Common::String readPascalString (bool transformCR=true)
 
- Public Member Functions inherited from Common::Stream
virtual bool err () const
 
virtual void clearErr ()
 

Detailed Description

Interface for a seekable and readable data stream.

Member Function Documentation

◆ pos()

virtual int32 Common::SeekableReadStream::pos ( ) const
pure virtual

Obtain the current value of the stream position indicator.

Returns
The current position indicator, or -1 if an error occurred.

◆ size()

virtual int32 Common::SeekableReadStream::size ( ) const
pure virtual

Obtain the total size of the stream, measured in bytes. If this value is unknown or cannot be computed, -1 is returned.

Returns
The size of the stream, or -1 if an error occurred.

◆ seek()

virtual bool Common::SeekableReadStream::seek ( int32  offset,
int  whence = SEEK_SET 
)
pure virtual

Set the stream position indicator for the stream.

The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-stream, respectively. A successful call to the seek() method clears the end-of-stream indicator for the stream.

Note
The semantics of any implementation of this method is supposed to match that of ISO C fseek().
Parameters
offsetRelative offset in bytes.
whenceSeek reference: SEEK_SET, SEEK_CUR, or SEEK_END.
Returns
True on success, false in case of a failure.

◆ skip()

virtual bool Common::SeekableReadStream::skip ( uint32  offset)
inlinevirtual

Skip the given number of bytes in the stream.

This is equivalent to calling:

seek(offset, SEK_CUR)

to add the given number of bytes to the current position indicator of the stream.

Returns
True on success, false in case of a failure.

◆ readLine() [1/2]

virtual char* Common::SeekableReadStream::readLine ( char *  s,
size_t  bufSize,
bool  handleCR = true 
)
virtual

Read at most one less than the number of characters specified by bufSize from the stream and store them in the string buffer.

Reading stops when the end of a line is reached (CR, CR/LF, or LF), and at end-of-stream or error. The newline, if any, is retained (CR and CR/LF are translated to LF = 0xA = '\n'). If any characters are read and there is no error, a \0 character is appended to end the string.

Upon successful completion, return a pointer to the string. If end-of-stream occurs before any characters are read, returns NULL and the buffer contents remain unchanged. If an error occurs, returns NULL and the buffer contents are indeterminate. This method does not distinguish between end-of-stream and error; callers must use err() or eos() to determine which occurred.

Note
This method is closely modeled after the standard fgets() function from stdio.h.
Parameters
sThe buffer to store into.
bufSizeSize of the buffer.
handleCRIf set (default), then CR and CR/LF are handled, as well as LF.
Returns
Pointer to the read string, or NULL if an error occurred.

◆ readLine() [2/2]

virtual String Common::SeekableReadStream::readLine ( bool  handleCR = true)
virtual

Read a full line and returns it as a Common::String.

Reading stops when the end of a line is reached (CR, CR/LF, or LF), and at end-of-stream or error.

Upon successful completion, return a string with the content of the line, without the end of a line marker. This method does not indicate whether an error occurred. Callers must use err() or eos() to determine whether an exception occurred.

Parameters
handleCRIf set (default), then CR and CR/LF are handled, as well as LF.

◆ hexdump()

void Common::SeekableReadStream::hexdump ( int  len,
int  bytesPerLine = 16,
int  startOffset = 0 
)

Print a hexdump of the stream while maintaing position. The number of bytes per line is customizable.

Parameters
lenLength of this data.
bytesPerLineNumber of bytes to print per line (default: 16).
startOffsetShift the shown offsets by the starting offset (default: 0).

The documentation for this class was generated from the following file: