mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 14:44:19 -06: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:
parent
e68b6b6f4c
commit
115aa6885f
35 changed files with 426 additions and 173 deletions
|
@ -3,6 +3,9 @@
|
|||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
#endif
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -115,6 +118,9 @@ Line::vector() const
|
|||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
|
||||
REGISTER_CLASS(Line, "Line");
|
||||
|
||||
void
|
||||
Line::from_SV(SV* line_sv)
|
||||
{
|
||||
|
@ -127,8 +133,8 @@ void
|
|||
Line::from_SV_check(SV* line_sv)
|
||||
{
|
||||
if (sv_isobject(line_sv) && (SvTYPE(SvRV(line_sv)) == SVt_PVMG)) {
|
||||
if (!sv_isa(line_sv, "Slic3r::Line") && !sv_isa(line_sv, "Slic3r::Line::Ref"))
|
||||
CONFESS("Not a valid Slic3r::Line object");
|
||||
if (!sv_isa(line_sv, perl_class_name(this)) && !sv_isa(line_sv, perl_class_name_ref(this)))
|
||||
CONFESS("Not a valid %s object", perl_class_name(this));
|
||||
*this = *(Line*)SvIV((SV*)SvRV( line_sv ));
|
||||
} else {
|
||||
this->from_SV(line_sv);
|
||||
|
@ -141,11 +147,11 @@ Line::to_AV() {
|
|||
av_extend(av, 1);
|
||||
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Point::Ref", &(this->a) );
|
||||
sv_setref_pv( sv, perl_class_name_ref(&this->a), &(this->a) );
|
||||
av_store(av, 0, sv);
|
||||
|
||||
sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Point::Ref", &(this->b) );
|
||||
sv_setref_pv( sv, perl_class_name_ref(&this->b), &(this->b) );
|
||||
av_store(av, 1, sv);
|
||||
|
||||
return newRV_noinc((SV*)av);
|
||||
|
@ -154,14 +160,14 @@ Line::to_AV() {
|
|||
SV*
|
||||
Line::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Line::Ref", this );
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
|
||||
SV*
|
||||
Line::to_SV_clone_ref() const {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Line", new Line(*this) );
|
||||
sv_setref_pv( sv, perl_class_name(this), new Line(*this) );
|
||||
return sv;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue