add support for smart pointers + %extend
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6819 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3331853982
commit
49c6b3f14f
5 changed files with 75 additions and 36 deletions
|
|
@ -10,6 +10,8 @@ b = Bar(f)
|
|||
b.y = 2
|
||||
|
||||
if f.y != 2:
|
||||
print f.y
|
||||
print b.y
|
||||
raise RuntimeError
|
||||
|
||||
if b.x != f.x:
|
||||
|
|
@ -17,3 +19,6 @@ if b.x != f.x:
|
|||
|
||||
if b.z != f.z:
|
||||
raise RuntimeError
|
||||
|
||||
if b.extension() != f.extension():
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -1,36 +1,43 @@
|
|||
%module smart_pointer_member
|
||||
|
||||
|
||||
%extend Foo
|
||||
{
|
||||
int extension(int i, int j) { return i; }
|
||||
int extension(int i) { return i; }
|
||||
int extension() { return 1; }
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
int x[4];
|
||||
int y;
|
||||
static const int z;
|
||||
};
|
||||
|
||||
class Bar {
|
||||
Foo *f;
|
||||
public:
|
||||
Bar(Foo *f) : f(f) { }
|
||||
Foo *operator->() {
|
||||
class Foo {
|
||||
public:
|
||||
int x[4];
|
||||
int y;
|
||||
static const int z;
|
||||
};
|
||||
|
||||
class Bar {
|
||||
Foo *f;
|
||||
public:
|
||||
Bar(Foo *f) : f(f) { }
|
||||
Foo *operator->() {
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
int get_y(Bar *b)
|
||||
{
|
||||
return (*b)->y;
|
||||
}
|
||||
|
||||
int get_z(Bar *b)
|
||||
{
|
||||
return (*b)->z;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
int get_y(Bar *b)
|
||||
{
|
||||
return (*b)->y;
|
||||
}
|
||||
|
||||
int get_z(Bar *b)
|
||||
{
|
||||
return (*b)->z;
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
%{
|
||||
const int Foo::z = 3;
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue