Merge pull request #10 from flannelhead/cpp11-fix

Fix compilation with C++11 and above
This commit is contained in:
bubnikv 2016-11-03 19:10:45 +00:00 committed by GitHub
commit f278fa454e
6 changed files with 61 additions and 33 deletions

View file

@ -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

View file

@ -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

View file

@ -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());
@ -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
@ -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);
_chained_path_from(src, src.front().first_point(), no_reverse, true);
}
Polylines PolylineCollection::chained_path_from(Polylines src, Point start_near, bool 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);
return _chained_path_from(src, start_near, no_reverse, true);
}
Polylines PolylineCollection::chained_path(Polylines src, bool no_reverse)
{
return (src.empty() || src.front().empty()) ?
Polylines() :
chained_path_from(std::move(src), src.front().first_point(), no_reverse);
}
#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)
{

View file

@ -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); }
@ -22,12 +31,9 @@ public:
#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);
};
}

View file

@ -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);

View file

@ -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));
@ -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
@ -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