Replace to_SV_ref() and to_SV_clone_ref() with templated glue functions

This commit is contained in:
Alessandro Ranellucci 2014-05-08 14:52:48 +02:00
parent f76e2c2222
commit 76a8ec3d9e
54 changed files with 39 additions and 254 deletions

View file

@ -1,8 +1,5 @@
#include "BoundingBox.hpp"
#include <algorithm>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -592,9 +592,9 @@ polynode2perl(const ClipperLib::PolyNode& node)
Slic3r::Polygon p;
ClipperPath_to_Slic3rMultiPoint(node.Contour, p);
if (node.IsHole()) {
(void)hv_stores( hv, "hole", p.to_SV_clone_ref() );
(void)hv_stores( hv, "hole", Slic3r::perl_to_SV_clone_ref(p) );
} else {
(void)hv_stores( hv, "outer", p.to_SV_clone_ref() );
(void)hv_stores( hv, "outer", Slic3r::perl_to_SV_clone_ref(p) );
}
(void)hv_stores( hv, "children", polynode_children_2_perl(node) );
return (SV*)newRV_noinc((SV*)hv);

View file

@ -6,9 +6,6 @@
#include "ClipperUtils.hpp"
#include "polypartition.h"
#include "poly2tri/poly2tri.h"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
#include <algorithm>
#include <list>
@ -367,28 +364,14 @@ ExPolygon::to_AV() {
AV* av = newAV();
av_extend(av, num_holes); // -1 +1
av_store(av, 0, this->contour.to_SV_ref());
av_store(av, 0, perl_to_SV_ref(this->contour));
for (unsigned int i = 0; i < num_holes; i++) {
av_store(av, i+1, this->holes[i].to_SV_ref());
av_store(av, i+1, perl_to_SV_ref(this->holes[i]));
}
return newRV_noinc((SV*)av);
}
SV*
ExPolygon::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
SV*
ExPolygon::to_SV_clone_ref() const {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new ExPolygon(*this) );
return sv;
}
SV*
ExPolygon::to_SV_pureperl() const
{

View file

@ -39,8 +39,6 @@ class ExPolygon
void from_SV(SV* poly_sv);
void from_SV_check(SV* poly_sv);
SV* to_AV();
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
SV* to_SV_pureperl() const;
#endif
};

View file

@ -1,8 +1,5 @@
#include "ExPolygonCollection.hpp"
#include "Geometry.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -1,7 +1,4 @@
#include "Extruder.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -4,9 +4,6 @@
#include "ClipperUtils.hpp"
#include "Extruder.hpp"
#include <sstream>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -106,20 +103,6 @@ ExtrusionPath::_inflate_collection(const Polylines &polylines, ExtrusionEntityCo
}
#ifdef SLIC3RXS
SV*
ExtrusionPath::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
SV*
ExtrusionPath::to_SV_clone_ref() const {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new ExtrusionPath(*this) );
return sv;
}
REGISTER_CLASS(ExtrusionPath, "ExtrusionPath");
#endif

View file

@ -64,11 +64,6 @@ class ExtrusionPath : public ExtrusionEntity
double xofs, double yofs, std::string extrusion_axis,
std::string gcode_line_suffix) const;
#ifdef SLIC3RXS
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
#endif
private:
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
};

View file

@ -1,9 +1,6 @@
#include "ExtrusionEntityCollection.hpp"
#include <algorithm>
#include <map>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -1,8 +1,5 @@
#include "Flow.hpp"
#include <cmath>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -4,9 +4,6 @@
#include <algorithm>
#include <cmath>
#include <sstream>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -157,31 +154,12 @@ Line::to_AV() {
AV* av = newAV();
av_extend(av, 1);
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(&this->a), &(this->a) );
av_store(av, 0, sv);
sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(&this->b), &(this->b) );
av_store(av, 1, sv);
av_store(av, 0, perl_to_SV_ref(this->a));
av_store(av, 1, perl_to_SV_ref(this->b));
return newRV_noinc((SV*)av);
}
SV*
Line::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
SV*
Line::to_SV_clone_ref() const {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new Line(*this) );
return sv;
}
SV*
Line::to_SV_pureperl() const {
AV* av = newAV();

View file

@ -38,8 +38,6 @@ class Line
void from_SV(SV* line_sv);
void from_SV_check(SV* line_sv);
SV* to_AV();
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
SV* to_SV_pureperl() const;
#endif
};

View file

@ -1,8 +1,4 @@
#include "Model.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -301,13 +297,6 @@ ModelObject::invalidate_bounding_box()
#ifdef SLIC3RXS
REGISTER_CLASS(ModelObject, "Model::Object");
SV*
ModelObject::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
#endif
@ -322,13 +311,6 @@ ModelVolume::ModelVolume(ModelObject* object, const t_model_material_id &materia
#ifdef SLIC3RXS
REGISTER_CLASS(ModelVolume, "Model::Volume");
SV*
ModelVolume::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
#endif
@ -343,13 +325,6 @@ ModelInstance::ModelInstance(ModelObject *object, double rotation,
#ifdef SLIC3RXS
REGISTER_CLASS(ModelInstance, "Model::Instance");
SV*
ModelInstance::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
#endif
}

View file

@ -85,6 +85,10 @@ class ModelObject
t_layer_height_ranges layer_height_ranges;
Pointf origin_translation;
// these should be private but we need to expose them via XS until all methods are ported
BoundingBoxf3 _bounding_box;
bool _bounding_box_valid;
ModelObject(Model *model, const std::string &input_file, const DynamicPrintConfig &config,
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
ModelObject(const ModelObject &other);
@ -115,14 +119,7 @@ class ModelObject
size_t facets_count() const;
bool needed_repair() const;
#ifdef SLIC3RXS
SV* to_SV_ref();
#endif
private:
BoundingBoxf3 _bounding_box;
bool _bounding_box_valid;
void update_bounding_box();
};
@ -136,10 +133,6 @@ class ModelVolume
ModelVolume(ModelObject *object, const t_model_material_id &material_id,
const TriangleMesh &mesh, bool modifier);
#ifdef SLIC3RXS
SV* to_SV_ref();
#endif
};
class ModelInstance
@ -155,10 +148,6 @@ class ModelInstance
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
void transform_polygon(Polygon* polygon) const;
#ifdef SLIC3RXS
SV* to_SV_ref();
#endif
};
}

