Fixes to support protected members with director, proper virtual member recognition and support of the nodirector feature
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5485 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
46d70e8e1f
commit
75c1713b2d
13 changed files with 380 additions and 37 deletions
|
|
@ -112,6 +112,8 @@ CPP_TEST_CASES += \
|
|||
director_basic \
|
||||
director_exception \
|
||||
director_finalizer \
|
||||
director_nested \
|
||||
director_protected \
|
||||
director_unroll \
|
||||
director_wombat \
|
||||
dynamic_cast \
|
||||
|
|
|
|||
62
SWIG/Examples/test-suite/director_nested.i
Normal file
62
SWIG/Examples/test-suite/director_nested.i
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
%module(directors="1") director_nested
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") FooBar<int>;
|
||||
|
||||
%newobject *::create();
|
||||
|
||||
%inline %{
|
||||
template <class C>
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
|
||||
std::string advance()
|
||||
{
|
||||
return "Foo::advance;" + do_advance();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual std::string do_advance() = 0;
|
||||
};
|
||||
%}
|
||||
|
||||
%template(Foo_int) Foo<int>;
|
||||
|
||||
%inline %{
|
||||
|
||||
class Bar : public Foo<int>
|
||||
{
|
||||
public:
|
||||
|
||||
std::string step()
|
||||
{
|
||||
return "Bar::step;" + advance();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string do_advance()
|
||||
{
|
||||
return "Bar::do_advance;" + do_step();
|
||||
}
|
||||
|
||||
|
||||
virtual std::string do_step() = 0;
|
||||
};
|
||||
|
||||
template <class C>
|
||||
class FooBar : public Bar
|
||||
{
|
||||
public:
|
||||
virtual C get_value() = 0;
|
||||
};
|
||||
%}
|
||||
|
||||
%template(FooBar_int) FooBar<int>;
|
||||
|
||||
46
SWIG/Examples/test-suite/director_protected.i
Normal file
46
SWIG/Examples/test-suite/director_protected.i
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
%module(directors="1") director_protected
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") Foo;
|
||||
%feature("director") Bar;
|
||||
|
||||
%newobject *::create();
|
||||
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string pong() {
|
||||
return "Foo::pong();" + ping();
|
||||
}
|
||||
protected:
|
||||
virtual std::string ping() = 0;
|
||||
};
|
||||
|
||||
class Bar : public Foo
|
||||
{
|
||||
public:
|
||||
Foo* create()
|
||||
{
|
||||
return new Bar();
|
||||
}
|
||||
|
||||
std::string pong() {
|
||||
return "Bar::pong();" + Foo::pong();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string ping() {
|
||||
return "Bar::ping();";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
%}
|
||||
|
||||
36
SWIG/Examples/test-suite/python/director_nested_runme.py
Normal file
36
SWIG/Examples/test-suite/python/director_nested_runme.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from director_nested import *
|
||||
|
||||
|
||||
class A(FooBar_int):
|
||||
def do_step(self):
|
||||
return "A::do_step;"
|
||||
|
||||
def get_value(self):
|
||||
return "A::get_value"
|
||||
|
||||
pass
|
||||
|
||||
|
||||
a = A()
|
||||
if a.step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;":
|
||||
raise RuntimeError,"Bad A virtual resolution"
|
||||
|
||||
|
||||
class B(FooBar_int):
|
||||
def do_advance(self):
|
||||
return "B::do_advance;" + self.do_step()
|
||||
|
||||
def do_step(self):
|
||||
return "B::do_step;"
|
||||
|
||||
def get_value(self):
|
||||
return "B::get_value"
|
||||
|
||||
pass
|
||||
|
||||
|
||||
b = B()
|
||||
|
||||
if b.step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;":
|
||||
raise RuntimeError,"Bad B virtual resolution"
|
||||
|
||||
54
SWIG/Examples/test-suite/python/director_protected_runme.py
Normal file
54
SWIG/Examples/test-suite/python/director_protected_runme.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from director_protected import *
|
||||
|
||||
|
||||
|
||||
class FooBar(Bar):
|
||||
def ping(self):
|
||||
return "FooBar::ping();"
|
||||
|
||||
|
||||
b = Bar()
|
||||
f = b.create()
|
||||
fb = FooBar()
|
||||
|
||||
try:
|
||||
s1 = b.pong()
|
||||
if s1 != "Bar::pong();Foo::pong();Bar::ping();":
|
||||
raise RuntimeError
|
||||
pass
|
||||
except:
|
||||
raise RuntimeError, "bad Bar::pong"
|
||||
|
||||
try:
|
||||
s2 = f.pong()
|
||||
if s2 != "Bar::pong();Foo::pong();Bar::ping();":
|
||||
raise RuntimeError
|
||||
pass
|
||||
except:
|
||||
raise RuntimeError," bad Foo::pong"
|
||||
|
||||
try:
|
||||
s3 = fb.pong()
|
||||
if s3 != "Bar::pong();Foo::pong();FooBar::ping();":
|
||||
raise RuntimeError
|
||||
pass
|
||||
except:
|
||||
raise RuntimeError," bad FooBar::pong"
|
||||
|
||||
private=1
|
||||
try:
|
||||
b.ping()
|
||||
private=0
|
||||
except:
|
||||
pass
|
||||
if not private:
|
||||
raise RuntimeError,"Boo::ping is private"
|
||||
|
||||
private=1
|
||||
try:
|
||||
f.ping()
|
||||
private=0
|
||||
except:
|
||||
pass
|
||||
if not private:
|
||||
raise RuntimeError,"Foo::ping is private"
|
||||
Loading…
Add table
Add a link
Reference in a new issue