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

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

#
Swig | 238 lines | 194 code | 42 blank | 2 comment | 0 complexity | 87d9f5507a59786a962dd682a5eebd3f MD5 | raw file
  1%module contract
  2
  3%warnfilter(SWIGWARN_RUBY_MULTIPLE_INHERITANCE,
  4	    SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
  5	    SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
  6	    SWIGWARN_D_MULTIPLE_INHERITANCE,
  7	    SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, D, Java, PHP multiple inheritance */
  8
  9#ifdef SWIGCSHARP
 10%ignore B::bar; // otherwise get a warning: `C.bar' no suitable methods found to override
 11#endif
 12
 13#ifdef SWIGD
 14%ignore B::bar; // Prevents getting an error that C.bar does not override any function because multiple inheritance is not supported.
 15#endif
 16
 17%contract test_preassert(int a, int b) {
 18require:
 19	a > 0;
 20	b > 0;
 21}
 22
 23%contract test_postassert(int a) {
 24ensure:
 25	test_postassert > 0;
 26}
 27
 28%contract test_prepost(int a, int b) {
 29require:
 30	a > 0;
 31ensure:
 32	test_prepost > 0;
 33}
 34
 35%inline %{
 36
 37int test_preassert(int x, int y) {
 38   if ((x > 0) && (y > 0)) return 1;
 39   return 0;
 40}
 41
 42int test_postassert(int x) {
 43    return x;
 44}
 45
 46int test_prepost(int x, int y) {
 47    return x+y;    
 48}
 49%}
 50
 51/* Class tests */
 52
 53%contract Foo::test_preassert(int x, int y) {
 54 require:
 55  x > 0;
 56  y > 0;
 57}
 58
 59%contract Foo::test_postassert(int a) {
 60 ensure:
 61  test_postassert > 0;
 62}
 63
 64%contract Foo::test_prepost(int a, int b) {
 65 require:
 66  a > 0;
 67 ensure:
 68  test_prepost > 0;
 69}
 70
 71%contract Foo::stest_prepost(int a, int b) {
 72 require:
 73  a > 0;
 74 ensure:
 75  stest_prepost > 0;
 76}
 77
 78%contract Bar::test_prepost(int c, int d) {
 79 require:
 80  d > 0;
 81}
 82
 83%inline %{
 84class Foo {
 85public:
 86        virtual ~Foo() { }
 87  
 88	virtual int test_preassert(int x, int y) {
 89            if ((x > 0) && (y > 0)) return 1;
 90            return 0;
 91	}   
 92	virtual int test_postassert(int x) {
 93	  return x;
 94	}
 95	virtual int test_prepost(int x, int y) {
 96	  return x+y;
 97	}
 98	static int stest_prepost(int x, int y) {
 99	  return x+y;
100	}
101 };
102
103class Bar : public Foo {
104public:
105	virtual int test_prepost(int x, int y) {
106	  return x+y;
107	}
108};
109
110%}
111
112/* Multiple inheritance test */
113
114%contract A::foo(int i, int j, int k, int l, int m) {
115 require:
116  i > 0;
117  j > 0;
118 ensure:
119  foo > 0;
120}
121
122%contract B::bar(int x, int y, int z, int w, int v) {
123 require:
124  w > 0;
125  v > 0;
126 ensure:
127  bar > 0;
128}
129
130%contract C::foo(int a, int b, int c, int d, int e) {
131 require:
132  c > 0;
133  d > 0;
134 ensure:
135  foo > 0;
136}
137
138%contract D::foo(int, int, int, int, int x) {
139 require:
140  x > 0;
141}
142
143%contract D::bar(int a, int b, int c, int, int) {
144 require:
145  a > 0;
146  b > 0;
147  c > 0;
148}
149
150%inline %{
151  class A {
152   public:
153    virtual ~A() {}
154    virtual int foo(int a, int b, int c, int d, int e) {
155      if ((a > 0) && (b > 0) && (c > 0) && (d > 0) && (e > 0)) {
156	return 1;
157      }
158      return 0;
159    }
160  };
161
162  class B {
163   public:
164    virtual ~B() {}
165    virtual int bar(int a, int b, int c, int d, int e) {
166      if ((a > 0) && (b > 0) && (c > 0) && (d > 0) && (e > 0)) {
167	return 1;
168      }
169      return 0;
170    }
171  };
172
173  class C : public A, public B {
174   public:
175    virtual int foo(int a, int b, int c, int d, int e) {
176      return A::foo(a,b,c,d,e);
177    }
178    virtual int bar(int a, int b, int c, int d, int e) {
179      return B::bar(a,b,c,d,e);
180    }
181  };
182  
183  class D : public C {
184   public:
185    virtual int foo(int a, int b, int c, int d, int e) {
186      return C::foo(a,b,c,d,e);
187    }
188    virtual int bar(int a, int b, int c, int d, int e) {
189      return C::bar(a,b,c,d,e);
190    }
191  };
192  %}
193
194%extend E {
195  %contract manipulate_i(int i) {
196  require:
197  i <= $self->m_i;
198  }
199}
200
201%inline %{
202struct E {
203  int m_i;
204  void manipulate_i(int i) {
205  }
206};
207%}
208
209
210// Namespace
211
212%{
213namespace myNames {
214
215class myClass
216{
217    public:
218    	myClass(int i) {}
219};
220
221}
222%}
223
224namespace myNames {
225
226%contract myClass::myClass( int i ) {
227require:
228    i > 0;
229}
230
231class myClass
232{
233    public:
234    	myClass(int i) {}
235};
236
237}
238