From ef14c8a6f685c5ad47fae2261be5225812ea2256 Mon Sep 17 00:00:00 2001
From: William S Fulton
+All the rules discussed for Typemaps apply to C++ as well as C. +However in addition C++ passes an extra parameter into every +non-static class method -- the this pointer. Occasionally it can be +useful to apply a typemap to this pointer (for example to check +and make sure this is non-null before deferencing). +Actually, C also has an the equivalent of the this pointer which is used +when accessing variables in a C struct. +
++In order to customise the this pointer handling, target a variable named self in your typemaps. +self is the name SWIG uses to refer to the extra parameter in wrapped functions. +
++For example, if wrapping for Java generation: +
+ +
+%typemap(check) SWIGTYPE *self %{
+if (!$1) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "swigCPtr null");
+ return $null;
+}
+%}
+
++In the above case, the $1 variable is expanded into the argument +name that SWIG is using as the this pointer. + +SWIG will then insert the check code before the actual C++ class method +is called, and will raise an exception rather than crash +the Java virtual machine. + +The generated code will look something like: +
+ +
+ if (!arg1) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException,
+ "invalid native object; delete() likely already called");
+ return ;
+ }
+ (arg1)->wrappedFunction(...);
+
++Note that if you have a parameter named self then it +will also match the typemap. One work around is to create an interface file that wraps +the method, but give the argument a name other than self. +
+ +The