From 7ab0c6b72b509b5d77094e0af1906084a57c0083 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 4 Aug 2023 15:10:33 +0200 Subject: [PATCH] libluna: Add assignment operators to Buffer --- libluna/include/luna/Buffer.h | 3 +++ libluna/src/Buffer.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/libluna/include/luna/Buffer.h b/libluna/include/luna/Buffer.h index cd711c0a..3a561eaf 100644 --- a/libluna/include/luna/Buffer.h +++ b/libluna/include/luna/Buffer.h @@ -23,6 +23,9 @@ class Buffer Buffer(Buffer&& other); 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. * diff --git a/libluna/src/Buffer.cpp b/libluna/src/Buffer.cpp index b0a0b29b..188ec368 100644 --- a/libluna/src/Buffer.cpp +++ b/libluna/src/Buffer.cpp @@ -24,6 +24,16 @@ Buffer::Buffer(Buffer&& other) : m_data(other.data()), m_size(other.size()) 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() { if (m_data) free_impl(m_data);