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;

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "BoundingBox.hpp"
#include "Point.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Geometry::BoundingBox} class BoundingBox {

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "clipper.hpp"
#include "ClipperUtils.hpp"
#include "perlglue.hpp"
%}
%package{Slic3r::Geometry::Clipper};

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "PrintConfig.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Config} class DynamicPrintConfig {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "ExPolygon.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::ExPolygon} class ExPolygon {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "ExPolygonCollection.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::ExPolygon::Collection} class ExPolygonCollection {
@ -45,7 +44,7 @@ ExPolygonCollection::arrayref()
av_fill(av, THIS->expolygons.size()-1);
int i = 0;
for (ExPolygons::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
av_store(av, i++, (*it).to_SV_ref());
av_store(av, i++, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "Extruder.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Extruder} class Extruder {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "ExtrusionEntityCollection.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::ExtrusionPath::Collection} class ExtrusionEntityCollection {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "ExtrusionEntity.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::ExtrusionLoop} class ExtrusionLoop {
@ -36,7 +35,7 @@ ExtrusionLoop::arrayref()
av_fill(av, THIS->paths.size()-1);
int i = 0;
for (ExtrusionPaths::iterator it = THIS->paths.begin(); it != THIS->paths.end(); ++it) {
av_store(av, i++, it->to_SV_ref());
av_store(av, i++, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "ExtrusionEntity.hpp"
#include "ExtrusionEntityCollection.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::ExtrusionPath} class ExtrusionPath {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "Flow.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Flow} class Flow {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "Geometry.hpp"
#include "perlglue.hpp"
%}

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "Line.hpp"
#include "Polyline.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Line} class Line {

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "Model.hpp"
#include "PrintConfig.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Model} class Model {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "Point.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Point} class Point {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "Polygon.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Polygon} class Polygon {

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "ClipperUtils.hpp"
#include "Polyline.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Polyline} class Polyline {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "PolylineCollection.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Polyline::Collection} class PolylineCollection {
@ -47,7 +46,7 @@ PolylineCollection::arrayref()
av_fill(av, THIS->polylines.size()-1);
int i = 0;
for (Polylines::iterator it = THIS->polylines.begin(); it != THIS->polylines.end(); ++it) {
av_store(av, i++, (*it).to_SV_ref());
av_store(av, i++, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "Print.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Print::State} class PrintState {

View File

@ -4,7 +4,6 @@
#include <myinit.h>
#include "Surface.hpp"
#include "ClipperUtils.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Surface} class Surface {

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "SurfaceCollection.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Surface::Collection} class SurfaceCollection {
@ -35,7 +34,7 @@ SurfaceCollection::arrayref()
av_fill(av, THIS->surfaces.size()-1);
int i = 0;
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
av_store(av, i++, (*it).to_SV_ref());
av_store(av, i++, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
@ -47,7 +46,7 @@ SurfaceCollection::filter_by_type(surface_type)
CODE:
AV* av = newAV();
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
if ((*it).surface_type == surface_type) av_push(av, (*it).to_SV_ref());
if ((*it).surface_type == surface_type) av_push(av, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
@ -92,7 +91,7 @@ SurfaceCollection::group()
av_fill(innerav, it->size()-1);
size_t j = 0;
for (SurfacesPtr::iterator it_s = it->begin(); it_s != it->end(); ++it_s) {
av_store(innerav, j++, (*it_s)->to_SV_clone_ref());
av_store(innerav, j++, perl_to_SV_clone_ref(**it_s));
}
av_store(av, i++, newRV_noinc((SV*)innerav));
}

View File

@ -3,7 +3,6 @@
%{
#include <myinit.h>
#include "TriangleMesh.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::TriangleMesh} class TriangleMesh {
@ -158,7 +157,7 @@ TriangleMesh::slice(z)
av_extend(expolygons_av, layers[i].size()-1);
unsigned int j = 0;
for (ExPolygons::iterator it = layers[i].begin(); it != layers[i].end(); ++it) {
av_store(expolygons_av, j++, (*it).to_SV_clone_ref());
av_store(expolygons_av, j++, perl_to_SV_clone_ref(*it));
}
av_store(layers_av, i, newRV_noinc((SV*)expolygons_av));
}

View File

@ -237,7 +237,7 @@ T_ARRAYREF
av_extend(av, $var.size()-1);
int i = 0;
for (${type}::const_iterator it = $var.begin(); it != $var.end(); ++it) {
av_store(av, i++, it->to_SV_clone_ref());
av_store(av, i++, perl_to_SV_clone_ref(*it));
}
$var.clear();
@ -248,7 +248,7 @@ T_ARRAYREF_PTR
av_extend(av, $var->size()-1);
int i = 0;
for (${ my $t = $type; $t =~ s/\*$//; \$t }::iterator it = $var->begin(); it != $var->end(); ++it) {
av_store(av, i++, it->to_SV_ref());
av_store(av, i++, perl_to_SV_ref(*it));
}
T_PTR_ARRAYREF_PTR
@ -258,7 +258,7 @@ T_PTR_ARRAYREF_PTR
av_extend(av, $var->size()-1);
int i = 0;
for (${ my $t = $type; $t =~ s/\*$//; \$t }::iterator it = $var->begin(); it != $var->end(); ++it) {
av_store(av, i++, (*it)->to_SV_ref());
av_store(av, i++, perl_to_SV_ref(**it));
}
T_PTR_ARRAYREF