PageRenderTime 15ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/constant_pointers.i

#
Swig | 143 lines | 106 code | 34 blank | 3 comment | 0 complexity | 68c800f94cfd93f132107ac69e198db3 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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
  9%inline %{
 10
 11int        GlobalInt;
 12const int  ConstInt=2;
 13int*       GlobalIntPtr=&GlobalInt;
 14int* const GlobalConstIntPtr=&GlobalInt;
 15#define ARRAY_SIZE 2
 16
 17class ParametersTest {
 18public:
 19    void param1(int* a) {}
 20    void param2(const int* a) {}
 21    void param3(int* const a) {}
 22    void param4(int const a) {}
 23    void param5(const int a) {}
 24    void param6(int& a) {}
 25    void param7(const int& a) {}
 26    void param8(int const& a) {}
 27    void param9(int*& a) {}
 28    void param10(int* const& a) {}
 29    void param11(const int* const a) {}
 30
 31    void param_array1(int* a[ARRAY_SIZE]) {}
 32    void param_array2(const int* a[ARRAY_SIZE]) {}
 33    void param_array3(int* const a[ARRAY_SIZE]) {}
 34    void param_array4(int const a[ARRAY_SIZE]) {}
 35    void param_array5(const int a[ARRAY_SIZE]) {}
 36    void param_array6(const int* const a[ARRAY_SIZE]) {}
 37};
 38
 39class MemberVariablesTest {
 40public:
 41    int* member1;
 42    ParametersTest* member2;
 43    int* const member3;
 44    ParametersTest* const member4;
 45
 46    int* array_member1[ARRAY_SIZE];
 47    ParametersTest* array_member2[ARRAY_SIZE];
 48    MemberVariablesTest() : member3(NULL), member4(NULL) {}
 49};
 50void foo(const int *const i) {}
 51
 52typedef int *typedef1, typedef2, *const typedef3;
 53int int1, int2=2, *int3, *const int4 = &GlobalInt;
 54
 55int* const global_const_int_ptr_array[ARRAY_SIZE] = { &int1, &int2 };
 56ParametersTest* const array_member4[ARRAY_SIZE] = { new ParametersTest(), new ParametersTest() };
 57
 58class ReturnValuesTest {
 59public:
 60    typedef1 td1;
 61    typedef2 td2;
 62    int int1, int2, *const int3, *int4, array1[ARRAY_SIZE];
 63    int ret1() {return 5;}
 64    const int ret2() {return 5;}
 65    int ret3() {return 5;}
 66    const int* ret4() {return &ConstInt;}
 67    int* const ret5() {return &GlobalInt;}
 68
 69    void ret6(int*& a) {}
 70    int*& ret7() {return GlobalIntPtr;}
 71    ReturnValuesTest() : int3(NULL) {}
 72};
 73
 74const int* globalRet1() {return &GlobalInt;}
 75int* const globalRet2() {return &GlobalInt;}
 76
 77%}
 78
 79
 80%{
 81  struct A
 82  {
 83  };
 84%}
 85
 86
 87%inline 
 88{
 89  typedef const A* Acptr;
 90
 91  Acptr opaque(Acptr aptr) {
 92    return aptr;
 93  }
 94
 95  struct B
 96  {
 97    B() : ca() {}
 98    const A ca;
 99    A a;
100    A* ap;
101    const A* cap;
102    Acptr acptr;  
103  };
104
105  const B* bar(const B* b) {
106    return b;
107  }
108
109  B const*& cbar(B const*& b) {
110    return b;
111  }
112}
113
114
115
116%{
117static int wxEVT_COMMAND_BUTTON_CLICKEDv;
118static int **wxEVT_COMMAND_BUTTON_CLICKEDp;
119char *langs[] ={"Hello"};
120 
121     
122%}
123
124
125%inline {
126#define EWXWEXPORT_VAR 
127
128  const int* wxEVENT_COMMAND_BUTTON_CLICKEDr = (int*) &wxEVT_COMMAND_BUTTON_CLICKEDv;
129  const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDp;
130  char **languages1 = &langs[0];
131  char **languages2 = (char **)&langs[0];
132}
133
134%inline %{
135struct Foo {
136  const int *icap;
137};
138const int* icap;
139const Foo *cap;
140%}
141
142
143