From 13f00211d3cfdfb7cd107469fb2e8e1eb28cd1b5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 18 Apr 2022 16:34:14 +0100 Subject: [PATCH] Surface_mesh: Add move semantics --- .../include/CGAL/Surface_mesh/Properties.h | 21 +++++++- .../include/CGAL/Surface_mesh/Surface_mesh.h | 54 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index 825d414e707..7a02ef0ed73 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -242,6 +242,12 @@ public: // copy constructor: performs deep copy of property arrays Property_container(const Property_container& _rhs) { operator=(_rhs); } + Property_container(Property_container&& c) noexcept + : size_(0), capacity_(0) + { + c.swap(*this); + } + // assignment: performs deep copy of property arrays Property_container& operator=(const Property_container& _rhs) { @@ -257,6 +263,14 @@ public: return *this; } + Property_container& operator=(Property_container&& c) noexcept + { + Self tmp(std::move(c)); + tmp.swap(*this); + return *this; + } + + void transfer(const Property_container& _rhs) { for(std::size_t i=0; iparrays_.swap (other.parrays_); - std::swap(this->size_, other.size_); + std::swap(this->size_, other.size_); // AF: why not the same for capacity_ ? } private: @@ -554,6 +568,11 @@ public: /// @cond CGAL_DOCUMENT_INTERNALS Property_map_base(Property_array* p=nullptr) : parray_(p) {} + Property_map_base(Property_map_base&& pm) noexcept + : parray_(std::exchange(pm.parray_, nullptr)) + {} + + Property_map_base(const Property_map_base& pm) = default; void reset() { parray_ = nullptr; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 2127f3c8ed3..d1cc535344a 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -343,6 +343,12 @@ public: typedef typename Base::reference reference; Property_map() : Base() {} Property_map(const Base& pm): Base(pm) {} + + Property_map(const Property_map& pm) = default; + + Property_map(Property_map&& pm) noexcept + : Base(pm) + {} }; template @@ -914,9 +920,57 @@ public: /// Copy constructor: copies `rhs` to `*this`. Performs a deep copy of all properties. Surface_mesh(const Surface_mesh& rhs) { *this = rhs; } + Surface_mesh(Surface_mesh&& sm) + : vprops_(std::move(sm.vprops_)) + , hprops_(std::move(sm.hprops_)) + , eprops_(std::move(sm.eprops_)) + , fprops_(std::move(sm.fprops_)) + , vconn_(std::move(sm.vconn_)) + , hconn_(std::move(sm.hconn_)) + , fconn_(std::move(sm.fconn_)) + , vremoved_(std::move(sm.vremoved_)) + , eremoved_(std::move(sm.eremoved_)) + , fremoved_(std::move(sm.fremoved_)) + , vpoint_(std::move(sm.vpoint_)) + , removed_vertices_(sd::exchange(sm.removed_vertices, 0)) + , removed_edges_(sd::exchange(sm.removed_edges, 0)) + , removed_faces_(sd::exchange(sm.removed_faces, 0)) + , vertices_freelist_(std::exchange(sm.vertices_freelist_,(std::numeric_limits::max)())) + , edgces_freelist_(std::exchange(sm.edges_freelist_,(std::numeric_limits::max)())) + , faces_freelist_(std::exchange(sm.faces_freelist_,(std::numeric_limits::max)())) + , garbage_(std::exchange(sm.garbage_, false)) + , recycle_(std::exchange(sm.recycle_, true)) + , anonymous_property_(std::exchange(sm.anonymous_property_, 0)) + {} + /// assigns `rhs` to `*this`. Performs a deep copy of all properties. Surface_mesh& operator=(const Surface_mesh& rhs); + + Surface_mesh& operator=(Surface_mesh&& sm) + { + vprops_ = std::move(sm.vprops_); + hprops_ = std::move(sm.hprops_); + eprops_ = std::move(sm.eprops_); + fprops_ = std::move(sm.fprops_); + vconn_ = std::move(sm.vconn_); + hconn_ = std::move(sm.hconn_); + fconn_ = std::move(sm.fconn_); + vremoved_ = std::move(sm.vremoved_); + eremoved_ = std::move(sm.eremoved_); + fremoved_ = std::move(sm.fremoved_); + vpoint_ = std::move(sm.vpoint_); + removed_vertices_ = sd::exchange(sm.removed_vertices, 0); + removed_edges_ = sd::exchange(sm.removed_edges, 0); + removed_faces_ = sd::exchange(sm.removed_faces, 0); + vertices_freelist_ = std::exchange(sm.vertices_freelist_, (std::numeric_limits::max)();) + edgces_freelist_ = std::exchange(sm.edges_freelist_,(std::numeric_limits::max)();) + faces_freelist_ = std::exchange(sm.faces_freelist_,(std::numeric_limits::max)();) + garbage_ = std::exchange(sm.garbage_, false); + recycle_ = std::exchange(sm.recycle_, true); + anonymous_property_ = std::exchange(sm.anonymous_property_, 0); + } + /// assigns `rhs` to `*this`. Does not copy custom properties. Surface_mesh& assign(const Surface_mesh& rhs);