Update documentation for using SWIG_ConvertPtr example usage

Add a test case to test the example documentation typemaps
This commit is contained in:
William S Fulton 2016-10-22 20:55:37 +01:00
commit 96015de0dd
8 changed files with 125 additions and 54 deletions

View file

@ -487,6 +487,7 @@ CPP_TEST_CASES += \
typemap_array_qualifiers \
typemap_delete \
typemap_directorout \
typemap_documentation \
typemap_global_scope \
typemap_manyargs \
typemap_namespace \

View file

@ -0,0 +1,20 @@
import typemap_documentation
f = typemap_documentation.Foo()
f.x = 55
b = typemap_documentation.Bar()
b.y = 44
if 55 != typemap_documentation.GrabVal(f):
raise RuntimeError("bad value")
try:
typemap_documentation.GrabVal(b)
raise RuntimeError("unexpected exception")
except TypeError:
pass
if 55 != typemap_documentation.GrabValFooBar(f):
raise RuntimeError("bad f value")
if 44 != typemap_documentation.GrabValFooBar(b):
raise RuntimeError("bad b value")

View file

@ -0,0 +1,50 @@
%module typemap_documentation
// A place for checking that documented typemaps are working.
// The UTL languages are the only ones that are consistent enough to support these generic typemap functions.
// These are in the Typemaps.html chapter.
%inline %{
class Foo {
public:
int x;
};
class Bar {
public:
int y;
};
%}
#if defined(SWIGUTL)
%typemap(in) Foo * {
if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
}
#endif
%inline %{
int GrabVal(Foo *f) {
return f->x;
}
%}
#if defined(SWIGUTL)
%typemap(in) Foo * {
if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
Bar *temp;
if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *), 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo or Bar");
}
$1 = (Foo *)temp;
}
}
#endif
%inline %{
int GrabValFooBar(Foo *f) {
return f->x;
}
%}