Merge branch 'unique_ptr'
* unique_ptr: Add std::unique_ptr<type> to Perl5.
This commit is contained in:
commit
3cbcdbf681
3 changed files with 37 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
%module cpp11_std_unique_ptr
|
||||
|
||||
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY)
|
||||
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGPERL)
|
||||
|
||||
%include "std_unique_ptr.i"
|
||||
|
||||
|
|
|
|||
17
Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl
Normal file
17
Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 6;
|
||||
BEGIN { use_ok('cpp11_std_unique_ptr') }
|
||||
require_ok('cpp11_std_unique_ptr');
|
||||
|
||||
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
|
||||
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");
|
||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 2, "have 2 pointers");
|
||||
|
||||
undef $k1;
|
||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 1, "left 1 pointer");
|
||||
|
||||
is($k2->getLabel, "second", "proper label");
|
||||
|
||||
undef $k2;
|
||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 0, "remove all pointers");
|
||||
19
Lib/perl5/std_unique_ptr.i
Normal file
19
Lib/perl5/std_unique_ptr.i
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_unique_ptr.i
|
||||
*
|
||||
* The typemaps here allow handling functions returning std::unique_ptr<>,
|
||||
* which is the most common use of this type. If you have functions taking it
|
||||
* as parameter, these typemaps can't be used for them and you need to do
|
||||
* something else (e.g. use shared_ptr<> which SWIG supports fully).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define %unique_ptr(TYPE)
|
||||
%typemap (out) std::unique_ptr< TYPE > %{
|
||||
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
|
||||
%}
|
||||
%template() std::unique_ptr< TYPE >;
|
||||
%enddef
|
||||
|
||||
namespace std {
|
||||
template <class T> class unique_ptr {};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue