diff options
author | bunnei <bunneidev@gmail.com> | 2020-10-27 07:02:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 07:02:42 +0100 |
commit | d33399e1f46a10490b586196c6d0db0f04be4206 (patch) | |
tree | 8b2e1d98bf832049936ab931fc3a120e70bc36c2 /src/common/stream.cpp | |
parent | Merge pull request #4832 from bunnei/cpu-manager-microprofile-fix (diff) | |
parent | video_core: NVDEC Implementation (diff) | |
download | yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.tar yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.tar.gz yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.tar.bz2 yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.tar.lz yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.tar.xz yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.tar.zst yuzu-d33399e1f46a10490b586196c6d0db0f04be4206.zip |
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 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <stdexcept> +#include "common/common_types.h" +#include "common/stream.h" + +namespace Common { + +Stream::Stream() = default; +Stream::~Stream() = default; + +void Stream::Seek(s32 offset, SeekOrigin origin) { + if (origin == SeekOrigin::SetOrigin) { + if (offset < 0) { + position = 0; + } else if (position >= buffer.size()) { + position = buffer.size(); + } else { + position = offset; + } + } else if (origin == SeekOrigin::FromCurrentPos) { + Seek(static_cast<s32>(position) + offset, SeekOrigin::SetOrigin); + } else if (origin == SeekOrigin::FromEnd) { + Seek(static_cast<s32>(buffer.size()) - offset, SeekOrigin::SetOrigin); + } +} + +u8 Stream::ReadByte() { + if (position < buffer.size()) { + return buffer[position++]; + } else { + throw std::out_of_range("Attempting to read a byte not within the buffer range"); + } +} + +void Stream::WriteByte(u8 byte) { + if (position == buffer.size()) { + buffer.push_back(byte); + position++; + } else { + buffer.insert(buffer.begin() + position, byte); + } +} + +} // namespace Common |