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

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

#
Swig | 159 lines | 120 code | 36 blank | 3 comment | 0 complexity | 4ef652e9eace48e57723bb69640f17aa MD5 | raw file
  1/*
  2This 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.
  3*/
  4
  5%module constant_pointers
  6
  7%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);                   /* memory leak when setting a ptr/ref variable */
  8%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG);               /* Setting a pointer/reference variable may leak memory. */
  9 
 10
 11%inline %{
 12
 13int        GlobalInt;
 14const int  ConstInt=2;
 15int*       GlobalIntPtr=&GlobalInt;
 16int* const GlobalConstIntPtr=&GlobalInt;
 17#define ARRAY_SIZE 2
 18
 19class ParametersTest {
 20public:
 21    void param1(int* a) {}
 22    void param2(const int* a) {}
 23    void param3(int* const a) {}
 24    void param4(int const a) {}
 25    void param5(const int a) {}
 26    void param6(int& a) {}
 27    void param7(const int& a) {}
 28    void param8(int const& a) {}
 29    void param9(int*& a) {}
 30    void param10(int* const& a) {}
 31    void param11(const int* const a) {}
 32
 33    void param_array1(int* a[ARRAY_SIZE]) {}
 34    void param_array2(const int* a[ARRAY_SIZE]) {}
 35    void param_array3(int* const a[ARRAY_SIZE]) {}
 36    void param_array4(int const a[ARRAY_SIZE]) {}
 37    void param_array5(const int a[ARRAY_SIZE]) {}
 38    void param_array6(const int* const a[ARRAY_SIZE]) {}
 39};
 40
 41class MemberVariablesTest {
 42public:
 43    int* member1;
 44    ParametersTest* member2;
 45    int* const member3;
 46    ParametersTest* const member4;
 47
 48    int* array_member1[ARRAY_SIZE];
 49    ParametersTest* array_member2[ARRAY_SIZE];
 50    MemberVariablesTest() : member3(NULL), member4(NULL) {}
 51private:
 52  MemberVariablesTest& operator=(const MemberVariablesTest&);
 53};
 54void foofunction(const int *const i) {}
 55
 56typedef int *typedef1, typedef2, *const typedef3;
 57int int1, int2=2, *int3, *const int4 = &GlobalInt;
 58
 59int* const global_const_int_ptr_array[ARRAY_SIZE] = { &int1, &int2 };
 60ParametersTest* const array_member4[ARRAY_SIZE] = { new ParametersTest(), new ParametersTest() };
 61
 62class ReturnValuesTest {
 63public:
 64    typedef1 td1;
 65    typedef2 td2;
 66    int int1, int2, *const int3, *int4, array1[ARRAY_SIZE];
 67    int ret1() {return 5;}
 68    const int ret2() {return 5;}
 69    int ret3() {return 5;}
 70    const int* ret4() {return &ConstInt;}
 71    int* const ret5() {return &GlobalInt;}
 72
 73    void ret6(int*& a) {}
 74    int*& ret7() {return GlobalIntPtr;}
 75    void ret8(int*const& a) {}
 76    int*const& ret9() {return GlobalIntPtr;}
 77    ReturnValuesTest() : int3(NULL) {}
 78private:
 79  ReturnValuesTest& operator=(const ReturnValuesTest&);
 80};
 81
 82const int* globalRet1() {return &GlobalInt;}
 83int* const globalRet2() {return &GlobalInt;}
 84
 85%}
 86
 87
 88%{
 89  struct A
 90  {
 91  };
 92%}
 93
 94
 95%inline 
 96{
 97  typedef const A* Acptr;
 98
 99  Acptr opaque(Acptr aptr) {
100    return aptr;
101  }
102
103  struct B
104  {
105    B() : ca() {}
106    const A ca;
107    A a;
108    A* ap;
109    const A* cap;
110    Acptr acptr;  
111  private:
112    B& operator=(const B&);
113  };
114
115  const B* bar(const B* b) {
116    return b;
117  }
118
119  B *const& cbar(B *const& b) {
120    return b;
121  }
122}
123
124
125
126%{
127static int wxEVT_COMMAND_BUTTON_CLICKEDv;
128static int *wxEVT_COMMAND_BUTTON_CLICKEDp;
129static int **wxEVT_COMMAND_BUTTON_CLICKEDpp = &wxEVT_COMMAND_BUTTON_CLICKEDp;
130#if defined(SWIGR)
131#undef lang1 /* conflicts with symbol in R internals */
132#endif
133
134char lang1[16] = "Hello";
135char *langs[] ={ lang1 };
136 
137     
138%}
139
140
141%inline {
142#define EWXWEXPORT_VAR 
143
144  const int* wxEVENT_COMMAND_BUTTON_CLICKEDr = (int*) &wxEVT_COMMAND_BUTTON_CLICKEDv;
145  const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDpp;
146  char **languages1 = &langs[0];
147  char **languages2 = (char **)&langs[0];
148}
149
150%inline %{
151struct Foo {
152  const int *icap;
153};
154const int* icap;
155const Foo *cap;
156%}
157
158
159