diff options
| author | 2021-01-10 22:09:56 -0700 | |
|---|---|---|
| committer | 2021-01-10 22:09:56 -0700 | |
| commit | 7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch) | |
| tree | 5056f9406dec188439cb0deb87603498243a9412 /src/common/stream.cpp | |
| parent | More forgetting... duh (diff) | |
| parent | Merge pull request #5229 from Morph1984/fullscreen-opt (diff) | |
| download | yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip | |
Merge remote-tracking branch 'upstream/master' into int-flags
Diffstat (limited to 'src/common/stream.cpp')
| -rw-r--r-- | src/common/stream.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/common/stream.cpp b/src/common/stream.cpp new file mode 100644 index 000000000..bf0496c26 --- /dev/null +++ b/src/common/stream.cpp | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <stdexcept> | ||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "common/stream.h" | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | Stream::Stream() = default; | ||
| 12 | Stream::~Stream() = default; | ||
| 13 | |||
| 14 | void Stream::Seek(s32 offset, SeekOrigin origin) { | ||
| 15 | if (origin == SeekOrigin::SetOrigin) { | ||
| 16 | if (offset < 0) { | ||
| 17 | position = 0; | ||
| 18 | } else if (position >= buffer.size()) { | ||
| 19 | position = buffer.size(); | ||
| 20 | } else { | ||
| 21 | position = offset; | ||
| 22 | } | ||
| 23 | } else if (origin == SeekOrigin::FromCurrentPos) { | ||
| 24 | Seek(static_cast<s32>(position) + offset, SeekOrigin::SetOrigin); | ||
| 25 | } else if (origin == SeekOrigin::FromEnd) { | ||
| 26 | Seek(static_cast<s32>(buffer.size()) - offset, SeekOrigin::SetOrigin); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | u8 Stream::ReadByte() { | ||
| 31 | if (position < buffer.size()) { | ||
| 32 | return buffer[position++]; | ||
| 33 | } else { | ||
| 34 | throw std::out_of_range("Attempting to read a byte not within the buffer range"); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void Stream::WriteByte(u8 byte) { | ||
| 39 | if (position == buffer.size()) { | ||
| 40 | buffer.push_back(byte); | ||
| 41 | position++; | ||
| 42 | } else { | ||
| 43 | buffer.insert(buffer.begin() + position, byte); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | } // namespace Common | ||