PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 107 lines | 83 code | 24 blank | 0 comment | 0 complexity | 319eefb2e08fb1a9119d3bbc07e791fd MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module extend_placement
  2. // Tests placement of %extend directives
  3. // Before the class
  4. %extend Foo {
  5. Foo(int a) { return new Foo(); }
  6. ~Foo() { delete $self;}
  7. int spam(int x) { return x; }
  8. int spam(int x, int y) { return x + y ; }
  9. int spam(int x, int y,int z) { return x + y ; }
  10. int spam(Foo f, double d = 10.0) { return 0; }
  11. };
  12. %inline %{
  13. class Foo {
  14. public:
  15. Foo(){}
  16. #ifdef SWIG
  17. %extend { Foo(int a, int b) { return new Foo(); } }
  18. #endif
  19. int spam() { return 1; }
  20. int spam(const char* c) { return 2; }
  21. };
  22. %}
  23. // After the class
  24. %inline %{
  25. class Bar {
  26. public:
  27. Bar() { }
  28. int spam() { return 1; }
  29. int spam(const char* c) { return 2; }
  30. };
  31. %}
  32. %extend Bar {
  33. Bar(int a) { return new Bar(); }
  34. ~Bar() { delete $self;}
  35. int spam() { return 1}
  36. int spam(int x) { return x; }
  37. int spam(int x, int y) { return x + y ; }
  38. int spam(int x, int y,int z) { return x + y ; }
  39. int spam(Bar b, double d = 10.0) { return 0; }
  40. };
  41. // testing templates
  42. // Before the class
  43. %extend FooT {
  44. FooT(int a) { return new FooT<T>(); }
  45. ~FooT() { delete $self;}
  46. int spam(int x) { return x; }
  47. int spam(int x, int y) { return x + y ; }
  48. int spam(int x, int y,int z) { return x + y ; }
  49. int spam(Foo f, double d = 10.0) { return 0; }
  50. };
  51. %inline %{
  52. template<class T>
  53. class FooT {
  54. public:
  55. FooT(){}
  56. #ifdef SWIG
  57. %extend { FooT(int a, int b) { return new FooT<T>(); } }
  58. #endif
  59. int spam() { return 1; }
  60. int spam(const char* c) { return 2; }
  61. };
  62. %}
  63. %template(FooTi) FooT<int>;
  64. // After the class
  65. %inline %{
  66. template<class T>
  67. class BarT {
  68. public:
  69. BarT() { }
  70. int spam() { return 1; }
  71. int spam(const char* c) { return 2; }
  72. };
  73. %}
  74. %extend BarT {
  75. BarT(int a) { return new BarT<T>(); }
  76. ~BarT() { delete $self;}
  77. int spam() { return 1}
  78. int spam(int x) { return x; }
  79. int spam(int x, int y) { return x + y ; }
  80. int spam(int x, int y,int z) { return x + y ; }
  81. int spam(Bar b, double d = 10.0) { return 0; }
  82. };
  83. %template(BarTi) BarT<int>;