PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 181 lines | 150 code | 31 blank | 0 comment | 0 complexity | 5d769d85b16bbea701e47820207d50d6 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module features
  2. %warnfilter(SWIGWARN_LANG_IDENTIFIER,SWIGWARN_IGNORE_OPERATOR_PLUSEQ);
  3. // This testcase checks that %feature is working for templates and non user supplied constructors/destructors and is just generally working
  4. // If the default %exception is used it will not compile. It shouldn't get used.
  5. %exception "this_will_not_compile";
  6. // Test 1: Test for no user supplied constructors and destructor
  7. %exception Simple::Simple(const Simple&) "$action /*Simple::Simple*/";
  8. %exception Simple::Simple() "$action /*Simple::Simple*/";
  9. %exception Simple::~Simple() "$action /*Simple::~Simple*/";
  10. %inline %{
  11. class Simple {};
  12. %}
  13. %exception NS::SimpleNS::SimpleNS(const NS::SimpleNS&) "$action /*NS::SimpleNS::SimpleNS*/";
  14. %exception NS::SimpleNS::SimpleNS() "$action /*NS::SimpleNS::SimpleNS*/";
  15. %exception NS::SimpleNS::~SimpleNS() "$action /*NS::SimpleNS::~SimpleNS*/";
  16. // method tests
  17. %exception NS::SimpleNS::method() "_failed_ /*NS::Simple::method() const*/";
  18. %exception NS::SimpleNS::method() const "$action /*NS::Simple::method() const*/";
  19. %exception NS::SimpleNS::afunction() "$action /*NS::Simple::afunction()*/";
  20. %inline %{
  21. namespace NS
  22. {
  23. class SimpleNS {
  24. public:
  25. void method() const {}
  26. void afunction() {}
  27. };
  28. }
  29. %}
  30. // Test 2: Test templated functions
  31. %exception foobar "caca";
  32. %exception foobar<int>(int) "$action /*foobar<int>*/";
  33. %inline %{
  34. template<class T> void foobar(T t) {}
  35. %}
  36. %template(FooBarInt) foobar<int>;
  37. // Test 3: Test templates with no user supplied constructors and destructor
  38. %exception SimpleTemplate<int>::SimpleTemplate(const SimpleTemplate<int>&) "$action /*SimpleTemplate<int>::SimpleTemplate<int>*/";
  39. %exception SimpleTemplate<int>::SimpleTemplate() "$action /*SimpleTemplate<int>::SimpleTemplate<int>*/";
  40. %exception SimpleTemplate<int>::~SimpleTemplate() "$action /*SimpleTemplate<int>::~SimpleTemplate*/";
  41. %inline %{
  42. template<class T> class SimpleTemplate {
  43. public:
  44. };
  45. %}
  46. %template(SimpleInt) SimpleTemplate<int>;
  47. // Test 4: Test templates with user supplied constructors and destructor
  48. %exception Template<int>::Template() "$action /*Template<int>::Template<int>*/";
  49. %exception Template<int>::Template(const Template&) "$action /*Template<int>::Template<int>(const Template&)*/";
  50. %exception Template<int>::~Template() "$action /*Template<int>::~Template*/";
  51. // method tests
  52. %exception Template<int>::foo "$action /*Template<int>::foo*/";
  53. %exception Template::get "$action /*Template<int>::get*/";
  54. %exception Template<int>::set(const int &t) "$action /*Template<int>::set(const int &t)*/";
  55. %exception Template<int>::bar(const int &t) "_failed_ /*Template<int>::bar(const int &t) const*/";
  56. %exception Template<int>::bar(const int &t) const "$action /*Template<int>::bar(const int &t) const*/";
  57. %inline %{
  58. template<class T> class Template {
  59. public:
  60. Template(){}
  61. Template(const Template&){}
  62. ~Template(){}
  63. void foo(){}
  64. void bar(const int &t) const {}
  65. #ifdef SWIG
  66. %extend {
  67. T& get(int i) const {
  68. throw 1;
  69. }
  70. void set(const T &t) {}
  71. }
  72. #endif
  73. };
  74. %}
  75. %template(TemplateInt) Template<int>;
  76. // Test 5: wildcards
  77. %exception Space::WildCards::WildCards(const Space::WildCards&) "$action /* Space::WildCards::WildCards() */";
  78. %exception Space::WildCards::WildCards() "$action /* Space::WildCards::WildCards() */";
  79. %exception Space::WildCards::~WildCards() "$action /* Space::WildCards::WildCards() */";
  80. %exception *::incy "_failure_ /* *::incy */";
  81. %exception *::incy(int a) "_failure_ /* *::incy(int a) */";
  82. %exception *::incy(int a) const "$action /* *::incy(int a) const */";
  83. %exception *::wincy(int a) "$action /* *::wincy(int a) */";
  84. %exception *::spider "$action /* *::spider */";
  85. %exception *::spider(int a) "_failure_ /* *::spider(int a) */";
  86. %inline %{
  87. namespace Space {
  88. struct WildCards {
  89. virtual ~WildCards() {}
  90. virtual WildCards* incy(int a) const { return 0; }
  91. virtual WildCards* wincy(int a) { return 0; }
  92. virtual WildCards* spider(int a) const { return 0; }
  93. };
  94. }
  95. %}
  96. // Test 6: default arguments
  97. %exception Space::Animals::Animals(const Space::Animals&) "$action /* Space::Animals::Animals(int a = 0, double d = 0.0) */";
  98. %exception Space::Animals::Animals(int a = 0, double d = 0.0) "$action /* Space::Animals::Animals(int a = 0, double d = 0.0) */";
  99. %exception Space::Animals::~Animals() "$action /* Space::Animals::~Animals() */";
  100. %exception Space::Animals::lions(int a = 0, double d = 0.0) const "$action /* Space::Animals::lions(int a = 0, double d = 0.0) const */";
  101. %exception Space::Animals::leopards(int a = 0, double d = 0.0) "$action /* Space::Animals::leopards(int a = 0, double d = 0.0) */";
  102. %exception *::cheetahs(int a = 0, double d = 0.0) const "$action /* *::cheetahs(int a = 0, double d = 0.0) const */";
  103. %exception *::jackal(int a = 0, double d = 0.0) "$action /* *::jackal(int a = 0, double d = 0.0) */";
  104. %inline %{
  105. namespace Space {
  106. struct Animals {
  107. Animals(int a = 0, double d = 0.0) {}
  108. void* lions(int a = 0, double d = 0.0) const { return 0; }
  109. void* leopards(int a = 0, double d = 0.0) { return 0; }
  110. int cheetahs(int a = 0, double d = 0.0) const { return 0; }
  111. int jackal(int a = 0, double d = 0.0) { return 0; }
  112. };
  113. }
  114. %}
  115. // Test 7: inheritance
  116. %exception Space::Base::Base(const Space::Base&) "$action /* Space::Base::Base() */";
  117. %exception Space::Base::Base() "$action /* Space::Base::Base() */";
  118. %exception Space::Base::~Base() "$action /* Space::Base::~Base() */";
  119. %exception Space::Derived::Derived(const Space::Derived&) "$action /* Space::Derived::Derived() */";
  120. %exception Space::Derived::Derived() "$action /* Space::Derived::Derived() */";
  121. %exception Space::Derived::~Derived() "$action /* Space::Derived::~Derived() */";
  122. // The following should apply to both Base and Derived
  123. %exception Space::Base::virtualmethod(int a) const "$action /* Space::Base::virtualmethod(int a) const */";
  124. %exception Space::Base::operator+=(int) "$action /* Space::Base::Base() */";
  125. %inline %{
  126. namespace Space {
  127. struct Base {
  128. int operator+=(int) { return 0; }
  129. virtual const char** virtualmethod(int a) const { return 0; }
  130. virtual ~Base() {}
  131. };
  132. struct Derived : Base {
  133. virtual const char** virtualmethod(int a) const { return 0; }
  134. };
  135. }
  136. %}
  137. // Test 8 conversion operators
  138. %rename(opbool) operator bool;
  139. %rename(opuint) operator unsigned int;
  140. %exception ConversionOperators::ConversionOperators() "$action /* ConversionOperators::ConversionOperators() */";
  141. %exception ConversionOperators::~ConversionOperators() "$action /* ConversionOperators::~ConversionOperators() */";
  142. %exception ConversionOperators::operator bool "$action /* ConversionOperators::operator bool */";
  143. %exception ConversionOperators::operator unsigned int "$action /* ConversionOperators::unsigned int*/";
  144. %inline %{
  145. class ConversionOperators {
  146. public:
  147. operator bool() { return false; }
  148. operator unsigned int() { return 0; }
  149. };
  150. %}