mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-25 19:02:45 -06:00
99ceb03a1c
This formats all copyright comments according to SPDX formatting guidelines. Additionally, this resolves the remaining GPLv2 only licensed files by relicensing them to GPLv2.0-or-later.
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#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
|