The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5fcae5eb66
commit
12a43edc2d
1508 changed files with 125983 additions and 44037 deletions
65
Examples/test-suite/dynamic_cast.i
Normal file
65
Examples/test-suite/dynamic_cast.i
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* File : example.i */
|
||||
%module dynamic_cast
|
||||
|
||||
#ifndef SWIGJAVA
|
||||
%apply SWIGTYPE *DYNAMIC { Foo * };
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual Foo *blah() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
%typemap(out) Foo *blah {
|
||||
Bar *downcast = dynamic_cast<Bar *>($1);
|
||||
*(Bar **)&$result = downcast;
|
||||
}
|
||||
|
||||
%typemap(javaout) Foo * {
|
||||
return new Bar($jnicall, $owner);
|
||||
}
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
class Bar : public Foo {
|
||||
public:
|
||||
virtual Foo *blah() {
|
||||
return (Foo *) this;
|
||||
}
|
||||
virtual char * test() {
|
||||
return (char *) "Bar::test";
|
||||
}
|
||||
};
|
||||
|
||||
char *do_test(Bar *b) {
|
||||
return b->test();
|
||||
}
|
||||
%}
|
||||
|
||||
#ifndef SWIGJAVA
|
||||
// A general purpose function for dynamic casting of a Foo *
|
||||
%{
|
||||
static swig_type_info *
|
||||
Foo_dynamic(void **ptr) {
|
||||
Bar *b;
|
||||
b = dynamic_cast<Bar *>((Foo *) *ptr);
|
||||
if (b) {
|
||||
*ptr = (void *) b;
|
||||
return SWIGTYPE_p_Bar;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
%}
|
||||
|
||||
// Register the above casting function
|
||||
DYNAMIC_CAST(SWIGTYPE_p_Foo, Foo_dynamic);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue