PageRenderTime 32ms CodeModel.GetById 27ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/java_lib_arrays.i

#
Swig | 69 lines | 57 code | 10 blank | 2 comment | 0 complexity | 6e530fc9997402bd082e7fb3f816030d MD5 | raw file
 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
 9JAVA_ARRAYSOFCLASSES(SimpleStruct)
10%apply ARRAYSOFENUMS[ANY] { finger[ANY] }
11//%apply signed char[ANY] { char array_c2[ANY] }
12
13%include "arrays.i"
14
15// This will test the %typemap(javacode) in the JAVA_ARRAYSOFCLASSES works with C structs amongst other things
16JAVA_ARRAYSOFCLASSES(struct AnotherStruct)
17%inline %{
18struct AnotherStruct {
19	SimpleStruct  simple;
20};
21double extract(struct AnotherStruct as[], int index) {
22  return as[index].simple.double_field;
23}
24double extract2(struct AnotherStruct as[5], int index) {
25  return as[index].simple.double_field;
26}
27%}
28
29// Test %apply to pointers
30JAVA_ARRAYSOFCLASSES(struct YetAnotherStruct)
31%apply struct YetAnotherStruct[] { struct YetAnotherStruct *yas }
32//%apply struct YetAnotherStruct[] { struct YetAnotherStruct * } // Note: Does not work unless this is put after the YetAnotherStruct definition
33%inline %{
34struct YetAnotherStruct {
35	SimpleStruct  simple;
36};
37double extract_ptr(struct YetAnotherStruct *yas, int index) {
38  return yas[index].simple.double_field;
39}
40void modifyYAS(struct YetAnotherStruct yas[], int size) {
41  int i;
42  for (i=0; i<size; ++i) {
43    SimpleStruct ss;
44    ss.double_field = yas[i].simple.double_field * 10.0;
45    yas[i].simple = ss;
46  }
47}
48%}
49
50%apply ARRAYSOFENUMS[ANY] { toe[ANY] }
51%apply ARRAYSOFENUMS[] { toe[] }
52%apply ARRAYSOFENUMS[] { toe* }
53%inline %{
54typedef enum { Big, Little } toe;
55void toestest(toe *t, toe tt[], toe ttt[2]) {}
56%}
57
58
59JAVA_ARRAYS_IMPL(char, jbyte, Byte, Char)
60JAVA_ARRAYS_TYPEMAPS(char, byte, jbyte, Char, "[B")
61%typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */
62    signed char[ANY], signed char[]
63    ""
64
65%inline %{
66struct ArrayStructExtra {
67	char           array_c2[ARRAY_LEN];
68};
69%}