File Coverage

blib/lib/ExtUtils/Typemaps/STL/String.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 18 18 100.0


line stmt bran cond sub pod time code
1             package ExtUtils::Typemaps::STL::String;
2              
3 1     1   978 use strict;
  1         3  
  1         44  
4 1     1   5 use warnings;
  1         3  
  1         36  
5 1     1   6929 use ExtUtils::Typemaps;
  1         48744  
  1         143  
6              
7             our $VERSION = '1.05';
8              
9             our @ISA = qw(ExtUtils::Typemaps);
10              
11             =head1 NAME
12              
13             ExtUtils::Typemaps::STL::String - A set of typemaps for STL std::strings
14              
15             =head1 SYNOPSIS
16              
17             use ExtUtils::Typemaps::STL::String;
18             # First, read my own type maps:
19             my $private_map = ExtUtils::Typemaps->new(file => 'my.map');
20            
21             # Then, get the object map set and merge it into my maps
22             $private_map->merge(typemap => ExtUtils::Typemaps::STL::String->new);
23            
24             # Now, write the combined map to an output file
25             $private_map->write(file => 'typemap');
26              
27             =head1 DESCRIPTION
28              
29             C is an C
30             subclass that provides a set of mappings for C++ STL strings.
31             These are:
32              
33             TYPEMAP
34             std::string T_STD_STRING
35             std::string* T_STD_STRING_PTR
36              
37             INPUT
38             T_STD_STRING
39             $var = std::string( SvPV_nolen( $arg ), SvCUR( $arg ) );
40              
41             T_STD_STRING_PTR
42             $var = new std::string( SvPV_nolen( $arg ), SvCUR( $arg ) );
43              
44             OUTPUT
45             T_STD_STRING
46             $arg = newSVpvn( $var.c_str(), $var.length() );
47              
48             T_STD_STRING_PTR
49             $arg = newSVpvn( $var->c_str(), $var->length() );
50              
51             =head1 METHODS
52              
53             These are the overridden methods:
54              
55             =head2 new
56              
57             Creates a new C object.
58             It acts as any other C object, except that
59             it has the string type maps initialized.
60              
61             =cut
62              
63             sub new {
64 3     3 1 1210 my $class = shift;
65              
66 3         25 my $self = $class->SUPER::new(@_);
67 3         79 $self->add_string(string => <<'END_TYPEMAP');
68             TYPEMAP
69             std::string T_STD_STRING
70             std::string* T_STD_STRING_PTR
71              
72             INPUT
73             T_STD_STRING
74             $var = std::string( SvPV_nolen( $arg ), SvCUR( $arg ) );
75              
76             T_STD_STRING_PTR
77             $var = new std::string( SvPV_nolen( $arg ), SvCUR( $arg ) );
78              
79             OUTPUT
80             T_STD_STRING
81             $arg = newSVpvn( $var.c_str(), $var.length() );
82              
83             T_STD_STRING_PTR
84             $arg = newSVpvn( $var->c_str(), $var->length() );
85             END_TYPEMAP
86              
87 3         3592 return $self;
88             }
89              
90             1;
91              
92             __END__