473,569 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use an array of struct in java using SWIG

21 New Member
Hello All,

I have a function in C++ that takes an array of struct. I want to convert this function to java using SWIG.

Here what I have

structs.h

Expand|Select|Wrap|Line Numbers
  1. typedef struct myStruct{
  2.    char name;
  3.    int type;
  4.  
  5. void Foo( myStruct * mystr){
  6.   //do something
  7. }
In C++ driver (and this works fine)

Expand|Select|Wrap|Line Numbers
  1. #include "structs.h"
  2. myStruct structTest[5];  //an array
  3. structTest[0].name="me";
  4. structTest[0].type='1';
...
SWIG ...
I included this header in my interface file and it generates all the classes.

.... Here is what I did in my Java driver

Expand|Select|Wrap|Line Numbers
  1. myStruct jtest=new myStruct();
  2. jtest.setName("me");
  3. jtest.setType("1");
  4. Foo(jtest);
This worked fine however, I can only do one item at a time. Is there away I create an array of myStruct like I did in C++? I tried but got some errors. Here is one thing I tried:

Expand|Select|Wrap|Line Numbers
  1. myStruct jtest[] = new myStruct();
Can any one help? I will appreciate it.

Regards,
Jazi
Oct 22 '07 #1
4 7937
Laharl
849 Recognized Expert Contributor
I'm not familiar with SWIG, but Java array syntax is

Expand|Select|Wrap|Line Numbers
  1. MyStruct[] array = new MyStruct[5];
  2.  
Oct 22 '07 #2
Jazi
21 New Member
I'm not familiar with SWIG, but Java array syntax is

Expand|Select|Wrap|Line Numbers
  1. MyStruct[] array = new MyStruct[5];
  2.  
Thanks Kaharl,
Here is what I did

myStruct[] jtest=new myStruct[5];
Foo(jtest);

The syntax seems to be correct but it does not seem to like it

mydriver.java:3 0: Foo(jtest) in structs cannot be applied to (jtest[])
Foo(jtest);
^
1 error

The argument of this function should be a pointer and now it does not like it because it is an array. Any other explanations?

Thanks
Oct 23 '07 #3
Ganon11
3,652 Recognized Expert Specialist
The way SWIG translated your Foo function, it expects a single myStruct variable. Maybe you can, in your C++ code, change the function header to expect a myStruct mystr[] instead of a myStruct * mystr.
Oct 23 '07 #4
Jazi
21 New Member
The way SWIG translated your Foo function, it expects a single myStruct variable. Maybe you can, in your C++ code, change the function header to expect a myStruct mystr[] instead of a myStruct * mystr.
I did that but it does not seem to make any difference. I keep getting the same results and therefore the same error. Somehow I need to tell it this is a java array and it has to be done at the interface file level but I am not familiar with it.

Thanks for your tip.
Oct 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
7162
by: Carl Waldbieser | last post by:
I tried to adapt the instructions for building the M2Crypto module (http://sandbox.rulemaker.net/ngps/m2/INSTALL.html) to build a version compatible with Python2.3, but I've had some mixed results. I actually got everything to build and install, but when I try to import M2Crypto-- well, here is a sample session: >>> import M2Crypto...
14
2843
by: Joachim Boomberschloss | last post by:
Hello, I am working on a project in Python, and I"m currently looking into the possibiliy of writing some of the project"s modules in Java. Given that a large part of the code is already written in Python, using the standard libraries and several extension modules, I am trying to gauge the viability of integration with
2
2233
by: SunMan | last post by:
Hello! I am trying to create a program that will ask for a user to enter a series of letters (codes) and then print out a table that shows the codes in decending frequency. Only letters will be read into the array. I have created a struct and array like below. struct record { char inputChar;
7
26124
by: Jamil Anwar Zaman | last post by:
If I dynamically allocate memory to a pointer, then is it possible to see afterwards what is the memory size the pointer is looking at. e.g int SIZE = 10; int *a = malloc(SIZE*sizeof(int)); printf("Size : %d", sizeof(a)); this actually gives me 4 bytes, which essentially is the sizeof the pointer. But I want to know the actual memory...
22
2432
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a nightmare. There are of course many solutions, but they all end up forcing you to abandon the array syntax in favour of macros or functions. Now...
5
7313
by: Krish | last post by:
Hello People I hope I am On Topic. Anyways, here is my problem. Any insights would be really appreciated. I have wrapped a C IO module using SWIG -> Python Module. Suppose the name of the module is "imageio" and the reader function from the file is image_read() which returns an object ( "filled" C structure) with a lot of members.
3
3201
by: Sudheer Gupta | last post by:
Hi, I am having trouble using C struct in python. Hope anyone can help me out ... Say, I have my C struct as typedef struct call { struct call *next;
0
1651
by: Jazi | last post by:
I would appreciate if someone can help me dealing with wrapping java around c++ using SWIG. I have wrapped simple classes without any problem but I had some difficulties getting a vector function working. Here is what I have. I have two classes in C++; Fold class and Subs class. In the Subs class there is a method called get_all_folds that...
5
7215
by: emmanuel.rivoire | last post by:
Hello, I spent almost a week to be able to embed Python within my C++ game engine. I wrote a mini-tutorial of what I was able to do so far here : http://forums.indiegamer.com/showpost.php?p=169352&postcount=9 At the end of my tutorial, I wrote : "You can do the same with C++ classes, and with structures within structures. Swig can parse...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.