PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Swig | 166 lines | 122 code | 43 blank | 1 comment | 0 complexity | aac1e580ce44e68f0fc4bf72d68c6733 MD5 | raw file
  1%module mixed_types
  2
  3%warnfilter(SWIGWARN_RUBY_WRONG_NAME) hi; /* Ruby, wrong constant name */
  4%warnfilter(SWIGWARN_RUBY_WRONG_NAME) hello; /* Ruby, wrong constant name */
  5
  6%warnfilter(SWIGWARN_GO_NAME_CONFLICT);                       /* Ignoring 'hello' due to Go name ('Hello') conflict with 'Hello' */
  7
  8%inline 
  9{
 10  const void* ref_pointer(const void*& a) {
 11    return a;
 12  }
 13
 14  struct A
 15  {
 16  };
 17  
 18  const A* ref_pointer(A* const& a) {
 19    return a;
 20  }
 21
 22  const A** ref_pointer_1(const A**& a) {
 23    return a;
 24  }
 25
 26  A* pointer_1(A* a) {
 27    return a;
 28  }
 29
 30  const A& ref_const(const A& a) {
 31    return a;
 32  }
 33
 34  enum Hello { hi,hello };
 35
 36  int sint(int a) {
 37    return a;
 38  }
 39
 40  const int& ref_int(const int& a) {
 41    return a;
 42  }
 43
 44  Hello senum(Hello a) {
 45    return a;
 46  }
 47  
 48  const Hello& ref_enum(const Hello& a) {
 49    return a;
 50  }  
 51
 52  typedef A *Aptr;
 53  const Aptr& rptr_const(const Aptr& a) {
 54    return a;
 55  }
 56
 57  const Aptr& rptr_const2(const Aptr& a) {
 58    return a;
 59  }
 60
 61  const void*& rptr_void(const void*& a) {
 62    return a;
 63  }
 64
 65  const A& cref_a(const A& a) {
 66    return a;
 67  }
 68
 69  A& ref_a(A& a) {
 70    return a;
 71  }
 72
 73
 74  template <class T> struct NameT {
 75  };
 76  
 77  
 78  typedef char name[8];
 79  typedef char namea[];
 80
 81  typedef NameT<char> name_t[8];
 82  
 83  char* test_a(char hello[8],
 84	       char hi[],
 85	       const char chello[8],
 86	       const char chi[]) {
 87    return hi;
 88  }
 89
 90  int test_b(name n2) {
 91    return 1;
 92  }
 93
 94/* gcc doesn't like this one. Removing until reason resolved.*/
 95  int test_c(const name& n1) {
 96    return 1;
 97  }
 98
 99  int test_d(name* n1) {
100    return 1;
101  }
102
103  int test_e(const name_t& n1) {
104    return 1;
105  }
106
107  int test_f(name_t n1) {
108    return 1;
109  }
110
111  int test_g(name_t* n1) {
112    return 1;
113  }
114
115  struct Foo 
116  {
117    int foo(const Aptr&a);
118    int foon(const char (&a)[8]);
119  };
120
121  inline int Foo::foo(A* const& a) { return 1; }
122
123}
124
125%{
126  inline int Foo::foon(const name& a) { return a[0]; }
127%}
128
129
130
131%inline %{
132#define ARRAY_LEN_X 2
133#define ARRAY_LEN_Y 4
134
135typedef enum {One, Two, Three, Four, Five} finger;
136
137typedef struct {
138    double         double_field;
139} SimpleStruct;
140
141char           array_c [ARRAY_LEN_X][ARRAY_LEN_Y];
142signed char    array_sc[ARRAY_LEN_X][ARRAY_LEN_Y];
143unsigned char  array_uc[ARRAY_LEN_X][ARRAY_LEN_Y];
144short          array_s [ARRAY_LEN_X][ARRAY_LEN_Y];
145unsigned short array_us[ARRAY_LEN_X][ARRAY_LEN_Y];
146int            array_i [ARRAY_LEN_X][ARRAY_LEN_Y];
147unsigned int   array_ui[ARRAY_LEN_X][ARRAY_LEN_Y];
148long           array_l [ARRAY_LEN_X][ARRAY_LEN_Y];
149unsigned long  array_ul[ARRAY_LEN_X][ARRAY_LEN_Y];
150long long      array_ll[ARRAY_LEN_X][ARRAY_LEN_Y];
151float          array_f [ARRAY_LEN_X][ARRAY_LEN_Y];
152double         array_d [ARRAY_LEN_X][ARRAY_LEN_Y];
153SimpleStruct   array_struct[ARRAY_LEN_X][ARRAY_LEN_Y];
154SimpleStruct*  array_structpointers[ARRAY_LEN_X][ARRAY_LEN_Y];
155int*           array_ipointers [ARRAY_LEN_X][ARRAY_LEN_Y];
156finger         array_enum[ARRAY_LEN_X][ARRAY_LEN_Y];
157finger*        array_enumpointers[ARRAY_LEN_X][ARRAY_LEN_Y];
158const int      array_const_i[ARRAY_LEN_X][ARRAY_LEN_Y] = { {10, 11, 12, 13}, {14, 15, 16, 17} };
159
160void fn_taking_arrays(SimpleStruct array_struct[ARRAY_LEN_X][ARRAY_LEN_Y]) {}
161
162int get_2d_array(int (*array)[ARRAY_LEN_Y], int x, int y){
163    return array[x][y];
164}
165%}
166