summaryrefslogtreecommitdiff
path: root/Examples/test-suite/csharp_lib_arrays_bool.i
blob: 58cee9d804dc685047216639f8369aa3287f362e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
%module csharp_lib_arrays_bool

%include "arrays_csharp.i"

%apply bool INPUT[] { bool* sourceArray }
%apply bool OUTPUT[] { bool* targetArray }

%apply bool INOUT[] { bool* array1 }
%apply bool INOUT[] { bool* array2 }

%inline %{
#include <iostream>

/* copy the contents of the first array to the second */
void myArrayCopyBool( bool* sourceArray, bool* targetArray, int nitems ) {
  int i;
  for ( i = 0; i < nitems; i++ ) {
    targetArray[ i ] = sourceArray[ i ];
  }
}

/* swap the contents of the two arrays */
void myArraySwapBool( bool* array1, bool* array2, int nitems ) {
  int i;
  bool temp;
  for ( i = 0; i < nitems; i++ ) {
    temp = array1[ i ];
    array1[ i ] = array2[ i ];
    array2[ i ] = temp;
  }
}

bool checkBoolArrayCorrect( bool* sourceArray, int sourceArraySize ) {
  if( sourceArraySize != 8 ) {
    std::cout << "checkBoolArrayCorrect: Expected array with 8 elements" << std::endl;
    return false;
  }
  return sourceArray[0] == true &&
         sourceArray[1] == false &&
         sourceArray[2] == false &&
         sourceArray[3] == true &&
         sourceArray[4] == false &&
         sourceArray[5] == true &&
         sourceArray[6] == true &&
         sourceArray[7] == false;
}
%}

%clear bool* sourceArray;
%clear bool* targetArray;

%clear bool* array1;
%clear bool* array2;

// Below replicates the above array handling but this time using the pinned (fixed) array typemaps
%csmethodmodifiers myArrayCopyUsingFixedArraysBool "public unsafe";
%csmethodmodifiers myArraySwapUsingFixedArraysBool "public unsafe";

%apply bool FIXED[] { bool* sourceArray }
%apply bool FIXED[] { bool* targetArray }

%inline %{
void myArrayCopyUsingFixedArraysBool( bool *sourceArray, bool* targetArray, int nitems ) {
  myArrayCopyBool(sourceArray, targetArray, nitems);
}
%}

%apply bool FIXED[] { bool* array1 }
%apply bool FIXED[] { bool* array2 }

%inline %{
void myArraySwapUsingFixedArraysBool( bool* array1, bool* array2, int nitems ) {
  myArraySwapBool(array1, array2, nitems);
}
%}