Consider a SomeClass.h
with the following functions declared
void doSomethingSimple(double);
void dealWithComplexClasses(ComplexClass&);
I want to expose doSomethingSimple(double)
in Java, but NOT dealWithComplexClasses(ComplexClass&)
I have tried various things such as:
%ignore SomeClass::dealWithComplexClasses(ComplexClass&);
%ignore SomeClass::dealWithComplexClasses;
I also found this SO question which is answered but did not help me (while the problem is similar so I must be missing something)
But in the end Swig always creates a proxy java class for ComplexClass and there is a dealWithComplexClasses(SWIGTYPE_p_ComplexClass class)
in the SomeClass.java
How can I tell Swig to generate code only for what I want to expose in Java ? Or to ignore functions and classes I don't want to expose?
The SWIG parser can handle simple C++ class definitions and supports public inheritance, virtual functions, static functions, constructors and destructors. Currently, C++ translation is performed by politely tranforming C++ code into C code and generating wrappers for the C functions.
The Simplified Wrapper and Interface Generator (SWIG) is an open-source software tool used to connect computer programs or libraries written in C or C++ with scripting languages such as Lua, Perl, PHP, Python, R, Ruby, Tcl, and other languages like C#, Java, JavaScript, Go, D, OCaml, Octave, Scilab and Scheme.
The Java extension to SWIG makes it very easy to plumb in existing C/C++ code for access from Java, as SWIG writes the Java Native Interface (JNI) code for you.
You are doing the right thing. The %ignore SomeClass::dealWithComplexClasses
should have worked so I suspect you were trying other things at the same time and interpreted errors as indication that this hadn't worked. Try:
%ignore ComplexClass; // will not wrap ComplexClass
%ignore SomeClass::dealWithComplexClasses; // do not wrap that method or any of its overloads
Another possibility but can't tell from your post, is that your class is in a namespace. In this case you need the namespace prepended.
If it still doesn't work, need more info, post a minimal .i and .h for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With