Reputation: 9827
I have the below structure in my SWIG interface file and thusly my sample.h header file. I'm assuming the sockaddr, ios_boolean and unsigned char definitions from this structure are the reason why I get the below generated classes. If I know the type on that ios_boolean and unsigned char map to on the Java side is there a way to use an %apply to get rid of the generated pointer classes? I tried %apply int {ios_boolean}; but then I get a SWIGTYPE_p_boolean.java. Any ideas?
%rename (Sample) sample_details_t_;
typedef struct sample_details_t_ {
ios_boolean is_allowed;
unsigned char mac[11];
} sample_t;
generates:
SWIGTYPE_p_unsigned_char.java
SWIGTYPE_p_ios_boolean.java
Exception:
[exec] ewapi_wrap.c:982: error: `true' undeclared (first use in this function)
[exec] ewapi_wrap.c:982: error: (Each undeclared identifier is reported only once
[exec] ewapi_wrap.c:982: error: for each function it appears in.)
[exec] ewapi_wrap.c:982: error: `false' undeclared (first use in this function
Upvotes: 1
Views: 1167
Reputation: 88721
You probably want to do something like:
%include <arrays_java.i>
%rename (Sample) sample_details_t_;
%apply bool { ios_boolean };
typedef struct sample_details_t_ {
ios_boolean is_allowed;
unsigned char mac[11];
} sample_t;
This wraps mac
as short[]
(with constraints on the array size) and is_allowed
as boolean
on the Java side and results in these files:
Sample.java test.java testJNI.java
Make sure you delete any old SWIGTYPE_*.java
files that are lying around from older versions of your SWIG interface, they won't get deleted automatically and might fail to compile if you do something like javac *.java
.
Upvotes: 2