diff --git a/SWIG/Examples/test-suite/python/director_stl.i b/SWIG/Examples/test-suite/python/director_stl.i new file mode 100644 index 000000000..05f5b482c --- /dev/null +++ b/SWIG/Examples/test-suite/python/director_stl.i @@ -0,0 +1,66 @@ +%module(directors="1") director_stl + +%include "std_string.i" +%include "std_pair.i" +%include "std_vector.i" + +%feature("director") Foo; + +%feature("director:except") { + if ($error != NULL) { + throw Swig::DirectorMethodException(); + } +} + +%exception { + try { $action } + catch (...) { SWIG_fail; } +} + +%inline +{ +class Foo { +public: + virtual ~Foo() {} + + virtual std::string& bar(std::string& s) + { + return s; + } + + + virtual std::string ping(std::string s) = 0; + virtual std::string pong(const std::string& s) + { return std::string("Foo::pong:") + s + ":" + ping(s); } + + std::string tping(std::string s) { return ping(s); } + std::string tpong(const std::string& s) { return pong(s); } + + virtual std::pair + pident(const std::pair& p) { return p; } + + virtual std::vector + vident(const std::vector& p) { return p; } + + virtual std::vector + vsecond(const std::vector& p, const std::vector& s) { return s; } + + std::pair + tpident(const std::pair& p) { return pident(p); } + + std::vector + tvident(const std::vector& p) { return vident(p); } + + virtual std::vector + tvsecond(const std::vector& p, const std::vector& s) { return vsecond(p,s); } + + + virtual std::vector + vidents(const std::vector& p) { return p; } + + std::vector + tvidents(const std::vector& p) { return vidents(p); } + +}; + +} diff --git a/SWIG/Examples/test-suite/python/director_stl_runme.py b/SWIG/Examples/test-suite/python/director_stl_runme.py new file mode 100644 index 000000000..aaea0362a --- /dev/null +++ b/SWIG/Examples/test-suite/python/director_stl_runme.py @@ -0,0 +1,39 @@ +import director_stl + +class MyFoo(director_stl.Foo): + def ping(self, s): + return "MyFoo::ping():" + s + + def pident(self, arg): + return arg + + def vident(self,v): + return v + + def vidents(self,v): + return v + + def vsecond(self,v1,v2): + return v2 + + +a = MyFoo() + +a.tping("hello") +a.tpong("hello") + +p = (1,2) +a.pident(p) +v = (3,4) +a.vident(v) + +a.tpident(p) +a.tvident(v) + +v1 = (3,4) +v2 = (5,6) +a.tvsecond(v1,v2) + +vs=("hi", "hello") +vs +a.tvidents(vs) diff --git a/SWIG/Examples/test-suite/python/lib_std_string.i b/SWIG/Examples/test-suite/python/lib_std_string.i new file mode 100644 index 000000000..f9ce9e48b --- /dev/null +++ b/SWIG/Examples/test-suite/python/lib_std_string.i @@ -0,0 +1,57 @@ +%module lib_std_string +%include "std_string.i" + +%template(string) std::basic_string; +%inline %{ + +struct A : std::string +{ + A(const std::string& s) : std::string(s) + { + } + +}; + + + +std::string test_value(std::string x) { + return x; +} + +const std::string& test_const_reference(const std::string &x) { + return x; +} + +void test_pointer(std::string *x) { +} + +std::string *test_pointer_out() { + static std::string x = "x"; + return &x; +} + +void test_const_pointer(const std::string *x) { +} + +const std::string *test_const_pointer_out() { + static std::string x = "x"; + return &x; +} + +void test_reference(std::string &x) { +} + +std::string& test_reference_out() { + static std::string x = "x"; + return x; +} + +void test_throw() throw(std::string){ + static std::string x = "x"; + + throw x; +} + +%} + + diff --git a/SWIG/Examples/test-suite/python/lib_std_string_runme.py b/SWIG/Examples/test-suite/python/lib_std_string_runme.py new file mode 100644 index 000000000..d72b0ddcb --- /dev/null +++ b/SWIG/Examples/test-suite/python/lib_std_string_runme.py @@ -0,0 +1,27 @@ +import lib_std_string + +x="hello" + +if lib_std_string.test_value(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_const_reference(x) != x: + raise RuntimeError, "bad string mapping" + + +s = lib_std_string.string("he") +s.append("llo") + +if lib_std_string.test_value(s) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_const_reference(s) != x: + raise RuntimeError, "bad string mapping" + +a = lib_std_string.A("hello") + +if lib_std_string.test_value(a) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_const_reference(a) != x: + raise RuntimeError, "bad string mapping"