Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Ledvina <ledvinap@gmail.com>2014-04-27 21:18:53 +0400
committerPetr Ledvina <ledvinap@gmail.com>2014-04-27 21:38:56 +0400
commit115aa6885f7ca50aa5377b36a881173703ae748b (patch)
treec8c3ba0dab68f8c00d61945c619c7483eca2744d /xs/src/ExPolygon.cpp
parente68b6b6f4c28535a2798bdcffa252b21617be71e (diff)
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.
Diffstat (limited to 'xs/src/ExPolygon.cpp')
-rw-r--r--xs/src/ExPolygon.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/xs/src/ExPolygon.cpp b/xs/src/ExPolygon.cpp
index a6c3bc7fd..12f595ac7 100644
--- a/xs/src/ExPolygon.cpp
+++ b/xs/src/ExPolygon.cpp
@@ -4,6 +4,9 @@
#include "Line.hpp"
#include "ClipperUtils.hpp"
#include "polypartition.h"
+#ifdef SLIC3RXS
+#include "perlglue.hpp"
+#endif
#include <list>
@@ -240,6 +243,9 @@ ExPolygon::triangulate2(Polygons* polygons) const
}
#ifdef SLIC3RXS
+
+REGISTER_CLASS(ExPolygon, "ExPolygon");
+
SV*
ExPolygon::to_AV() {
const unsigned int num_holes = this->holes.size();
@@ -257,14 +263,14 @@ ExPolygon::to_AV() {
SV*
ExPolygon::to_SV_ref() {
SV* sv = newSV(0);
- sv_setref_pv( sv, "Slic3r::ExPolygon::Ref", this );
+ sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv;
}
SV*
ExPolygon::to_SV_clone_ref() const {
SV* sv = newSV(0);
- sv_setref_pv( sv, "Slic3r::ExPolygon", new ExPolygon(*this) );
+ sv_setref_pv( sv, perl_class_name(this), new ExPolygon(*this) );
return sv;
}
@@ -300,8 +306,8 @@ void
ExPolygon::from_SV_check(SV* expoly_sv)
{
if (sv_isobject(expoly_sv) && (SvTYPE(SvRV(expoly_sv)) == SVt_PVMG)) {
- if (!sv_isa(expoly_sv, "Slic3r::ExPolygon") && !sv_isa(expoly_sv, "Slic3r::ExPolygon::Ref"))
- CONFESS("Not a valid Slic3r::ExPolygon object");
+ if (!sv_isa(expoly_sv, perl_class_name(this)) && !sv_isa(expoly_sv, perl_class_name_ref(this)))
+ CONFESS("Not a valid %s object", perl_class_name(this));
// a XS ExPolygon was supplied
*this = *(ExPolygon *)SvIV((SV*)SvRV( expoly_sv ));
} else {