#include "core/Buffer.hpp" #include #include "core/Buffer.hpp" #include "core/Math.hpp" #include "core/Utility.hpp" Core::Buffer::Buffer() : length(0), capacity(0), buffer(nullptr) { } Core::Buffer::Buffer(const Buffer& other) : Buffer() { add(other.getData(), other.getLength()); } Core::Buffer::Buffer(Buffer&& other) noexcept : Buffer() { swap(other); } Core::Buffer::~Buffer() { deallocateRaw(buffer); } Core::Buffer& Core::Buffer::operator=(Buffer&& other) noexcept { swap(other); return *this; } Core::Buffer& Core::Buffer::operator=(const Buffer& other) { return add(other.getData(), other.length); } Core::Buffer& Core::Buffer::add(const void* data, size_t size) { while(length + size > capacity) { capacity += Core::max(8, capacity / 4); buffer = static_cast(reallocateRaw(buffer, capacity)); } memcpy(buffer + length, data, size); length += size; return *this; } size_t Core::Buffer::getLength() const { return length; } const char* Core::Buffer::getData() const { return buffer; } void Core::Buffer::swap(Buffer& other) noexcept { Core::swap(length, other.length); Core::swap(capacity, other.capacity); Core::swap(buffer, other.buffer); } void Core::Buffer::clear() { length = 0; }