Merge remote-tracking branch 'origin/shared_ptr_const_conv' into shared_ptr_derived_2
This commit is contained in:
commit
377d439964
4 changed files with 77 additions and 2 deletions
57
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
57
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
%module cpp11_shared_ptr_const
|
||||||
|
|
||||||
|
%{
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Foo(int i) : m(i) {}
|
||||||
|
int get_m() { return m;}
|
||||||
|
int m;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::shared_ptr<Foo> foo(Foo v) {
|
||||||
|
return std::shared_ptr<Foo>(new Foo(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const Foo> const_foo(Foo v) {
|
||||||
|
return std::shared_ptr<const Foo>(new Foo(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<Foo> > foo_vec(Foo v) {
|
||||||
|
std::vector<std::shared_ptr<Foo> > result;
|
||||||
|
result.push_back( std::shared_ptr<Foo>(new Foo(v)) );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) {
|
||||||
|
std::vector<std::shared_ptr<const Foo> > result;
|
||||||
|
result.push_back( std::shared_ptr<Foo>(new Foo(v)) );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include <std_shared_ptr.i>
|
||||||
|
%include <std_vector.i>
|
||||||
|
|
||||||
|
%shared_ptr(Foo);
|
||||||
|
|
||||||
|
%template (FooVector) std::vector<std::shared_ptr<Foo> >;
|
||||||
|
%template (FooConstVector) std::vector<std::shared_ptr<Foo const> >;
|
||||||
|
|
||||||
|
std::shared_ptr<Foo> foo(Foo v);
|
||||||
|
std::shared_ptr<const Foo> const_foo(Foo v);
|
||||||
|
std::vector<std::shared_ptr<Foo> > foo_vec(Foo v) const;
|
||||||
|
std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) const;
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Foo(int i);
|
||||||
|
int get_m();
|
||||||
|
int m;
|
||||||
|
};
|
||||||
|
|
@ -31,7 +31,8 @@ CPP_TEST_CASES = \
|
||||||
|
|
||||||
CPP11_TEST_CASES = \
|
CPP11_TEST_CASES = \
|
||||||
cpp11_hash_tables \
|
cpp11_hash_tables \
|
||||||
cpp11_shared_ptr_upcast
|
cpp11_shared_ptr_upcast \
|
||||||
|
cpp11_shared_ptr_const
|
||||||
|
|
||||||
C_TEST_CASES += \
|
C_TEST_CASES += \
|
||||||
li_cstring \
|
li_cstring \
|
||||||
|
|
|
||||||
9
Examples/test-suite/ruby/cpp11_shared_ptr_const_runme.rb
Normal file
9
Examples/test-suite/ruby/cpp11_shared_ptr_const_runme.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
require "swig_assert"
|
||||||
|
require "cpp11_shared_ptr_const"
|
||||||
|
|
||||||
|
include Cpp11_shared_ptr_const
|
||||||
|
|
||||||
|
simple_assert_equal(1, foo( Foo.new(1) ).get_m )
|
||||||
|
simple_assert_equal(7, const_foo( Foo.new(7) ).get_m )
|
||||||
|
simple_assert_equal(7, foo_vec( Foo.new(7) )[0].get_m )
|
||||||
|
simple_assert_equal(8, const_foo_vec( Foo.new(8) )[0].get_m )
|
||||||
|
|
@ -83,6 +83,14 @@ namespace swig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
template<class Type>
|
||||||
|
struct traits_from<std::shared_ptr<const Type> > {
|
||||||
|
static VALUE from(const std::shared_ptr<const Type>& val) {
|
||||||
|
std::shared_ptr<Type> p = std::const_pointer_cast<Type>(val);
|
||||||
|
return swig::from(p);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue