New Slic3r::Point::XS class

This commit is contained in:
Alessandro Ranellucci 2013-07-06 15:26:32 +02:00
parent cca25c9950
commit c50ecfb7f8
11 changed files with 109 additions and 17 deletions

View File

@ -7,5 +7,8 @@ our $VERSION = '0.01';
use XSLoader; use XSLoader;
XSLoader::load(__PACKAGE__, $VERSION); XSLoader::load(__PACKAGE__, $VERSION);
package Slic3r::Point::XS;
use overload
'@{}' => sub { $_[0]->_toPerl };
1; 1;

14
xs/src/Point.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "myinit.h"
#include "Point.hpp"
Point::Point(unsigned long x, unsigned long y) {}
Point::~Point() {}
SV*
Point::_toPerl() {
AV* av = newAV();
av_fill(av, 1);
av_store_point_xy(av, x, y);
return (SV*)newRV_noinc((SV*)av);
}

21
xs/src/Point.hpp Normal file
View File

@ -0,0 +1,21 @@
#ifndef slic3r_Point_hpp_
#define slic3r_Point_hpp_
extern "C" {
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
}
class Point
{
public:
unsigned long x;
unsigned long y;
Point(unsigned long _x, unsigned long _y): x(_x), y(_y) {};
~Point();
SV* _toPerl();
};
#endif

View File

@ -1,3 +1,6 @@
#ifndef slic3r_TriangleMesh_hpp_
#define slic3r_TriangleMesh_hpp_
#include <admesh/stl.h> #include <admesh/stl.h>
extern "C" { extern "C" {
@ -21,4 +24,4 @@ class TriangleMesh
stl_file stl; stl_file stl;
}; };
#endif

24
xs/src/ZTable.hpp Normal file
View File

@ -0,0 +1,24 @@
#ifndef slic3r_ZTable_hpp_
#define slic3r_ZTable_hpp_
extern "C" {
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
}
class ZTable
{
public:
ZTable(std::vector<unsigned int>* z_array);
std::vector<unsigned int> get_range(unsigned int min_z, unsigned int max_z);
std::vector<unsigned int> z;
};
ZTable::ZTable(std::vector<unsigned int>* ztable) :
z(*ztable)
{
}
#endif

View File

@ -3,21 +3,8 @@
#include <vector> #include <vector>
//////////////// #define av_store_point_xy(AV, X, Y) \
class ZTable av_store(AV, 0, newSViv(X)); \
{ av_store(AV, 1, newSViv(Y))
public:
ZTable(std::vector<unsigned int>* z_array);
std::vector<unsigned int> get_range(unsigned int min_z, unsigned int max_z);
std::vector<unsigned int> z;
};
ZTable::ZTable(std::vector<unsigned int>* ztable) :
z(*ztable)
{
}
////////////////
#include "TriangleMesh.hpp"
#endif #endif

12
xs/t/03_point.t Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/perl
use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 1;
my $point = Slic3r::Point::XS->new(10, 15);
is_deeply [ @$point ], [10, 15], 'point roundtrip';
__END__

View File

@ -2,6 +2,7 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "ZTable.hpp"
#include <vector> #include <vector>
%} %}

25
xs/xsp/Point.xsp Normal file
View File

@ -0,0 +1,25 @@
%module{Slic3r::XS};
%{
#include <myinit.h>
#include "Point.hpp"
%}
%name{Slic3r::Point::XS} class Point {
Point(unsigned long _x, unsigned long _y);
~Point();
SV* _toPerl();
};
%package{Slic3r::Point::XS};
%{
PROTOTYPES: DISABLE
std::string
hello_world()
CODE:
RETVAL = "Hello world!";
OUTPUT:
RETVAL
%}

View File

@ -2,6 +2,7 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "TriangleMesh.hpp"
%} %}
%name{Slic3r::TriangleMesh::XS} class TriangleMesh { %name{Slic3r::TriangleMesh::XS} class TriangleMesh {

View File

@ -1,3 +1,4 @@
ZTable* O_OBJECT ZTable* O_OBJECT
TriangleMesh* O_OBJECT TriangleMesh* O_OBJECT
Point* O_OBJECT
std::vector< unsigned int >* T_STD_VECTOR_UINT_PTR std::vector< unsigned int >* T_STD_VECTOR_UINT_PTR