mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-05-18 09:29:05 -07:00
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:
@@ -1,7 +1,10 @@
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include "Point.hpp"
|
||||
#include "Line.hpp"
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
#endif
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
@@ -139,17 +142,20 @@ Point::ccw(const Line &line) const
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
|
||||
REGISTER_CLASS(Point, "Point");
|
||||
|
||||
SV*
|
||||
Point::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Point::Ref", (void*)this );
|
||||
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, "Slic3r::Point", new Point(*this) );
|
||||
sv_setref_pv( sv, perl_class_name(this), new Point(*this) );
|
||||
return sv;
|
||||
}
|
||||
|
||||
@@ -176,14 +182,34 @@ void
|
||||
Point::from_SV_check(SV* point_sv)
|
||||
{
|
||||
if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) {
|
||||
if (!sv_isa(point_sv, "Slic3r::Point") && !sv_isa(point_sv, "Slic3r::Point::Ref"))
|
||||
CONFESS("Not a valid Slic3r::Point object");
|
||||
if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this)))
|
||||
CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv))));
|
||||
*this = *(Point*)SvIV((SV*)SvRV( point_sv ));
|
||||
} else {
|
||||
this->from_SV(point_sv);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
Pointf::scale(double factor)
|
||||
{
|
||||
this->x *= factor;
|
||||
this->y *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::translate(double x, double y)
|
||||
{
|
||||
this->x += x;
|
||||
this->y += y;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
|
||||
REGISTER_CLASS(Pointf, "Pointf");
|
||||
|
||||
SV*
|
||||
Pointf::to_SV_pureperl() const {
|
||||
AV* av = newAV();
|
||||
@@ -207,20 +233,6 @@ Pointf::from_SV(SV* point_sv)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
Pointf::scale(double factor)
|
||||
{
|
||||
this->x *= factor;
|
||||
this->y *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::translate(double x, double y)
|
||||
{
|
||||
this->x += x;
|
||||
this->y += y;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf3::scale(double factor)
|
||||
{
|
||||
@@ -235,4 +247,8 @@ Pointf3::translate(double x, double y, double z)
|
||||
this->z += z;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(Pointf3, "Pointf3");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user