From c7d78b6c132da108a2c888b6f3baee333b535ece Mon Sep 17 00:00:00 2001
From: William S Fulton
Java is one of the few non-scripting language modules in SWIG.
@@ -2289,7 +2290,6 @@ Although directors make it natural to mix native C++ objects with Java objects (
one should be aware of the obvious fact that method calls to Java objects from C++ will be much slower than calls to C++ objects.
Additionally, compared to classes that do not use directors, the call routing in the director methods adds a small overhead.
This situation can be optimized by selectively enabling director methods (using the %feature directive) for only those methods that are likely to be extended in Java.
-The Director method recursion section details how to reduce some overhead involved in recursion checking code which is generated by default.
@@ -2353,44 +2353,6 @@ directorDerived::upcall_method() invoked.
-
-
-The Java module's director code attempts to prevent recursion from the C++ proxy class's code to Java and back through the C++ proxy class.
-The most common reason for this loop is a typo in the Java derived class, e.g., pucall_method instead of upcall_method in the following Java code:
-
@@ -131,8 +130,10 @@ The Java extension to SWIG makes it very easy to plumb in existing C/C++ code fo
It is different to using the 'javah' tool as SWIG will wrap existing C/C++ code, whereas javah takes 'native' Java function declarations and creates C/C++ function prototypes.
SWIG wraps C/C++ code using Java proxy classes and is very useful if you want to have access to large amounts of C/C++ code from Java.
If only one or two JNI functions are needed then using SWIG may be overkill.
-An important point to note is that SWIG enables a Java program to easily call into C/C++ code and not visa-versa.
-If you primarily want calls from C/C++ into Java then currently SWIG isn't particularly useful as the appropriate JNI code will have to be written by hand.
+SWIG enables a Java program to easily call into C/C++ code from Java.
+Historically, SWIG was not able to generate any code to call into Java code from C++.
+However, SWIG now supports full cross language polymorphism and code is generated to call up from C++ to Java when wrapping C++ virtual methods.
+
15.5.5 Director method recursion
-
-
-
-
-Another common typo is a mismatch between the arguments specified in the C++ method declaration and the Java subclass's method declaration.
-A
-public class directorDerived extends DirectorBase {
- public directorDerived() {
- }
-
- public void pucall_method() {
- System.out.println("directorDerived::upcall_method() invoked.");
- }
-}
-
-SWIG_JavaDirectorRicochet exception is raised in Java when this particular problem is detected at runtime.
-
-This feature can be turned off in the SWIG interface file for the entire class, -
-
-%feature("director:recursive") DirectorBase
-
-
-or selectively for individual methods:
-
-
-%feature("director:recursive") DirectorBase::upcall_method()
-
-
-
-
-%typemap(jni) Vehicle * "jobject"
-%typemap(jtype) Vehicle * "Vehicle"
-%typemap(jstype) Vehicle * "Vehicle"
-%typemap(javaout) Vehicle * {
+%typemap(jni) Vehicle *vehicle_factory "jobject"
+%typemap(jtype) Vehicle *vehicle_factory "Vehicle"
+%typemap(jstype) Vehicle *vehicle_factory "Vehicle"
+%typemap(javaout) Vehicle *vehicle_factory {
return $jnicall;
}
-%typemap(out) Vehicle * {
+%typemap(out) Vehicle *vehicle_factory {
Ambulance *ambulance = dynamic_cast<Ambulance *>($1);
FireEngine *fireengine = dynamic_cast<FireEngine *>($1);
if (ambulance) {