/usr/share/perl5/ExtUtils/Typemaps/STL/List.pm is in libextutils-typemaps-default-perl 1.05-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | package ExtUtils::Typemaps::STL::List;
use strict;
use warnings;
use ExtUtils::Typemaps;
our $VERSION = '1.05';
our @ISA = qw(ExtUtils::Typemaps);
=head1 NAME
ExtUtils::Typemaps::STL::List - A set of typemaps for STL std::lists
=head1 SYNOPSIS
use ExtUtils::Typemaps::STL::List;
# First, read my own type maps:
my $private_map = ExtUtils::Typemaps->new(file => 'my.map');
# Then, get the object map set and merge it into my maps
$private_map->merge(typemap => ExtUtils::Typemaps::STL::List->new);
# Now, write the combined map to an output file
$private_map->write(file => 'typemap');
=head1 DESCRIPTION
C<ExtUtils::Typemaps::STL::List> is an C<ExtUtils::Typemaps>
subclass that provides a set of mappings for C++ STL lists.
These are:
TYPEMAP
std::list<double> T_STD_LIST_DOUBLE
std::list<double>* T_STD_LIST_DOUBLE_PTR
std::list<int> T_STD_LIST_INT
std::list<int>* T_STD_LIST_INT_PTR
std::list<unsigned int> T_STD_LIST_UINT
std::list<unsigned int>* T_STD_LIST_UINT_PTR
std::list<std::string> T_STD_LIST_STD_STRING
std::list<std::string>* T_STD_LIST_STD_STRING_PTR
std::list<char*> T_STD_LIST_CSTRING
std::list<char*>* T_STD_LIST_CSTRING_PTR
All of these mean that the lists are converted to references
to Perl arrays and vice versa.
=head1 METHODS
These are the overridden methods:
=head2 new
Creates a new C<ExtUtils::Typemaps::STL::List> object.
It acts as any other C<ExtUtils::Typemaps> object, except that
it has the list type maps initialized.
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my $input_tmpl = <<'HERE';
!TYPENAME!
if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
AV* av = (AV*)SvRV($arg);
const unsigned int len = av_len(av)+1;
$var = std::list<!TYPE!>();
SV** elem;
for (unsigned int i = 0; i < len; i++) {
elem = av_fetch(av, i, 0);
if (elem != NULL)
${var}.push_back(Sv!SHORTTYPE!V(*elem));
else
${var}[i].push_back(!DEFAULT!);
}
}
else
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\");
!TYPENAME!_PTR
if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
AV* av = (AV*)SvRV($arg);
const unsigned int len = av_len(av)+1;
$var = new std::list<!TYPE!>();
SV** elem;
for (unsigned int i = 0; i < len; i++) {
elem = av_fetch(av, i, 0);
if (elem != NULL)
(*$var).push_back(Sv!SHORTTYPE!V(*elem));
else
(*$var).push_back(!DEFAULT!);
}
}
else
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\");
HERE
my $output_tmpl = <<'HERE';
!TYPENAME!
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
const unsigned int len = $var.size(); // Technically may be linear...
av_extend(av, len-1);
unsigned int i = 0;
std::list<!TYPE!>::const_iterator lend = $var.cend();
std::list<!TYPE!>::const_iterator lit = $var.cbegin();
for (; lit != lend; ++lit) {
av_store(av, i++, newSV!SHORTTYPELC!v(*lit));
}
!TYPENAME!_PTR
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
const unsigned int len = $var->size(); // Technically may be linear...
av_extend(av, len-1);
unsigned int i = 0;
std::list<!TYPE!>::const_iterator lend = (*$var).cend();
std::list<!TYPE!>::const_iterator lit = (*$var).cbegin();
for (; lit != lend; ++lit) {
av_store(av, i++, newSV!SHORTTYPELC!v(*lit));
}
HERE
my ($output_code, $input_code);
# TYPENAME, TYPE, SHORTTYPE, SHORTTYPELC, DEFAULT
foreach my $type ([qw(T_STD_LIST_DOUBLE double N n 0.)],
[qw(T_STD_LIST_INT int I i 0)],
[qw(T_STD_LIST_UINT), "unsigned int", qw(U u 0)])
{
my @type = @$type;
my $otmpl = $output_tmpl;
my $itmpl = $input_tmpl;
for ($otmpl, $itmpl) {
s/!TYPENAME!/$type[0]/g;
s/!TYPE!/$type[1]/g;
s/!SHORTTYPE!/$type[2]/g;
s/!SHORTTYPELC!/$type[3]/g;
s/!DEFAULT!/$type[4]/g;
}
$output_code .= $otmpl;
$input_code .= $itmpl;
}
# add a static part
$output_code .= <<'END_OUTPUT';
T_STD_LIST_STD_STRING
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
const unsigned int len = $var.size(); // Technically may be linear...
av_extend(av, len-1);
unsigned int i = 0;
std::list<std::string>::const_iterator lend = $var.cend();
std::list<std::string>::const_iterator lit = $var.cbegin();
for (; lit != lend; ++lit) {
const std::string& str = *lit;
STRLEN len = str.length();
av_store(av, i++, newSVpv(str.c_str(), len));
}
T_STD_LIST_STD_STRING_PTR
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
const unsigned int len = $var->size(); // Technically may be linear...
av_extend(av, len-1);
unsigned int i = 0;
std::list<std::string>::const_iterator lend = (*$var).cend();
std::list<std::string>::const_iterator lit = (*$var).cbegin();
for (; lit != lend; ++lit) {
const std::string& str = *lit;
STRLEN len = str.length();
av_store(av, i++, newSVpv(str.c_str(), len));
}
T_STD_LIST_CSTRING
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
const unsigned int len = $var.size();
av_extend(av, len-1);
unsigned int i = 0;
std::list<char *>::const_iterator lend = $var.cend();
std::list<char *>::const_iterator lit = $var.cbegin();
for (; lit != lend; ++lit) {
av_store(av, i, newSVpv(*lit, (STRLEN)strlen(*lit)));
}
T_STD_LIST_CSTRING_PTR
AV* av = newAV();
$arg = newRV_noinc((SV*)av);
const unsigned int len = $var->size();
av_extend(av, len-1);
unsigned int i = 0;
std::list<char *>::const_iterator lend = (*$var).cend();
std::list<char *>::const_iterator lit = (*$var).cbegin();
for (; lit != lend; ++lit) {
av_store(av, i, newSVpv(*lit, (STRLEN)strlen(*lit)));
}
END_OUTPUT
# add a static part to input
$input_code .= <<'END_INPUT';
T_STD_LIST_STD_STRING
if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
AV* av = (AV*)SvRV($arg);
const unsigned int alen = av_len(av)+1;
$var = std::list<std::string>();
STRLEN len;
char* tmp;
SV** elem;
for (unsigned int i = 0; i < alen; i++) {
elem = av_fetch(av, i, 0);
if (elem != NULL) {
tmp = SvPV(*elem, len);
${var}.push_back(std::string(tmp, len));
}
else
${var}.push_back(std::string(\"\"));
}
}
else
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\");
T_STD_LIST_STD_STRING_PTR
if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
AV* av = (AV*)SvRV($arg);
const unsigned int alen = av_len(av)+1;
$var = new std::list<std::string>(alen);
STRLEN len;
char* tmp;
SV** elem;
for (unsigned int i = 0; i < alen; i++) {
elem = av_fetch(av, i, 0);
if (elem != NULL) {
tmp = SvPV(*elem, len);
(*$var).push_back(std::string(tmp, len));
}
else
(*$var).push_back(std::string(\"\"));
}
}
else
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\");
T_STD_LIST_CSTRING
if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
AV* av = (AV*)SvRV($arg);
const unsigned int len = av_len(av)+1;
$var = std::list<char*>();
SV** elem;
for (unsigned int i = 0; i < len; i++) {
elem = av_fetch(av, i, 0);
if (elem != NULL) {
${var}.push_back(SvPV_nolen(*elem));
else
${var}.push_back(NULL);
}
}
else
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\");
T_STD_LIST_CSTRING_PTR
if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) {
AV* av = (AV*)SvRV($arg);
const unsigned int len = av_len(av)+1;
$var = new std::list<char*>();
SV** elem;
for (unsigned int i = 0; i < len; i++) {
elem = av_fetch(av, i, 0);
if (elem != NULL) {
(*$var).push_back(SvPV_nolen(*elem));
else
(*$var).push_back(NULL);
}
}
else
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\");
END_INPUT
my $typemap_code = <<'END_TYPEMAP';
TYPEMAP
std::list<double>* T_STD_LIST_DOUBLE_PTR
std::list<double> T_STD_LIST_DOUBLE
std::list<int>* T_STD_LIST_INT_PTR
std::list<int> T_STD_LIST_INT
std::list<unsigned int>* T_STD_LIST_UINT_PTR
std::list<unsigned int> T_STD_LIST_UINT
std::list<std::string> T_STD_LIST_STD_STRING
std::list<std::string>* T_STD_LIST_STD_STRING_PTR
std::list<string> T_STD_LIST_STD_STRING
std::list<string>* T_STD_LIST_STD_STRING_PTR
std::list<char*> T_STD_LIST_CSTRING
std::list<char*>* T_STD_LIST_CSTRING_PTR
list<double>* T_STD_LIST_DOUBLE_PTR
list<double> T_STD_LIST_DOUBLE
list<int>* T_STD_LIST_INT_PTR
list<int> T_STD_LIST_INT
list<unsigned int>* T_STD_LIST_UINT_PTR
list<unsigned int> T_STD_LIST_UINT
list<std::string> T_STD_LIST_STD_STRING
list<std::string>* T_STD_LIST_STD_STRING_PTR
list<string> T_STD_LIST_STD_STRING
list<string>* T_STD_LIST_STD_STRING_PTR
list<char*> T_STD_LIST_CSTRING
list<char*>* T_STD_LIST_CSTRING_PTR
INPUT
END_TYPEMAP
$typemap_code .= $input_code;
$typemap_code .= "\nOUTPUT\n";
$typemap_code .= $output_code;
$typemap_code .= "\n";
$self->add_string(string => $typemap_code);
return $self;
}
1;
__END__
=head1 SEE ALSO
L<ExtUtils::Typemaps>, L<ExtUtils::Typemaps::Default>, L<ExtUtils::Typemaps::ObjectMap>,
L<ExtUtils::Typemaps::STL>, L<ExtUtils::Typemaps::STL::String>, L<ExtUtils::Typemaps::STL::Vector>
=head1 AUTHOR
Steffen Mueller <smueller@cpan.org>
=head1 COPYRIGHT AND LICENSE
Copyright 2013 by Steffen Mueller
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
|