From 3bf9dbc3f75cdb9d7f97e5e34fe441e4f9067e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 13 Apr 2013 19:08:00 +0200 Subject: [PATCH] Trade: properly implement move constructor and assignment in MeshData. Default implementation of move constructor won't set pointer to indices to `nullptr` in `other` object, thus implementing it explicitly. Not sure what will happen in move assignment, implementing it explicitly too. --- src/Trade/MeshData2D.cpp | 12 ++++++++++-- src/Trade/MeshData3D.cpp | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp index 57cde771b..44ea06609 100644 --- a/src/Trade/MeshData2D.cpp +++ b/src/Trade/MeshData2D.cpp @@ -30,9 +30,17 @@ namespace Magnum { namespace Trade { MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _textureCoords2D(std::move(textureCoords2D)) {} -MeshData2D::MeshData2D(MeshData2D&&) = default; +MeshData2D::MeshData2D(MeshData2D&& other): _primitive(other._primitive), _indices(other._indices), _positions(std::move(other._positions)), _textureCoords2D(std::move(other._textureCoords2D)) { + other._indices = nullptr; +} -MeshData2D& MeshData2D::operator=(MeshData2D&&) = default; +MeshData2D& MeshData2D::operator=(MeshData2D&& other) { + _primitive = other._primitive; + std::swap(_indices, other._indices); + std::swap(_positions, other._positions); + std::swap(_textureCoords2D, other._textureCoords2D); + return *this; +} MeshData2D::~MeshData2D() { delete _indices; diff --git a/src/Trade/MeshData3D.cpp b/src/Trade/MeshData3D.cpp index ee6e27253..5ad47c640 100644 --- a/src/Trade/MeshData3D.cpp +++ b/src/Trade/MeshData3D.cpp @@ -30,9 +30,18 @@ namespace Magnum { namespace Trade { MeshData3D::MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _normals(std::move(normals)), _textureCoords2D(std::move(textureCoords2D)) {} -MeshData3D::MeshData3D(MeshData3D&&) = default; +MeshData3D::MeshData3D(MeshData3D&& other): _primitive(other._primitive), _indices(other._indices), _positions(std::move(other._positions)), _normals(std::move(other._normals)), _textureCoords2D(std::move(other._textureCoords2D)) { + other._indices = nullptr; +} -MeshData3D& MeshData3D::operator=(MeshData3D&&) = default; +MeshData3D& MeshData3D::operator=(MeshData3D&& other) { + _primitive = other._primitive; + std::swap(_indices, other._indices); + std::swap(_positions, other._positions); + std::swap(_normals, other._normals); + std::swap(_textureCoords2D, other._textureCoords2D); + return *this; +} MeshData3D::~MeshData3D() { delete _indices;