ScummVM
Common::SeekableReadStream Class Referenceabstract

Interface for a seekable & readable data stream. More...

#include <stream.h>

Inheritance diagram for Common::SeekableReadStream:
Collaboration diagram for Common::SeekableReadStream:

Public Member Functions

virtual int32 pos () const =0
 Obtains the current value of the stream position indicator of the stream. More...
 
virtual int32 size () const =0
 Obtains the total size of the stream, measured in bytes. More...
 
virtual bool seek (int32 offset, int whence=SEEK_SET)=0
 Sets the stream position indicator for the stream. More...
 
virtual bool skip (uint32 offset)
 TODO: Get rid of this??? Or keep it and document it. More...
 
virtual char * readLine (char *s, size_t bufSize)
 Reads at most one less than the number of characters specified by bufSize from the and stores them in the string buf. More...
 
virtual String readLine ()
 Reads a full line and returns it as a Common::String. More...
 
void hexdump (int len, int bytesPerLine=16, int startOffset=0)
 Print a hexdump of the stream while maintaing position. More...
 
- Public Member Functions inherited from Common::ReadStream
virtual bool eos () const =0
 Returns true if a read failed because the stream end has been reached. More...
 
virtual uint32 read (void *dataPtr, uint32 dataSize)=0
 Read data from the stream. More...
 
byte readByte ()
 Read an unsigned byte from the stream and return it. More...
 
FORCEINLINE int8 readSByte ()
 Read a signed byte from the stream and return it. More...
 
uint16 readUint16LE ()
 Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
uint32 readUint32LE ()
 Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
uint64 readUint64LE ()
 Read an unsigned 64-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
uint16 readUint16BE ()
 Read an unsigned 16-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
uint32 readUint32BE ()
 Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
uint64 readUint64BE ()
 Read an unsigned 64-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE int16 readSint16LE ()
 Read a signed 16-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE int32 readSint32LE ()
 Read a signed 32-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE int64 readSint64LE ()
 Read a signed 64-bit word stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE int16 readSint16BE ()
 Read a signed 16-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE int32 readSint32BE ()
 Read a signed 32-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE int64 readSint64BE ()
 Read a signed 64-bit word stored in big endian (MSB first) order from the stream and return it. More...
 
FORCEINLINE float readFloatLE ()
 Read a 32-bit floating point value stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE float readFloatBE ()
 Read a 32-bit floating point value stored in big endian order from the stream and return it. More...
 
FORCEINLINE double readDoubleLE ()
 Read a 64-bit floating point value stored in little endian (LSB first) order from the stream and return it. More...
 
FORCEINLINE double readDoubleBE ()
 Read a 64-bit floating point value stored in big endian order from the stream and return it. More...
 
SeekableReadStreamreadStream (uint32 dataSize)
 Read the specified amount of data into a malloc'ed buffer which then is wrapped into a MemoryReadStream. More...
 
Common::String readPascalString (bool transformCR=true)
 Read stream in Pascal format, that is, one byte is string length, followed by string data. More...
 
- Public Member Functions inherited from Common::Stream
virtual ~Stream ()
 
virtual bool err () const
 Returns true if an I/O failure occurred. More...
 
virtual void clearErr ()
 Reset the I/O error status as returned by err(). More...
 

Detailed Description

Interface for a seekable & readable data stream.

Todo:
Get rid of SEEK_SET, SEEK_CUR, or SEEK_END, use our own constants

Definition at line 561 of file stream.h.

Member Function Documentation

◆ 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
lenthe length of that data
bytesPerLinenumber of bytes to print per line (default: 16)
startOffsetshift the shown offsets by the starting offset (default: 0)

Definition at line 248 of file stream.cpp.

◆ pos()

◆ readLine() [1/2]

char * Common::SeekableReadStream::readLine ( char *  s,
size_t  bufSize 
)
virtual

Reads at most one less than the number of characters specified by bufSize from the and stores them in the string buf.

Reading stops when the end of a line is reached (CR, CR/LF or LF), and at end-of-file or error. The newline, if any, is retained (CR and CR/LF are translated to LF = 0xA = '
'). 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-file 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-file and error; callers must use err() or eos() to determine which occurred.

Note
This methods is closely modeled after the standard fgets() function from stdio.h.
Parameters
sthe buffer to store into
bufSizethe size of the buffer
Returns
a pointer to the read string, or NULL if an error occurred

Reimplemented in Titanic::y222.

Definition at line 114 of file stream.cpp.

◆ readLine() [2/2]

String Common::SeekableReadStream::readLine ( )
virtual

Reads 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-file 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.

Reimplemented in Titanic::y222.

Definition at line 177 of file stream.cpp.

◆ seek()

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

Sets 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-file, respectively. A successful call to the seek() method clears the end-of-file indicator for the stream.

Note
The semantics of any implementation of this method are supposed to match those of ISO C fseek().
Parameters
offsetthe relative offset in bytes
whencethe seek reference: SEEK_SET, SEEK_CUR, or SEEK_END
Returns
true on success, false in case of a failure

Implemented in Parallaction::PowerPackerStream, Common::MemoryReadWriteStream, Common::GZipReadStream, InVMSave, DS::DSFileStream, Sci::MemoryDynamicRWStream, Common::File, Scumm::ScummDiskImage, BladeRunner::SaveFileReadStream, PS2FileStream, LastExpress::SavegameStream, Scumm::ScummNESFile, PspIoStream, Fullpipe::MfcArchive, Common::SeekableSubReadStream, Tinsel::TinselFile, Scumm::ScummFile, Common::MemoryReadStream, Gob::SaveConverter, TizenFileStream, Titanic::y222, RomfsStream, StdioStream, SymbianStdioStream, Kyra::EndianAwareStreamWrapper, Scumm::BaseScummFile, InFRAMSave, and InPAKSave.

◆ size()

◆ skip()

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

TODO: Get rid of this??? Or keep it and document it.

Returns
true on success, false in case of a failure

Reimplemented in InVMSave, Titanic::y222, InFRAMSave, and InPAKSave.

Definition at line 601 of file stream.h.


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