libluna: Add assignment operators to Buffer

This commit is contained in:
apio 2023-08-04 15:10:33 +02:00
parent 277953065a
commit 7ab0c6b72b
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,9 @@ class Buffer
Buffer(Buffer&& other); Buffer(Buffer&& other);
Buffer(const Buffer& other) = delete; // For now. Buffer(const Buffer& other) = delete; // For now.
Buffer& operator=(Buffer&&);
Buffer& operator=(const Buffer&) = delete;
/** /**
* @brief Create a Buffer object, allocating a specific amount of memory for it. * @brief Create a Buffer object, allocating a specific amount of memory for it.
* *

View File

@ -24,6 +24,16 @@ Buffer::Buffer(Buffer&& other) : m_data(other.data()), m_size(other.size())
other.m_data = nullptr; other.m_data = nullptr;
} }
Buffer& Buffer::operator=(Buffer&& other)
{
if (&other == this) return *this;
if (m_data) free_impl(m_data);
m_data = other.m_data;
m_size = other.m_size;
other.m_data = nullptr;
return *this;
}
Buffer::~Buffer() Buffer::~Buffer()
{ {
if (m_data) free_impl(m_data); if (m_data) free_impl(m_data);