libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Stream.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <vector>
6
7namespace Ship {
8
10enum class SeekOffsetType {
11 Start,
12 Current,
13 End,
14};
15
26class Stream {
27 public:
28 virtual ~Stream() = default;
29
33 virtual uint64_t GetLength() = 0;
34
38 uint64_t GetBaseAddress();
39
45 virtual void Seek(int32_t offset, SeekOffsetType seekType) = 0;
46
52 virtual std::unique_ptr<char[]> Read(size_t length) = 0;
53
59 virtual void Read(char* dest, size_t length) = 0;
60
68 virtual int8_t ReadByte() = 0;
69
75 virtual void Write(char* destBuffer, size_t length) = 0;
76
81 virtual void WriteByte(int8_t value) = 0;
82
86 virtual std::vector<char> ToVector() = 0;
87
91 virtual void Flush() = 0;
92
96 virtual void Close() = 0;
97
98 protected:
99 uint64_t mBaseAddress;
100};
101} // namespace Ship
Abstract base class for sequential byte streams (read/write).
Definition Stream.h:26
virtual void Seek(int32_t offset, SeekOffsetType seekType)=0
Moves the stream position.
virtual void Close()=0
Closes the stream and releases any held resources.
virtual void WriteByte(int8_t value)=0
Writes a single byte at the current position.
virtual int8_t ReadByte()=0
Reads a single byte from the current position.
virtual std::unique_ptr< char[]> Read(size_t length)=0
Reads length bytes from the current position and advances the position.
virtual uint64_t GetLength()=0
Returns the total length of the stream in bytes.
uint64_t mBaseAddress
Current read/write position (byte offset from the start).
Definition Stream.h:99
uint64_t GetBaseAddress()
Returns the current stream position as an absolute byte offset.
virtual ~Stream()=default
virtual void Read(char *dest, size_t length)=0
Reads length bytes from the current position into a caller-supplied buffer.
virtual void Write(char *destBuffer, size_t length)=0
Writes length bytes from destBuffer 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.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
SeekOffsetType
Identifies the reference point for a seek operation.
Definition Stream.h:10
@ Current
Seek relative to the current position.