Return objects by reference instead of always cloning

This commit is contained in:
Alessandro Ranellucci 2013-09-02 20:22:20 +02:00
parent 1741301973
commit c0789506e4
30 changed files with 158 additions and 54 deletions

View file

@ -14,9 +14,9 @@
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
Polygon* contour()
%code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(THIS->contour); %};
Polygons holes()
%code{% RETVAL = THIS->holes; %};
%code{% const char* CLASS = "Slic3r::Polygon::Ref"; RETVAL = &(THIS->contour); %};
Polygons* holes()
%code{% RETVAL = &(THIS->holes); %};
void scale(double factor);
void translate(double x, double y);
double area();

View file

@ -17,9 +17,9 @@
Lines lines()
%code{% RETVAL = THIS->polyline.lines(); %};
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = THIS->first_point(); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->last_point())); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = THIS->last_point(); %};
%{
ExtrusionPath*

View file

@ -14,9 +14,9 @@
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
Point* a()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->a); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = &(THIS->a); %};
Point* b()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->b); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = &(THIS->b); %};
void reverse();
void scale(double factor);
void translate(double x, double y);

View file

@ -30,7 +30,7 @@
bool make_clockwise();
bool is_valid();
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = THIS->first_point(); %};
%{
Polygon*

View file

@ -20,9 +20,9 @@
void reverse();
Lines lines();
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = THIS->first_point(); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->last_point())); %};
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = THIS->last_point(); %};
%{
Polyline*

View file

@ -23,6 +23,8 @@ Lines T_ARRAYREF
Polygons T_ARRAYREF
ExPolygons T_ARRAYREF
Polygons* T_ARRAYREF_POLYGONS_PTR
INPUT
T_ARRAYREF
@ -49,6 +51,15 @@ T_ARRAYREF
av_extend(av, $var.size()-1);
int i = 0;
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
av_store(av, i++, (*it).to_SV_ref());
av_store(av, i++, (*it).to_SV_clone_ref());
}
$var.clear();
T_ARRAYREF_POLYGONS_PTR
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
av_extend(av, $var->size()-1);
int i = 0;
for (Polygons::iterator it = $var->begin(); it != $var->end(); ++it) {
av_store(av, i++, (*it).to_SV_ref());
}

View file

@ -14,6 +14,7 @@
%typemap{Lines};
%typemap{Polygons};
%typemap{ExPolygons};
%typemap{Polygons*};
%typemap{SurfaceType}{parsed}{
%cpp_type{SurfaceType};