2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-19 23:11:50 +00:00

refactor: combined ZoneOutputStream interface with impl

This commit is contained in:
Jan Laupetin
2026-01-06 13:29:32 +00:00
parent ac9bdd21da
commit ac24e4f893
29 changed files with 354 additions and 310 deletions

View File

@@ -0,0 +1,38 @@
#include "InMemoryZoneData.h"
#include <stdexcept>
InMemoryZoneData::InMemoryZoneData()
: m_total_size(0)
{
m_buffers.emplace_back(BUFFER_SIZE);
}
InMemoryZoneData::MemoryBuffer::MemoryBuffer(const size_t size)
: m_data(std::make_unique<char[]>(size)),
m_size(0)
{
if (!m_data)
throw std::runtime_error("Failed to allocate memory for memory buffer.");
}
void* InMemoryZoneData::GetBufferOfSize(const size_t size)
{
if (size > BUFFER_SIZE)
{
m_buffers.emplace_back(size);
}
else
{
if (m_buffers.back().m_size + size > BUFFER_SIZE)
{
m_buffers.emplace_back(BUFFER_SIZE);
}
}
auto& backBuffer = m_buffers.back();
void* result = &backBuffer.m_data[backBuffer.m_size];
backBuffer.m_size += size;
m_total_size += size;
return result;
}