Skip to content

Commit

Permalink
Merge pull request #10 from flannelhead/cpp11-fix
Browse files Browse the repository at this point in the history
Fix compilation with C++11 and above
  • Loading branch information
bubnikv authored Nov 3, 2016
2 parents 7b6b609 + fad91b8 commit f278fa4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
6 changes: 3 additions & 3 deletions xs/src/libslic3r/ExPolygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ inline void polygons_append(Polygons &dst, const ExPolygons &src)
}

#if SLIC3R_CPPVER >= 11
inline void polygons_append(Polygons &dst, ExPolygons &&src)
inline void polygons_append(Polygons &dst, ExPolygons &&src)
{
dst.reserve(dst.size() + number_polygons(src));
for (ExPolygons::const_iterator it = expolys.begin(); it != expolys.end(); ++ it) {
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it) {
dst.push_back(std::move(it->contour));
std::move(std::begin(it->contour), std::end(it->contour), std::back_inserter(dst));
std::move(std::begin(it->holes), std::end(it->holes), std::back_inserter(dst));
}
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions xs/src/libslic3r/Fill/Fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ void make_fill(LayerRegion &layerm, ExtrusionEntityCollection &out)
continue;

// get filler object
#if SLIC3R_CPPVER >= 11
std::unique_ptr<Fill> f = std::unique_ptr<Fill>(Fill::new_from_type(fill_pattern));
#else
std::auto_ptr<Fill> f = std::auto_ptr<Fill>(Fill::new_from_type(fill_pattern));
#endif
f->set_bounding_box(layerm.layer()->object()->bounding_box());

// calculate the actual flow we'll be using for this infill
Expand Down
52 changes: 32 additions & 20 deletions xs/src/libslic3r/PolylineCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ inline int nearest_point_index(const std::vector<Chaining> &pairs, const Point &
return idx;
}

Polylines PolylineCollection::chained_path_from(
#if SLIC3R_CPPVER >= 11
Polylines &&src,
#else
Polylines PolylineCollection::_chained_path_from(
const Polylines &src,
Point start_near,
bool no_reverse
#if SLIC3R_CPPVER >= 11
, bool move_from_src
#endif
Point start_near,
bool no_reverse)
)
{
std::vector<Chaining> endpoints;
endpoints.reserve(src.size());
Expand All @@ -70,8 +70,12 @@ Polylines PolylineCollection::chained_path_from(
// find nearest point
int endpoint_index = nearest_point_index<double>(endpoints, start_near, no_reverse);
assert(endpoint_index >= 0 && endpoint_index < endpoints.size() * 2);
#if SLIC3R_CPPVER >= 11
retval.push_back(std::move(src[endpoints[endpoint_index/2].idx]));
#if SLIC3R_CPPVER > 11
if (move_from_src) {
retval.push_back(std::move(src[endpoints[endpoint_index/2].idx]));
} else {
retval.push_back(src[endpoints[endpoint_index/2].idx]);
}
#else
retval.push_back(src[endpoints[endpoint_index/2].idx]);
#endif
Expand All @@ -86,28 +90,36 @@ Polylines PolylineCollection::chained_path_from(
#if SLIC3R_CPPVER >= 11
Polylines PolylineCollection::chained_path(Polylines &&src, bool no_reverse)
{
return (src.empty() || src.front().empty()) ?
return (src.empty() || src.front().points.empty()) ?
Polylines() :
chained_path_from(std::move(src), src.front().first_point(), no_reverse);
}
Polylines PolylineCollection::chained_path_from(Polylines src, Point start_near, bool no_reverse)
{
return chained_path_from(std::move(src), start_near, no_reverse);
_chained_path_from(src, src.front().first_point(), no_reverse, true);
}
Polylines PolylineCollection::chained_path(Polylines src, bool no_reverse)

Polylines PolylineCollection::chained_path_from(Polylines &&src, Point start_near, bool no_reverse)
{
return (src.empty() || src.front().empty()) ?
Polylines() :
chained_path_from(std::move(src), src.front().first_point(), no_reverse);
return _chained_path_from(src, start_near, no_reverse, true);
}
#else
#endif

Polylines PolylineCollection::chained_path(const Polylines &src, bool no_reverse)
{
return (src.empty() || src.front().points.empty()) ?
Polylines() :
chained_path_from(src, src.front().first_point(), no_reverse);
_chained_path_from(src, src.front().first_point(), no_reverse
#if SLIC3R_CPPVER >= 11
, false
#endif
);
}

Polylines PolylineCollection::chained_path_from(const Polylines &src, Point start_near, bool no_reverse)
{
return _chained_path_from(src, start_near, no_reverse
#if SLIC3R_CPPVER >= 11
, false
#endif
);
}

Point PolylineCollection::leftmost_point(const Polylines &polylines)
{
Expand Down
18 changes: 12 additions & 6 deletions xs/src/libslic3r/PolylineCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ namespace Slic3r {

class PolylineCollection
{
static Polylines _chained_path_from(
const Polylines &src,
Point start_near,
bool no_reverse
#if SLIC3R_CPPVER >= 11
, bool move_from_src
#endif
);

public:
Polylines polylines;
void chained_path(PolylineCollection* retval, bool no_reverse = false) const
{ retval->polylines = chained_path(this->polylines, no_reverse); }
void chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse = false) const
void chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse = false) const
{ retval->polylines = chained_path_from(this->polylines, start_near, no_reverse); }
Point leftmost_point() const
{ return leftmost_point(polylines); }
Expand All @@ -22,12 +31,9 @@ class PolylineCollection
#if SLIC3R_CPPVER >= 11
static Polylines chained_path(Polylines &&src, bool no_reverse = false);
static Polylines chained_path_from(Polylines &&src, Point start_near, bool no_reverse = false);
static Polylines chained_path(Polylines src, bool no_reverse = false);
static Polylines chained_path_from(Polylines src, Point start_near, bool no_reverse = false);
#else
static Polylines chained_path(const Polylines &src, bool no_reverse = false);
static Polylines chained_path_from(const Polylines &src, Point start_near, bool no_reverse = false);
#endif
static Polylines chained_path(const Polylines &src, bool no_reverse = false);
static Polylines chained_path_from(const Polylines &src, Point start_near, bool no_reverse = false);
};

}
Expand Down
5 changes: 5 additions & 0 deletions xs/src/libslic3r/SupportMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,13 @@ void PrintObjectSupportMaterial::generate_toolpaths(
infill_pattern = ipHoneycomb;
break;
}
#if SLIC3R_CPPVER >= 11
std::unique_ptr<Fill> filler_interface = std::unique_ptr<Fill>(Fill::new_from_type(ipRectilinear));
std::unique_ptr<Fill> filler_support = std::unique_ptr<Fill>(Fill::new_from_type(infill_pattern));
#else
std::auto_ptr<Fill> filler_interface = std::auto_ptr<Fill>(Fill::new_from_type(ipRectilinear));
std::auto_ptr<Fill> filler_support = std::auto_ptr<Fill>(Fill::new_from_type(infill_pattern));
#endif
{
BoundingBox bbox_object = object.bounding_box();
filler_interface->set_bounding_box(bbox_object);
Expand Down
7 changes: 4 additions & 3 deletions xs/src/libslic3r/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ inline Polygons to_polygons(const SurfacesPtr &src)
#if SLIC3R_CPPVER >= 11
inline Polygons to_polygons(SurfacesPtr &&src)
{
size_t num = 0;
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++it)
num += (*it)->expolygon.holes.size() + 1;
Polygons polygons;
polygons.reserve(num);
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) {
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++it) {
polygons.push_back(std::move((*it)->expolygon.contour));
for (Polygons::const_iterator ith = (*it)->expolygon.holes.begin(); ith != (*it)->expolygon.holes.end(); ++ith) {
polygons.push_back(std::move(*ith));
Expand Down Expand Up @@ -146,7 +147,7 @@ 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) {
dst.push_back(std::move(it->expolygon.contour));
std::move(std::begin(it->expolygon.contour), std::end(it->expolygon.contour), std::back_inserter(dst));
std::move(std::begin(it->expolygon.holes), std::end(it->expolygon.holes), std::back_inserter(dst));
}
}
#endif
Expand All @@ -167,7 +168,7 @@ 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.contour), std::end((*it)->expolygon.contour), std::back_inserter(dst));
std::move(std::begin((*it)->expolygon.holes), std::end((*it)->expolygon.holes), std::back_inserter(dst));
}
}
#endif
Expand Down

0 comments on commit f278fa4

Please sign in to comment.