Browse Source

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.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
3bf9dbc3f7
  1. 12
      src/Trade/MeshData2D.cpp
  2. 13
      src/Trade/MeshData3D.cpp

12
src/Trade/MeshData2D.cpp

@ -30,9 +30,17 @@ namespace Magnum { namespace Trade {
MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector2>*> positions, std::vector<std::vector<Vector2>*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _textureCoords2D(std::move(textureCoords2D)) {} MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector2>*> positions, std::vector<std::vector<Vector2>*> 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() { MeshData2D::~MeshData2D() {
delete _indices; delete _indices;

13
src/Trade/MeshData3D.cpp

@ -30,9 +30,18 @@ namespace Magnum { namespace Trade {
MeshData3D::MeshData3D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector3>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _normals(std::move(normals)), _textureCoords2D(std::move(textureCoords2D)) {} MeshData3D::MeshData3D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector3>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> 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() { MeshData3D::~MeshData3D() {
delete _indices; delete _indices;

Loading…
Cancel
Save