Browse Source

Proper noexcept move constructor for Mesh.

Also documented the inability to copy.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
a168d2af4e
  1. 32
      src/Mesh.cpp
  2. 13
      src/Mesh.h

32
src/Mesh.cpp

@ -75,7 +75,7 @@ Mesh::~Mesh() {
(this->*destroyImplementation)(); (this->*destroyImplementation)();
} }
Mesh::Mesh(Mesh&& other): _id(other._id), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount) Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
, _indexStart(other._indexStart), _indexEnd(other._indexEnd) , _indexStart(other._indexStart), _indexEnd(other._indexEnd)
#endif #endif
@ -90,30 +90,26 @@ Mesh::Mesh(Mesh&& other): _id(other._id), _primitive(other._primitive), _vertexC
other._id = 0; other._id = 0;
} }
Mesh& Mesh::operator=(Mesh&& other) { Mesh& Mesh::operator=(Mesh&& other) noexcept {
(this->*destroyImplementation)(); std::swap(_id, other._id);
std::swap(_primitive, other._primitive);
_id = other._id; std::swap(_vertexCount, other._vertexCount);
_primitive = other._primitive; std::swap(_indexCount, other._indexCount);
_vertexCount = other._vertexCount;
_indexCount = other._indexCount;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
_indexStart = other._indexStart; std::swap(_indexStart, other._indexStart);
_indexEnd = other._indexEnd; std::swap(_indexEnd, other._indexEnd);
#endif #endif
_indexOffset = other._indexOffset; std::swap(_indexOffset, other._indexOffset);
_indexType = other._indexType; std::swap(_indexType, other._indexType);
_indexBuffer = other._indexBuffer; std::swap(_indexBuffer, other._indexBuffer);
_attributes = std::move(other._attributes); std::swap(_attributes, other._attributes);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
_integerAttributes = std::move(other._integerAttributes); std::swap(_integerAttributes, other._integerAttributes);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
_longAttributes = std::move(other._longAttributes); std::swap(_longAttributes, other._longAttributes);
#endif #endif
#endif #endif
other._id = 0;
return *this; return *this;
} }

13
src/Mesh.h

@ -242,9 +242,6 @@ class MAGNUM_EXPORT Mesh {
friend class Context; friend class Context;
friend class MeshView; friend class MeshView;
Mesh(const Mesh&) = delete;
Mesh& operator=(const Mesh&) = delete;
public: public:
/** /**
* @brief Primitive type * @brief Primitive type
@ -353,8 +350,11 @@ class MAGNUM_EXPORT Mesh {
*/ */
explicit Mesh(Primitive primitive = Primitive::Triangles); explicit Mesh(Primitive primitive = Primitive::Triangles);
/** @brief Copying is not allowed */
Mesh(const Mesh&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
Mesh(Mesh&& other); Mesh(Mesh&& other) noexcept;
/** /**
* @brief Destructor * @brief Destructor
@ -364,8 +364,11 @@ class MAGNUM_EXPORT Mesh {
*/ */
~Mesh(); ~Mesh();
/** @brief Copying is not allowed */
Mesh& operator=(const Mesh&) = delete;
/** @brief Move assignment */ /** @brief Move assignment */
Mesh& operator=(Mesh&& other); Mesh& operator=(Mesh&& other) noexcept;
/** /**
* @brief Index size * @brief Index size

Loading…
Cancel
Save