blib/lib/ExtUtils/Typemaps/STL/Extra.pm

filter: Statementstmt 100% 22 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 29 / 29 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package ExtUtils::Typemaps::STL::Extra;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use ExtUtils::Typemaps;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =encoding utf-8
10  
11 =head1 NAME
12  
13 ExtUtils::Typemaps::STL::Extra - Extra typemaps for STL types
14  
15 =head1 VERSION
16  
17 Version 0.01
18  
19 =cut
20  
21 2 our $VERSION = '0.01';
22 2 our @ISA = qw(ExtUtils::Typemaps);
23  
24 =head1 SYNOPSIS
25  
26 use Module::Build::WithXSpp;
27
28 my $build = Module::Build::WithXSpp->new(
29 extra_typemap_modules => {
30 'ExtUtils::Typemaps::STL::Extra' => '0'
31 },
32 );
33  
34 =head1 DESCRIPTION
35  
36 This module add extra typemaps for STL types to make it easier wrapping C++ using L<ExtUtils::XSpp>
37  
38  
39 =head1 METHODS
40  
41 =cut
42  
43 =head2 new
44  
45 Creates a new ExtUtils::Typemaps::STL::Extra object. It acts as any other ExtUtils::Typemaps object, except that it has the extra type maps initialized.
46  
47 =cut
48  
49 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
50 1 my $class = shift;
51  
52 1 my $self = $class->SUPER::new(@_);
53  
54 1 my $typemap = <<'END_TYPEMAP';
55 TYPEMAP
56 std::vector<std::vector<double> > T_STD_VECTOR_STD_VECTOR_DOUBLE
57  
58 INPUT
59  
60 T_STD_VECTOR_STD_VECTOR_DOUBLE
61 if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
62 AV* av = (AV*)SvRV($arg);
63 const unsigned int len = av_len(av)+1;
64 $var = std::vector<std::vector<double>>(len);
65 SV** elem;
66 for (unsigned int i = 0; i < len; i++) {
67 elem = av_fetch(av, i, 0);
68 if (elem != NULL && SvROK(*elem) && SvTYPE(SvRV(*elem))==SVt_PVAV) {
69
70 AV* av_inner = (AV*)SvRV(*elem);
71 const unsigned int len_j = av_len(av_inner) + 1;
72 std::vector<double> inner_vector(len_j);
73 SV** inner_elem;
74 for (unsigned int j = 0; j < len_j; j++) {
75 inner_elem = av_fetch(av_inner, j, 0);
76 if (inner_elem != NULL)
77 inner_vector[j] = SvNV(*inner_elem);
78 else
79 inner_vector[j] = 0;
80 }
81 ${var}[i] = inner_vector;
82 }
83 else
84 ${var}[i] = std::vector<double>();
85 }
86 }
87 else
88 Perl_croak(aTHX_ \"%s: %s is not an array reference\",
89 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
90 \"$var\");
91  
92 OUTPUT
93  
94 T_STD_VECTOR_STD_VECTOR_DOUBLE
95 AV* av = newAV();
96 $arg = newRV_noinc((SV*)av);
97 const unsigned int len = $var.size();
98 if (len)
99 av_extend(av, len-1);
100 for (unsigned int i = 0; i < len; i++) {
101 const unsigned int len_j = ${var}[i].size();
102 AV *inner_av = newAV();
103 if (len_j) av_extend(inner_av, len_j - 1);
104 for (unsigned int j = 0; j < len_j; j++) {
105 av_store(inner_av, j, newSVnv(${var}[i][j]));
106 }
107 av_store(av, i, newRV_noinc((SV*)inner_av));
108 }
109  
110  
111 END_TYPEMAP
112  
113 1 $self->add_string( string => $typemap );
114  
115 #die $typemap;
116 1 return $self;
117 }
118  
119 2 1; # End of ExtUtils::Typemaps::STL::Extra
120  
121 __END__
↑ Summary