Implement type checking for XS objects

Type handling is mainly done using templates.
Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used.
Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type).

Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return.

Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments).
It is overloaded to be able to return type, type* and type&.

Typechecking in ExtrusionEntityCollection updated to check all passed types.
This commit is contained in:
Petr Ledvina 2014-04-27 19:18:53 +02:00
parent e68b6b6f4c
commit 115aa6885f
35 changed files with 426 additions and 173 deletions

View file

@ -17,10 +17,8 @@
void reverse();
Lines lines()
%code{% RETVAL = THIS->polyline.lines(); %};
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
Clone<Point> first_point();
Clone<Point> last_point();
void clip_end(double distance);
void simplify(double tolerance);
double length();
@ -46,10 +44,8 @@ _new(CLASS, polyline_sv, role, mm3_per_mm)
OUTPUT:
RETVAL
Polyline*
Ref<Polyline>
ExtrusionPath::polyline(...)
PREINIT:
const char* CLASS = "Slic3r::Polyline::Ref";
CODE:
if (items > 1) {
THIS->polyline.from_SV_check( ST(1) );
@ -89,8 +85,6 @@ ExtrusionPath::append(...)
ExtrusionEntityCollection*
ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection)
PREINIT:
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE:
RETVAL = new ExtrusionEntityCollection ();
THIS->intersect_expolygons(*collection, RETVAL);
@ -99,8 +93,6 @@ ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection)
ExtrusionEntityCollection*
ExtrusionPath::subtract_expolygons(ExPolygonCollection* collection)
PREINIT:
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE:
RETVAL = new ExtrusionEntityCollection ();
THIS->subtract_expolygons(*collection, RETVAL);