Return a reference to the actual item instead of a clone when accessing contents of a SurfaceCollection

This commit is contained in:
Alessandro Ranellucci 2013-07-15 13:50:53 +02:00
parent f612d4c64e
commit e485f0b130
3 changed files with 12 additions and 3 deletions

View File

@ -23,6 +23,7 @@ class Surface
unsigned short thickness_layers; // in layers unsigned short thickness_layers; // in layers
double bridge_angle; double bridge_angle;
unsigned short extra_perimeters; unsigned short extra_perimeters;
bool in_collection;
}; };
} }

View File

@ -6,8 +6,6 @@
%} %}
%name{Slic3r::Surface} class Surface { %name{Slic3r::Surface} class Surface {
%name{_clone} Surface(Surface& self);
~Surface();
ExPolygon* expolygon() ExPolygon* expolygon()
%code{% const char* CLASS = "Slic3r::ExPolygon::XS"; RETVAL = new ExPolygon(THIS->expolygon); %}; %code{% const char* CLASS = "Slic3r::ExPolygon::XS"; RETVAL = new ExPolygon(THIS->expolygon); %};
double thickness() double thickness()
@ -36,6 +34,14 @@ _new(CLASS, expolygon, surface_type, thickness, thickness_layers, bridge_angle,
OUTPUT: OUTPUT:
RETVAL RETVAL
void
Surface::DESTROY()
CODE:
if (!THIS->in_collection) {
delete THIS;
THIS = NULL;
}
SurfaceType SurfaceType
Surface::surface_type(...) Surface::surface_type(...)
CODE: CODE:

View File

@ -19,6 +19,7 @@ SurfaceCollection::new(...)
RETVAL->surfaces.resize(items-1); RETVAL->surfaces.resize(items-1);
for (unsigned int i = 1; i < items; i++) { for (unsigned int i = 1; i < items; i++) {
RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) )); RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) ));
RETVAL->surfaces[i-1].in_collection = true;
} }
OUTPUT: OUTPUT:
RETVAL RETVAL
@ -31,7 +32,7 @@ SurfaceCollection::arrayref()
int i = 0; int i = 0;
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) { for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Surface", new Surface(*it) ); sv_setref_pv( sv, "Slic3r::Surface", &*it );
av_store(av, i++, sv); av_store(av, i++, sv);
} }
RETVAL = newRV_noinc((SV*)av); RETVAL = newRV_noinc((SV*)av);
@ -43,6 +44,7 @@ SurfaceCollection::append(...)
CODE: CODE:
for (unsigned int i = 1; i < items; i++) { for (unsigned int i = 1; i < items; i++) {
THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) ))); THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) )));
THIS->surfaces.back().in_collection = true;
} }
%} %}