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

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

#
Swig | 61 lines | 43 code | 16 blank | 2 comment | 0 complexity | 3da58ccd42e8c984f45b44f2d016b242 MD5 | raw file
 1%module csharp_lib_arrays
 2
 3%include "arrays_csharp.i"
 4
 5%apply int INPUT[]  { int* sourceArray }
 6%apply int OUTPUT[] { int* targetArray }
 7
 8%apply int INOUT[] { int* array1 }
 9%apply int INOUT[] { int* array2 }
10
11%inline %{
12/* copy the contents of the first array to the second */
13void myArrayCopy( int* sourceArray, int* targetArray, int nitems ) {
14  int i;
15  for ( i = 0; i < nitems; i++ ) {
16    targetArray[ i ] = sourceArray[ i ];
17  }
18}
19
20/* swap the contents of the two arrays */
21void myArraySwap( int* array1, int* array2, int nitems ) {
22  int i, temp;
23  for ( i = 0; i < nitems; i++ ) {
24    temp = array1[ i ];
25    array1[ i ] = array2[ i ];
26    array2[ i ] = temp;
27  }
28}
29%}
30
31
32%clear int* sourceArray;
33%clear int* targetArray;
34
35%clear int* array1;
36%clear int* array2;
37
38
39// Below replicates the above array handling but this time using the pinned (fixed) array typemaps
40%csmethodmodifiers myArrayCopyUsingFixedArrays "public unsafe";
41%csmethodmodifiers myArraySwapUsingFixedArrays "public unsafe";
42
43%apply int FIXED[] { int* sourceArray }
44%apply int FIXED[] { int* targetArray }
45
46%inline %{
47void myArrayCopyUsingFixedArrays( int *sourceArray, int* targetArray, int nitems ) {
48  myArrayCopy(sourceArray, targetArray, nitems);
49}
50%}
51
52%apply int FIXED[] { int* array1 }
53%apply int FIXED[] { int* array2 }
54
55%inline %{
56void myArraySwapUsingFixedArrays( int* array1, int* array2, int nitems ) {
57  myArraySwap(array1, array2, nitems);
58}
59%}
60
61