View file

@ -129,7 +129,7 @@ MultiPoint::to_AV() {
AV* av = newAV();
av_extend(av, num_points-1);
for (unsigned int i = 0; i < num_points; i++) {
av_store(av, i, this->points[i].to_SV_ref());
av_store(av, i, perl_to_SV_ref(this->points[i]));
}
return newRV_noinc((SV*)av);
}

View file

@ -1,6 +1,7 @@
#ifndef slic3r_MultiPoint_hpp_
#define slic3r_MultiPoint_hpp_
#include <myinit.h>
#include "Line.hpp"
#include "Point.hpp"
#include <algorithm>

View file

@ -2,9 +2,6 @@
#include "Line.hpp"
#include <cmath>
#include <sstream>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -145,20 +142,6 @@ Point::ccw(const Line &line) const
REGISTER_CLASS(Point, "Point");
SV*
Point::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv;
}
SV*
Point::to_SV_clone_ref() const {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new Point(*this) );
return sv;
}
SV*
Point::to_SV_pureperl() const {
AV* av = newAV();

View file

@ -41,8 +41,6 @@ class Point
#ifdef SLIC3RXS
void from_SV(SV* point_sv);
void from_SV_check(SV* point_sv);
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
SV* to_SV_pureperl() const;
#endif
};

View file

@ -2,9 +2,6 @@
#include "ClipperUtils.hpp"
#include "Polygon.hpp"
#include "Polyline.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -195,23 +192,8 @@ Polygon::triangulate_convex(Polygons* polygons) const
}
#ifdef SLIC3RXS
REGISTER_CLASS(Polygon, "Polygon");
SV*
Polygon::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv;
}
SV*
Polygon::to_SV_clone_ref() const {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new Polygon(*this) );
return sv;
}
void
Polygon::from_SV_check(SV* poly_sv)
{

View file

@ -38,8 +38,6 @@ class Polygon : public MultiPoint {
#ifdef SLIC3RXS
void from_SV_check(SV* poly_sv);
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
#endif
};

View file

@ -1,8 +1,5 @@
#include "Polyline.hpp"
#include "Polygon.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -122,25 +119,8 @@ Polyline::simplify(double tolerance)
#ifdef SLIC3RXS
REGISTER_CLASS(Polyline, "Polyline");
SV*
Polyline::to_SV_ref()
{
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv;
}
SV*
Polyline::to_SV_clone_ref() const
{
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new Polyline(*this) );
return sv;
}
void
Polyline::from_SV_check(SV* poly_sv)
{

View file

@ -24,8 +24,6 @@ class Polyline : public MultiPoint {
#ifdef SLIC3RXS
void from_SV_check(SV* poly_sv);
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
#endif
};

View file

@ -1,7 +1,4 @@
#include "PolylineCollection.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -1,7 +1,4 @@
#include "Print.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -1,6 +1,7 @@
#ifndef slic3r_Print_hpp_
#define slic3r_Print_hpp_
#include <myinit.h>
#include <set>
namespace Slic3r {

View file

@ -1,7 +1,4 @@
#include "PrintConfig.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -1,7 +1,4 @@
#include "Surface.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
@ -54,20 +51,6 @@ Surface::from_SV_check(SV* surface_sv)
// a XS Surface was supplied
*this = *(Surface *)SvIV((SV*)SvRV( surface_sv ));
}
SV*
Surface::to_SV_ref() {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv;
}
SV*
Surface::to_SV_clone_ref() const {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(this), new Surface(*this) );
return sv;
}
#endif
}

View file

@ -24,8 +24,6 @@ class Surface
#ifdef SLIC3RXS
void from_SV_check(SV* surface_sv);
SV* to_SV_ref();
SV* to_SV_clone_ref() const;
#endif
};

View file

@ -1,8 +1,5 @@
#include "SurfaceCollection.hpp"
#include <map>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {

View file

@ -11,9 +11,6 @@
#include <algorithm>
#include <math.h>
#include <assert.h>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
#ifdef SLIC3R_DEBUG
#include "SVG.hpp"

View file

@ -17,6 +17,7 @@ extern "C" {
#undef do_open
#undef do_close
}
#include "perlglue.hpp"
#endif
#define EPSILON 1e-4

View file

@ -23,7 +23,21 @@ template<class T>
const char* perl_class_name(const T*) { return ClassTraits<T>::name; }
template<class T>
const char* perl_class_name_ref(const T*) { return ClassTraits<T>::name_ref; }
template<class T>
SV* perl_to_SV_ref(T &t) {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name_ref(&t), &t );
return sv;
}
template<class T>
SV* perl_to_SV_clone_ref(const T &t) {
SV* sv = newSV(0);
sv_setref_pv( sv, perl_class_name(&t), new T(t) );
return sv;
}
template <class T>
class Ref {
T* val;