Surface_mesh: Add move semantics

This commit is contained in:
Andreas Fabri 2022-04-18 16:34:14 +01:00
parent af29d8d3d7
commit 13f00211d3
2 changed files with 74 additions and 1 deletions

View File

@ -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; i<parrays_.size(); ++i){
@ -494,7 +508,7 @@ public:
void swap (Property_container& other)
{
this->parrays_.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<T>* 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;

View File

@ -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 <typename Key, typename T>
@ -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<size_type>::max)()))
, edgces_freelist_(std::exchange(sm.edges_freelist_,(std::numeric_limits<size_type>::max)()))
, faces_freelist_(std::exchange(sm.faces_freelist_,(std::numeric_limits<size_type>::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<size_type>::max)();)
edgces_freelist_ = std::exchange(sm.edges_freelist_,(std::numeric_limits<size_type>::max)();)
faces_freelist_ = std::exchange(sm.faces_freelist_,(std::numeric_limits<size_type>::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);