From: Jepson, D. \(London\) <DJ...@ma...> - 2008-09-05 17:26:43
|
Hi - I'm a beginner with SWIG and looking for some help. I am having problems mapping a struct member, which is an array of struct pointers. The C follows, and it is the mapping of Nested I am having trouble with. In Thing, Nested is set with public void setNested(SWIGTYPE_p_p_Nested nested) { MQJNI.set_Thing_nested(swigCPtr, SWIGTYPE_p_p_Nested.getCPtr(nested)); } My Java compilation fails with +++++++++++++++++++++++++++++++ TestMQ.java:15: setNested(SWIGTYPE_p_p_Nested) in Thing cannot be applied to (Nested[]) thing[t].setNested(nested); ^ 1 error +++++++++++++++++++++++++++++++ So my question is, how am I supposed to call this from the Java? Do I need to do something with SWIG typemaps? Take a look at the Java test case - it shows I need to be able to construct Thing and Nested in the Java, and pass it into the C. Listings follow, but please let me know if you need anything else, Thanks, Dave The C header +++++++++++++++++++++++++++++++ struct Nested { int count; }; struct Thing { struct Nested *nested[MAXSIZE_NESTED]; }; double calc(struct Thing thing[MAXSIZE_THING]); +++++++++++++++++++++++++++++++ The SWIG file +++++++++++++++++++++++++++++++ %module MQ %include "typemaps.i" %include "arrays_java.i" %{ #include "sg.h" %} JAVA_ARRAYSOFCLASSES(Thing) #define MAXSIZE_NESTED 10 #define MAXSIZE_THING 20 struct Nested { int count; }; struct Thing { struct Nested *nested[MAXSIZE_NESTED]; }; double calc(struct Thing thing[MAXSIZE_THING]); +++++++++++++++++++++++++++++++ My Java test case. +++++++++++++++++++++++++++++++ class TestMQ { public static void main (String[] args) { System.loadLibrary("mqwrap"); // function parameters Thing[] thing = new Thing[MQConstants.MAXSIZE_THING]; for ( int t = 0; t < MQConstants.MAXSIZE_THING; t++ ) { Nested[] nested = new Nested[MQConstants.MAXSIZE_NESTED]; thing[t].setNested(nested); for ( int n = 0; n < MQConstants.MAXSIZE_NESTED; n++ ) { nested[n].setCount(2); } } System.out.println("TestMQ"); System.out.println("calc=" + MQ.calc(thing)); } } +++++++++++++++++++++++++++++++ ********************************************************************** The contents of this email are for the named addressee(s) only. It contains information which may be confidential and privileged. If you are not the intended recipient, please notify the sender immediately, destroy this email and any attachments and do not otherwise disclose or use them. Email transmission is not a secure method of communication and Man Investments cannot accept responsibility for the completeness or accuracy of this email or any attachments. Whilst Man Investments makes every effort to keep its network free from viruses, it does not accept responsibility for any computer virus which might be transferred by way of this email or any attachments. This email does not constitute a request, offer, recommendation or solicitation of any kind to buy, subscribe, sell or redeem any investment instruments or to perform other such transactions of any kind. Man Investments reserves the right to monitor, record and retain all electronic communications through its network to ensure the integrity of its systems, for record keeping and regulatory purposes. Visit us at: www.maninvestments.com ********************************************************************** |