libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::Stream Class Referenceabstract

Abstract base class for sequential byte streams (read/write). More...

#include <Stream.h>

Inheritance diagram for Ship::Stream:
[legend]

Public Member Functions

virtual ~Stream ()=default
 
virtual uint64_t GetLength ()=0
 Returns the total length of the stream in bytes.
 
uint64_t GetBaseAddress ()
 Returns the current stream position as an absolute byte offset.
 
virtual void Seek (int32_t offset, SeekOffsetType seekType)=0
 Moves the stream position.
 
virtual std::unique_ptr< char[]> Read (size_t length)=0
 Reads length bytes from the current position and advances the position.
 
virtual void Read (char *dest, size_t length)=0
 Reads length bytes from the current position into a caller-supplied buffer.
 
virtual int8_t ReadByte ()=0
 Reads a single byte from the current position.
 
virtual void Write (char *destBuffer, size_t length)=0
 Writes length bytes from destBuffer at the current position.
 
virtual void WriteByte (int8_t value)=0
 Writes a single byte at the current position.
 
virtual std::vector< char > ToVector ()=0
 Returns the full stream contents as a std::vector<char>.
 
virtual void Flush ()=0
 Flushes any buffered writes to the underlying storage.
 
virtual void Close ()=0
 Closes the stream and releases any held resources.
 

Protected Attributes

uint64_t mBaseAddress
 Current read/write position (byte offset from the start).
 

Detailed Description

Abstract base class for sequential byte streams (read/write).

Stream provides a common interface used by BinaryReader and BinaryWriter so that both can operate transparently over an in-memory buffer (MemoryStream) or any other concrete stream implementation without code changes.

All read and write operations advance an internal position cursor. Seeking is supported via Seek() with relative or absolute offsets.

Constructor & Destructor Documentation

◆ ~Stream()

virtual Ship::Stream::~Stream ( )
virtualdefault

Member Function Documentation

◆ Close()

virtual void Ship::Stream::Close ( )
pure virtual

Closes the stream and releases any held resources.

Implemented in Ship::MemoryStream.

◆ Flush()

virtual void Ship::Stream::Flush ( )
pure virtual

Flushes any buffered writes to the underlying storage.

Implemented in Ship::MemoryStream.

◆ GetBaseAddress()

uint64_t Ship::Stream::GetBaseAddress ( )

Returns the current stream position as an absolute byte offset.

◆ GetLength()

virtual uint64_t Ship::Stream::GetLength ( )
pure virtual

Returns the total length of the stream in bytes.

Implemented in Ship::MemoryStream.

◆ Read() [1/2]

virtual void Ship::Stream::Read ( char *  dest,
size_t  length 
)
pure virtual

Reads length bytes from the current position into a caller-supplied buffer.

Parameters
destWritable destination buffer (must be at least length bytes).
lengthNumber of bytes to read.

Implemented in Ship::MemoryStream.

◆ Read() [2/2]

virtual std::unique_ptr< char[]> Ship::Stream::Read ( size_t  length)
pure virtual

Reads length bytes from the current position and advances the position.

Parameters
lengthNumber of bytes to read.
Returns
Heap-allocated buffer containing the read bytes.

Implemented in Ship::MemoryStream.

◆ ReadByte()

virtual int8_t Ship::Stream::ReadByte ( )
pure virtual

Reads a single byte from the current position.

Throws std::out_of_range if the position is past the end of the stream.

Returns
The byte value at the current position.

Implemented in Ship::MemoryStream.

◆ Seek()

virtual void Ship::Stream::Seek ( int32_t  offset,
SeekOffsetType  seekType 
)
pure virtual

Moves the stream position.

Parameters
offsetNumber of bytes to seek (can be negative for SeekOffsetType::Current/End).
seekTypeReference point for the seek (start, current, or end).

Implemented in Ship::MemoryStream.

◆ ToVector()

virtual std::vector< char > Ship::Stream::ToVector ( )
pure virtual

Returns the full stream contents as a std::vector<char>.

Implemented in Ship::MemoryStream.

◆ Write()

virtual void Ship::Stream::Write ( char *  destBuffer,
size_t  length 
)
pure virtual

Writes length bytes from destBuffer at the current position.

Parameters
destBufferSource buffer.
lengthNumber of bytes to write.

Implemented in Ship::MemoryStream.

◆ WriteByte()

virtual void Ship::Stream::WriteByte ( int8_t  value)
pure virtual

Writes a single byte at the current position.

Parameters
valueByte to write.

Implemented in Ship::MemoryStream.

Member Data Documentation

◆ mBaseAddress

uint64_t Ship::Stream::mBaseAddress
protected

Current read/write position (byte offset from the start).


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