import source from 1.3.40
[external/swig.git] / Examples / test-suite / java_lib_arrays.i
1 /* Testcase for the Java array typemaps which are not used by default. */
2 %module java_lib_arrays
3
4 %include "enumtypeunsafe.swg"
5
6 /* Use the Java library typemaps */
7 %include "arrays_java.i"
8
9 JAVA_ARRAYSOFCLASSES(SimpleStruct)
10 %apply ARRAYSOFENUMS[ANY] { finger[ANY] }
11
12 %include "arrays.i"
13
14 // This will test the %typemap(javacode) in the JAVA_ARRAYSOFCLASSES works with C structs amongst other things
15 JAVA_ARRAYSOFCLASSES(struct AnotherStruct)
16 %inline %{
17 struct AnotherStruct {
18         SimpleStruct  simple;
19 };
20 double extract(struct AnotherStruct as[], int index) {
21   return as[index].simple.double_field;
22 }
23 double extract2(struct AnotherStruct as[5], int index) {
24   return as[index].simple.double_field;
25 }
26 %}
27
28 // Test %apply to pointers
29 JAVA_ARRAYSOFCLASSES(struct YetAnotherStruct)
30 %apply struct YetAnotherStruct[] { struct YetAnotherStruct *yas }
31 //%apply struct YetAnotherStruct[] { struct YetAnotherStruct * } // Note: Does not work unless this is put after the YetAnotherStruct definition
32 %inline %{
33 struct YetAnotherStruct {
34         SimpleStruct  simple;
35 };
36 double extract_ptr(struct YetAnotherStruct *yas, int index) {
37   return yas[index].simple.double_field;
38 }
39 void modifyYAS(struct YetAnotherStruct yas[], int size) {
40   int i;
41   for (i=0; i<size; ++i) {
42     SimpleStruct ss;
43     ss.double_field = yas[i].simple.double_field * 10.0;
44     yas[i].simple = ss;
45   }
46 }
47 %}
48
49 %apply ARRAYSOFENUMS[ANY] { toe[ANY] }
50 %apply ARRAYSOFENUMS[] { toe[] }
51 %apply ARRAYSOFENUMS[] { toe* }
52 %inline %{
53 typedef enum { Big, Little } toe;
54 void toestest(toe *t, toe tt[], toe ttt[2]) {}
55 %}
56