PrusaSlicer-NonPlainar/xs/xsp/PolylineCollection.xsp
Petr Ledvina 115aa6885f 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.
2014-04-27 19:38:56 +02:00

80 lines
2.2 KiB
Plaintext

%module{Slic3r::XS};
%{
#include <myinit.h>
#include "PolylineCollection.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Polyline::Collection} class PolylineCollection {
~PolylineCollection();
Clone<PolylineCollection> clone()
%code{% RETVAL = THIS; %};
void clear()
%code{% THIS->polylines.clear(); %};
PolylineCollection* chained_path(bool no_reverse)
%code{%
RETVAL = new PolylineCollection();
THIS->chained_path(RETVAL, no_reverse);
%};
PolylineCollection* chained_path_from(Point* start_near, bool no_reverse)
%code{%
RETVAL = new PolylineCollection();
THIS->chained_path_from(*start_near, RETVAL, no_reverse);
%};
int count()
%code{% RETVAL = THIS->polylines.size(); %};
Clone<Point> leftmost_point();
%{
PolylineCollection*
PolylineCollection::new(...)
CODE:
RETVAL = new PolylineCollection ();
// ST(0) is class name, others are Polylines
RETVAL->polylines.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
// Note: a COPY of the input is stored
RETVAL->polylines[i-1].from_SV_check(ST(i));
}
OUTPUT:
RETVAL
SV*
PolylineCollection::arrayref()
CODE:
AV* av = newAV();
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());
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
RETVAL
SV*
PolylineCollection::pp()
CODE:
AV* av = newAV();
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_pureperl());
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
RETVAL
void
PolylineCollection::append(...)
CODE:
for (unsigned int i = 1; i < items; i++) {
Polyline polyline;
polyline.from_SV_check( ST(i) );
THIS->polylines.push_back(polyline);
}
%}
};