summaryrefslogtreecommitdiff
path: root/Examples/test-suite/constant_pointers.i
blob: 1e03b29cabe22494e7b144887244f71de7ba0660 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
This testcase primarily test constant pointers, eg int* const.  Only a getter is expected to be produced when wrapping constant pointer variables. A number of other const issues are also tested.
*/

%module constant_pointers

#if defined(SWIGSCILAB)
%rename(MbrVar) MemberVariablesTest;
%rename(RetVal) ReturnValuesTest;
#endif

%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);                   /* memory leak when setting a ptr/ref variable */
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG);               /* Setting a pointer/reference variable may leak memory. */
 

%inline %{

int        GlobalInt;
const int  ConstInt=2;
int*       GlobalIntPtr=&GlobalInt;
int* const GlobalConstIntPtr=&GlobalInt;
#define ARRAY_SIZE 2

class ParametersTest {
public:
    void param1(int* a) {}
    void param2(const int* a) {}
    void param3(int* const a) {}
    void param4(int const a) {}
    void param5(const int a) {}
    void param6(int& a) {}
    void param7(const int& a) {}
    void param8(int const& a) {}
    void param9(int*& a) {}
    void param10(int* const& a) {}
    void param11(const int* const a) {}

    void param_array1(int* a[ARRAY_SIZE]) {}
    void param_array2(const int* a[ARRAY_SIZE]) {}
    void param_array3(int* const a[ARRAY_SIZE]) {}
    void param_array4(int const a[ARRAY_SIZE]) {}
    void param_array5(const int a[ARRAY_SIZE]) {}
    void param_array6(const int* const a[ARRAY_SIZE]) {}
};

class MemberVariablesTest {
public:
    int* member1;
    ParametersTest* member2;
    int* const member3;
    ParametersTest* const member4;

    int* array_member1[ARRAY_SIZE];
    ParametersTest* array_member2[ARRAY_SIZE];
    MemberVariablesTest() : member3(NULL), member4(NULL) {}
};
void foofunction(const int *const i) {}

typedef int *typedef1, typedef2, *const typedef3;
int int1, int2=2, *int3, *const int4 = &GlobalInt;

int* const global_const_int_ptr_array[ARRAY_SIZE] = { &int1, &int2 };
ParametersTest* const array_member4[ARRAY_SIZE] = { new ParametersTest(), new ParametersTest() };

class ReturnValuesTest {
public:
    typedef1 td1;
    typedef2 td2;
    int int1, int2, *const int3, *int4, array1[ARRAY_SIZE];
    int ret1() {return 5;}
    const int ret2() {return 5;}
    int ret3() {return 5;}
    const int* ret4() {return &ConstInt;}
    int* const ret5() {return &GlobalInt;}

    void ret6(int*& a) {}
    int*& ret7() {return GlobalIntPtr;}
    void ret8(int*const& a) {}
    int*const& ret9() {return GlobalIntPtr;}
    ReturnValuesTest() : int3(NULL) {}
};

const int* globalRet1() {return &GlobalInt;}
int* const globalRet2() {return &GlobalInt;}

%}


%{
  struct A
  {
  };
%}


%inline 
{
  typedef const A* Acptr;

  Acptr opaque(Acptr aptr) {
    return aptr;
  }

  struct B
  {
    B() : ca() {}
    const A ca;
    A a;
    A* ap;
    const A* cap;
    Acptr acptr;  
  };

  const B* bar(const B* b) {
    return b;
  }

  B *const& cbar(B *const& b) {
    return b;
  }
}



%{
static int wxEVT_COMMAND_BUTTON_CLICKEDv;
static int *wxEVT_COMMAND_BUTTON_CLICKEDp;
static int **wxEVT_COMMAND_BUTTON_CLICKEDpp = &wxEVT_COMMAND_BUTTON_CLICKEDp;
#if defined(SWIGR)
#undef lang1 /* conflicts with symbol in R internals */
#endif

char lang1[16] = "Hello";
char *langs[] ={ lang1 };
 
     
%}


%inline {
#define EWXWEXPORT_VAR 

  const int* wxEVENT_COMMAND_BUTTON_CLICKEDr = (int*) &wxEVT_COMMAND_BUTTON_CLICKEDv;
  const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDpp;
  char **languages1 = &langs[0];
  char **languages2 = (char **)&langs[0];
}

%inline %{
struct Foo {
  const int *icap;
};
const int* icap;
const Foo *cap;
%}