PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

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