Improvement of the move semantics on various objects:
The source object will be empty after the move operation.
This commit is contained in:
parent
d5f9db76b3
commit
29b986fa76
@ -206,26 +206,27 @@ inline Polygons to_polygons(const ExPolygons &src)
|
||||
return polygons;
|
||||
}
|
||||
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
inline Polygons to_polygons(ExPolygon &&src)
|
||||
{
|
||||
Polygons polygons;
|
||||
polygons.reserve(src.holes.size() + 1);
|
||||
polygons.push_back(std::move(src.contour));
|
||||
std::move(std::begin(src.holes), std::end(src.holes), std::back_inserter(polygons));
|
||||
src.holes.clear();
|
||||
return polygons;
|
||||
}
|
||||
|
||||
inline Polygons to_polygons(ExPolygons &&src)
|
||||
{
|
||||
Polygons polygons;
|
||||
polygons.reserve(number_polygons(src));
|
||||
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) {
|
||||
for (ExPolygons::iterator it = src.begin(); it != src.end(); ++it) {
|
||||
polygons.push_back(std::move(it->contour));
|
||||
std::move(std::begin(it->holes), std::end(it->holes), std::back_inserter(polygons));
|
||||
it->holes.clear();
|
||||
}
|
||||
return polygons;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void polygons_append(Polygons &dst, const ExPolygon &src)
|
||||
{
|
||||
@ -243,35 +244,38 @@ inline void polygons_append(Polygons &dst, const ExPolygons &src)
|
||||
}
|
||||
}
|
||||
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
inline void polygons_append(Polygons &dst, ExPolygon &&src)
|
||||
{
|
||||
dst.reserve(dst.size() + src.holes.size() + 1);
|
||||
dst.push_back(std::move(src.contour));
|
||||
std::move(std::begin(src.holes), std::end(src.holes), std::back_inserter(dst));
|
||||
src.holes.clear();
|
||||
}
|
||||
|
||||
inline void polygons_append(Polygons &dst, ExPolygons &&src)
|
||||
{
|
||||
dst.reserve(dst.size() + number_polygons(src));
|
||||
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
||||
for (ExPolygons::iterator it = src.begin(); it != src.end(); ++ it) {
|
||||
dst.push_back(std::move(it->contour));
|
||||
std::move(std::begin(it->holes), std::end(it->holes), std::back_inserter(dst));
|
||||
it->holes.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void expolygons_append(ExPolygons &dst, const ExPolygons &src)
|
||||
{
|
||||
dst.insert(dst.end(), src.begin(), src.end());
|
||||
}
|
||||
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
inline void expolygons_append(ExPolygons &dst, ExPolygons &&src)
|
||||
{
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
||||
if (dst.empty()) {
|
||||
dst = std::move(src);
|
||||
} else {
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void expolygons_rotate(ExPolygons &expolys, double angle)
|
||||
{
|
||||
|
@ -78,7 +78,12 @@ public:
|
||||
|
||||
ExtrusionPath(ExtrusionRole role) : role(role), mm3_per_mm(-1), width(-1), height(-1) {};
|
||||
ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height) : role(role), mm3_per_mm(mm3_per_mm), width(width), height(height) {};
|
||||
ExtrusionPath(ExtrusionPath &&rhs) : role(rhs.role), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), polyline(std::move(rhs.polyline)) {}
|
||||
// ExtrusionPath(ExtrusionRole role, const Flow &flow) : role(role), mm3_per_mm(flow.mm3_per_mm()), width(flow.width), height(flow.height) {};
|
||||
|
||||
ExtrusionPath& operator=(const ExtrusionPath &rhs) { this->role = rhs.role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height; this->polyline = rhs.polyline; return *this; }
|
||||
ExtrusionPath& operator=(ExtrusionPath &&rhs) { this->role = rhs.role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height; this->polyline = std::move(rhs.polyline); return *this; }
|
||||
|
||||
ExtrusionPath* clone() const { return new ExtrusionPath (*this); }
|
||||
void reverse() { this->polyline.reverse(); }
|
||||
Point first_point() const { return this->polyline.points.front(); }
|
||||
@ -140,8 +145,14 @@ public:
|
||||
ExtrusionPaths paths;
|
||||
|
||||
ExtrusionMultiPath() {};
|
||||
ExtrusionMultiPath(const ExtrusionMultiPath &rhs) : paths(rhs.paths) {}
|
||||
ExtrusionMultiPath(ExtrusionMultiPath &&rhs) : paths(std::move(rhs.paths)) {}
|
||||
ExtrusionMultiPath(const ExtrusionPaths &paths) : paths(paths) {};
|
||||
ExtrusionMultiPath(const ExtrusionPath &path) { this->paths.push_back(path); }
|
||||
|
||||
ExtrusionMultiPath& operator=(const ExtrusionMultiPath &rhs) { this->paths = rhs.paths; return *this; }
|
||||
ExtrusionMultiPath& operator=(ExtrusionMultiPath &&rhs) { this->paths = std::move(rhs.paths); return *this; }
|
||||
|
||||
bool is_loop() const { return false; }
|
||||
bool can_reverse() const { return true; }
|
||||
ExtrusionMultiPath* clone() const { return new ExtrusionMultiPath(*this); }
|
||||
|
@ -66,20 +66,6 @@ ExtrusionEntityCollection::reverse()
|
||||
std::reverse(this->entities.begin(), this->entities.end());
|
||||
}
|
||||
|
||||
void
|
||||
ExtrusionEntityCollection::append(const ExtrusionEntitiesPtr &entities)
|
||||
{
|
||||
for (ExtrusionEntitiesPtr::const_iterator ptr = entities.begin(); ptr != entities.end(); ++ptr)
|
||||
this->append(**ptr);
|
||||
}
|
||||
|
||||
void
|
||||
ExtrusionEntityCollection::append(const ExtrusionPaths &paths)
|
||||
{
|
||||
for (ExtrusionPaths::const_iterator path = paths.begin(); path != paths.end(); ++path)
|
||||
this->append(*path);
|
||||
}
|
||||
|
||||
void
|
||||
ExtrusionEntityCollection::replace(size_t i, const ExtrusionEntity &entity)
|
||||
{
|
||||
|
@ -16,12 +16,12 @@ public:
|
||||
ExtrusionEntityCollection(): no_sort(false) {};
|
||||
ExtrusionEntityCollection(const ExtrusionEntityCollection &other) : orig_indices(other.orig_indices), no_sort(other.no_sort) { this->append(other.entities); }
|
||||
ExtrusionEntityCollection(ExtrusionEntityCollection &&other) : entities(std::move(other.entities)), orig_indices(std::move(other.orig_indices)), no_sort(other.no_sort) {}
|
||||
ExtrusionEntityCollection(const ExtrusionPaths &paths);
|
||||
explicit ExtrusionEntityCollection(const ExtrusionPaths &paths);
|
||||
ExtrusionEntityCollection& operator=(const ExtrusionEntityCollection &other);
|
||||
ExtrusionEntityCollection& operator=(ExtrusionEntityCollection &&other)
|
||||
{ this->entities = std::move(other.entities); this->orig_indices = std::move(other.orig_indices); this->no_sort = other.no_sort; return *this; }
|
||||
~ExtrusionEntityCollection() { clear(); }
|
||||
operator ExtrusionPaths() const;
|
||||
explicit operator ExtrusionPaths() const;
|
||||
|
||||
bool is_collection() const { return true; };
|
||||
bool can_reverse() const { return !this->no_sort; };
|
||||
@ -29,8 +29,24 @@ public:
|
||||
void clear();
|
||||
void swap (ExtrusionEntityCollection &c);
|
||||
void append(const ExtrusionEntity &entity) { this->entities.push_back(entity.clone()); }
|
||||
void append(const ExtrusionEntitiesPtr &entities);
|
||||
void append(const ExtrusionPaths &paths);
|
||||
void append(const ExtrusionEntitiesPtr &entities) {
|
||||
this->entities.reserve(this->entities.size() + entities.size());
|
||||
for (ExtrusionEntitiesPtr::const_iterator ptr = entities.begin(); ptr != entities.end(); ++ptr)
|
||||
this->entities.push_back((*ptr)->clone());
|
||||
}
|
||||
void append(ExtrusionEntitiesPtr &&src) {
|
||||
if (entities.empty())
|
||||
entities = std::move(src);
|
||||
else {
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(entities));
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
void append(const ExtrusionPaths &paths) {
|
||||
this->entities.reserve(this->entities.size() + paths.size());
|
||||
for (ExtrusionPaths::const_iterator path = paths.begin(); path != paths.end(); ++path)
|
||||
this->entities.push_back(path->clone());
|
||||
}
|
||||
void replace(size_t i, const ExtrusionEntity &entity);
|
||||
void remove(size_t i);
|
||||
ExtrusionEntityCollection chained_path(bool no_reverse = false, std::vector<size_t>* orig_indices = NULL) const;
|
||||
|
@ -47,10 +47,12 @@ class MultiPoint
|
||||
void append(const Points::const_iterator &begin, const Points::const_iterator &end) { this->points.insert(this->points.end(), begin, end); }
|
||||
void append(Points &&src)
|
||||
{
|
||||
if (this->points.empty())
|
||||
if (this->points.empty()) {
|
||||
this->points = std::move(src);
|
||||
else
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(this->points));
|
||||
} else {
|
||||
this->points.insert(this->points.end(), src.begin(), src.end());
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool intersection(const Line& line, Point* intersection) const;
|
||||
|
@ -374,7 +374,7 @@ PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops,
|
||||
// reapply the nearest point search for starting point
|
||||
// We allow polyline reversal because Clipper may have randomly
|
||||
// reversed polylines during clipping.
|
||||
paths = ExtrusionEntityCollection(paths).chained_path();
|
||||
paths = (ExtrusionPaths)ExtrusionEntityCollection(paths).chained_path();
|
||||
} else {
|
||||
ExtrusionPath path(role);
|
||||
path.polyline = loop->polygon.split_at_first_point();
|
||||
|
@ -69,15 +69,16 @@ extern bool remove_small(Polygons &polys, double min_area);
|
||||
|
||||
// Append a vector of polygons at the end of another vector of polygons.
|
||||
inline void polygons_append(Polygons &dst, const Polygons &src) { dst.insert(dst.end(), src.begin(), src.end()); }
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
|
||||
inline void polygons_append(Polygons &dst, Polygons &&src)
|
||||
{
|
||||
if (dst.empty())
|
||||
if (dst.empty()) {
|
||||
dst = std::move(src);
|
||||
else
|
||||
} else {
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void polygons_rotate(Polygons &polys, double angle)
|
||||
{
|
||||
|
@ -27,10 +27,12 @@ public:
|
||||
void append(const Points::const_iterator &begin, const Points::const_iterator &end) { this->points.insert(this->points.end(), begin, end); }
|
||||
void append(Points &&src)
|
||||
{
|
||||
if (this->points.empty())
|
||||
if (this->points.empty()) {
|
||||
this->points = std::move(src);
|
||||
else
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(this->points));
|
||||
} else {
|
||||
this->points.insert(this->points.end(), src.begin(), src.end());
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
void append(const Polyline &src)
|
||||
{
|
||||
@ -39,10 +41,12 @@ public:
|
||||
|
||||
void append(Polyline &&src)
|
||||
{
|
||||
if (this->points.empty())
|
||||
if (this->points.empty()) {
|
||||
this->points = std::move(src.points);
|
||||
else
|
||||
std::move(std::begin(src.points), std::end(src.points), std::back_inserter(this->points));
|
||||
} else {
|
||||
this->points.insert(this->points.end(), src.points.begin(), src.points.end());
|
||||
src.points.clear();
|
||||
}
|
||||
}
|
||||
|
||||
operator Polylines() const;
|
||||
@ -99,10 +103,12 @@ inline void polylines_append(Polylines &dst, const Polylines &src)
|
||||
|
||||
inline void polylines_append(Polylines &dst, Polylines &&src)
|
||||
{
|
||||
if (dst.empty())
|
||||
if (dst.empty()) {
|
||||
dst = std::move(src);
|
||||
else
|
||||
} else {
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
|
||||
class ThickPolyline : public Polyline {
|
||||
|
@ -143,16 +143,15 @@ inline void polygons_append(Polygons &dst, const Surfaces &src)
|
||||
}
|
||||
}
|
||||
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
inline void polygons_append(Polygons &dst, Surfaces &&src)
|
||||
{
|
||||
dst.reserve(dst.size() + number_polygons(src));
|
||||
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
||||
for (Surfaces::iterator it = src.begin(); it != src.end(); ++ it) {
|
||||
dst.push_back(std::move(it->expolygon.contour));
|
||||
std::move(std::begin(it->expolygon.holes), std::end(it->expolygon.holes), std::back_inserter(dst));
|
||||
it->expolygon.holes.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Append a vector of Surfaces at the end of another vector of polygons.
|
||||
inline void polygons_append(Polygons &dst, const SurfacesPtr &src)
|
||||
@ -164,16 +163,15 @@ inline void polygons_append(Polygons &dst, const SurfacesPtr &src)
|
||||
}
|
||||
}
|
||||
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
inline void polygons_append(Polygons &dst, SurfacesPtr &&src)
|
||||
{
|
||||
dst.reserve(dst.size() + number_polygons(src));
|
||||
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
||||
dst.push_back(std::move((*it)->expolygon.contour));
|
||||
std::move(std::begin((*it)->expolygon.holes), std::end((*it)->expolygon.holes), std::back_inserter(dst));
|
||||
(*it)->expolygon.holes.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Append a vector of Surfaces at the end of another vector of polygons.
|
||||
inline void surfaces_append(Surfaces &dst, const ExPolygons &src, SurfaceType surfaceType)
|
||||
@ -193,27 +191,30 @@ inline void surfaces_append(Surfaces &dst, const Surfaces &src)
|
||||
dst.insert(dst.end(), src.begin(), src.end());
|
||||
}
|
||||
|
||||
#if SLIC3R_CPPVER >= 11
|
||||
inline void surfaces_append(Surfaces &dst, ExPolygons &&src, SurfaceType surfaceType)
|
||||
{
|
||||
dst.reserve(dst.size() + src.size());
|
||||
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it)
|
||||
dst.push_back(Surface(surfaceType, std::move(*it)));
|
||||
src.clear();
|
||||
}
|
||||
|
||||
inline void surfaces_append(Surfaces &dst, ExPolygons &&src, const Surface &surfaceTempl)
|
||||
{
|
||||
dst.reserve(dst.size() + number_polygons(src));
|
||||
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it)
|
||||
dst.push_back(Surface(surfaceTempl, std::move(*it)));
|
||||
src.clear();
|
||||
}
|
||||
inline void surfaces_append(Surfaces &dst, Surfaces &&src)
|
||||
{
|
||||
if (dst.empty())
|
||||
if (dst.empty()) {
|
||||
dst = std::move(src);
|
||||
else
|
||||
} else {
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
||||
src.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern BoundingBox get_extents(const Surface &surface);
|
||||
extern BoundingBox get_extents(const Surfaces &surfaces);
|
||||
|
Loading…
Reference in New Issue
Block a user