four new director tests
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4449 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5a7faa47a1
commit
99cef9c7da
9 changed files with 299 additions and 0 deletions
54
SWIG/Examples/test-suite/director_exception.i
Normal file
54
SWIG/Examples/test-suite/director_exception.i
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
%module(directors="1") director_exception
|
||||
%{
|
||||
|
||||
#include <string>
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Foo::ping()"; }
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
|
||||
Foo *launder(Foo *f) {
|
||||
return f;
|
||||
}
|
||||
|
||||
// define dummy director exception classes to prevent spurious errors
|
||||
// in target languages that do not support directors.
|
||||
|
||||
#ifndef SWIG_DIRECTORS
|
||||
class SWIG_DIRECTOR_EXCEPTION {};
|
||||
class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION {};
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%include "typemaps.i"
|
||||
%include "exception.i"
|
||||
%include "std_string.i"
|
||||
|
||||
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
throw SWIG_DIRECTOR_METHOD_EXCEPTION();
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (SWIG_DIRECTOR_EXCEPTION &e) { SWIG_fail; }
|
||||
}
|
||||
|
||||
|
||||
%feature("director") Foo;
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Foo::ping()"; }
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
|
||||
Foo *launder(Foo *f);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue