From cd2a8b74ac42c9fcee822e993410246719760f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 28 Aug 2013 16:31:40 +0200 Subject: [PATCH] Noexcept moving for Buffer, documented inability to copy. --- src/Buffer.cpp | 3 +++ src/Buffer.h | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 5e50750a6..5286ac42f 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -87,6 +87,9 @@ Buffer::Buffer(Buffer::Target targetHint): _targetHint(targetHint) } Buffer::~Buffer() { + /* Moved out, nothing to do */ + if(!_id) return; + GLuint* bindings = Context::current()->state().buffer->bindings; /* Remove all current bindings from the state */ diff --git a/src/Buffer.h b/src/Buffer.h index 1393cfe13..479fb6204 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -125,11 +125,6 @@ nothing. class MAGNUM_EXPORT Buffer { friend class Context; - Buffer(const Buffer&) = delete; - Buffer(Buffer&&) = delete; - Buffer& operator=(const Buffer&) = delete; - Buffer& operator=(Buffer&&) = delete; - public: /** * @brief %Buffer target @@ -474,6 +469,12 @@ class MAGNUM_EXPORT Buffer { */ explicit Buffer(Target targetHint = Target::Array); + /** @brief Copying is not allowed */ + Buffer(const Buffer&) = delete; + + /** @brief Move constructor */ + Buffer(Buffer&& other) noexcept; + /** * @brief Destructor * @@ -482,6 +483,12 @@ class MAGNUM_EXPORT Buffer { */ ~Buffer(); + /** @brief Copying is not allowed */ + Buffer& operator=(const Buffer&) = delete; + + /** @brief Move assignment */ + Buffer& operator=(Buffer&& other) noexcept; + /** @brief OpenGL buffer ID */ GLuint id() const { return _id; } @@ -924,6 +931,16 @@ CORRADE_ENUMSET_OPERATORS(Buffer::MapFlags) /** @debugoperator{Magnum::Buffer} */ Debug MAGNUM_EXPORT operator<<(Debug debug, Buffer::Target value); +inline Buffer::Buffer(Buffer&& other) noexcept: _id(other._id), _targetHint(other._targetHint) { + other._id = 0; +} + +inline Buffer& Buffer::operator=(Buffer&& other) noexcept { + std::swap(_id, other._id); + std::swap(_targetHint, other._targetHint); + return *this; +} + #ifndef MAGNUM_TARGET_GLES template Containers::Array inline Buffer::data() { const Int bufferSize = size();