diff options
Diffstat (limited to 'src/common/stream.h')
| -rw-r--r-- | src/common/stream.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/common/stream.h b/src/common/stream.h new file mode 100644 index 000000000..2585c16af --- /dev/null +++ b/src/common/stream.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | |||
| 10 | namespace Common { | ||
| 11 | |||
| 12 | enum class SeekOrigin { | ||
| 13 | SetOrigin, | ||
| 14 | FromCurrentPos, | ||
| 15 | FromEnd, | ||
| 16 | }; | ||
| 17 | |||
| 18 | class Stream { | ||
| 19 | public: | ||
| 20 | /// Stream creates a bitstream and provides common functionality on the stream. | ||
| 21 | explicit Stream(); | ||
| 22 | ~Stream(); | ||
| 23 | |||
| 24 | /// Reposition bitstream "cursor" to the specified offset from origin | ||
| 25 | void Seek(s32 offset, SeekOrigin origin); | ||
| 26 | |||
| 27 | /// Reads next byte in the stream buffer and increments position | ||
| 28 | u8 ReadByte(); | ||
| 29 | |||
| 30 | /// Writes byte at current position | ||
| 31 | void WriteByte(u8 byte); | ||
| 32 | |||
| 33 | std::size_t GetPosition() const { | ||
| 34 | return position; | ||
| 35 | } | ||
| 36 | |||
| 37 | std::vector<u8>& GetBuffer() { | ||
| 38 | return buffer; | ||
| 39 | } | ||
| 40 | |||
| 41 | const std::vector<u8>& GetBuffer() const { | ||
| 42 | return buffer; | ||
| 43 | } | ||
| 44 | |||
| 45 | private: | ||
| 46 | std::vector<u8> buffer; | ||
| 47 | std::size_t position{0}; | ||
| 48 | }; | ||
| 49 | |||
| 50 | } // namespace Common | ||