PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 108 lines | 90 code | 18 blank | 0 comment | 0 complexity | 5872419c47eb9904fdb3cd48bfaecd29 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // Test %rename directive with the 'using' keyword and within the class definition
  2. %module rename4
  3. %{
  4. #include "rename.h"
  5. %}
  6. namespace Space {
  7. struct Klass {
  8. Klass(int i) {}
  9. Klass() {}
  10. };
  11. }
  12. namespace AnotherSpace {
  13. class Another {};
  14. }
  15. namespace Space {
  16. %rename(opAnother1) XYZ::operator Another() const;
  17. %rename(opAnother2) XYZ<int>::operator Another() const;
  18. %rename(opAnother3) XYZ<Space::Klass>::operator Another() const;
  19. %rename(opAnother4) XYZ<Space::Enu>::operator Another() const;
  20. }
  21. // Test %rename - no namespace, but specific templated type in the parameter, is used over the generic type T
  22. %rename(tMethod2) templateT(int i);
  23. %rename(tMethodNotXYZ2) templateNotXYZ(NotXYZ<int>);
  24. %rename(tMethodXYZ2) templateXYZ(XYZ<int>);
  25. %rename(opT2) operator int();
  26. %rename(opNotXYZ2) operator NotXYZ<int>() const;
  27. %rename(opXYZ2) operator XYZ<int>() const;
  28. %rename(tMethod3) templateT(Space::Klass i);
  29. %rename(tMethodNotXYZ3) templateNotXYZ(NotXYZ<Space::Klass>);
  30. %rename(tMethodXYZ3) templateXYZ(XYZ<Space::Klass>);
  31. %rename(opT3) operator Space::Klass();
  32. %rename(opNotXYZ3) operator NotXYZ<Space::Klass>() const;
  33. %rename(opXYZ3) operator XYZ<Space::Klass>() const;
  34. %rename(tMethod4) templateT(Space::Enu i);
  35. %rename(tMethodNotXYZ4) templateNotXYZ(NotXYZ<Space::Enu>);
  36. %rename(tMethodXYZ4) templateXYZ(XYZ<Space::Enu>);
  37. %rename(opT4) operator Space::Enu();
  38. %rename(opNotXYZ4) operator NotXYZ<Space::Enu>() const;
  39. %rename(opXYZ4) operator XYZ<Space::Enu>() const;
  40. namespace Space {
  41. using namespace AnotherSpace;
  42. enum Enu { En1, En2, En3 };
  43. template<typename T> struct NotXYZ {};
  44. template<typename T> class XYZ {
  45. // Test %rename within the class
  46. %rename(opIntPtrA) operator NotXYZ<int>*() const;
  47. %rename(opIntPtrB) operator XYZ<int>*() const;
  48. %rename(tMethod1) templateT(T i);
  49. %rename(tMethodNotXYZ1) templateNotXYZ(NotXYZ<T>);
  50. %rename(tMethodXYZ1) templateXYZ(XYZ<T>);
  51. %rename(opT1) operator T();
  52. %rename(opNotXYZ1) operator NotXYZ<T>() const;
  53. %rename(opXYZ1) operator XYZ<T>() const;
  54. NotXYZ<int> *m_int;
  55. T m_t;
  56. NotXYZ<T> m_notxyz;
  57. public:
  58. operator NotXYZ<int>*() const { return m_int; }
  59. operator XYZ<int>*() const { return 0; }
  60. operator Another() const { Another an; return an; }
  61. void templateT(T i) {}
  62. void templateNotXYZ(NotXYZ<T> i) {}
  63. void templateXYZ(XYZ<T> i) {}
  64. operator T() { return m_t; }
  65. operator NotXYZ<T>() const { return m_notxyz; }
  66. operator XYZ<T>() const { XYZ<T> xyz; return xyz; }
  67. };
  68. }
  69. namespace Space {
  70. // non-templated class using itself in method and operator
  71. class ABC {
  72. public:
  73. %rename(methodABC) method(ABC a) const;
  74. %rename(opABC) operator ABC() const;
  75. %rename(methodKlass) method(Klass k) const;
  76. %rename(opKlass) operator Klass() const;
  77. void method(ABC a) const {}
  78. void method(Klass k) const {}
  79. operator ABC() const { ABC a; return a; }
  80. operator Klass() const { Klass k; return k; }
  81. };
  82. }
  83. %template(XYZInt) Space::XYZ<int>;
  84. %template(XYZDouble) Space::XYZ<double>;
  85. %template(XYZKlass) Space::XYZ<Space::Klass>;
  86. %template(XYZEnu) Space::XYZ<Space::Enu>;
  87. %template(NotXYZInt) Space::NotXYZ<int>;
  88. %template(NotXYZDouble) Space::NotXYZ<double>;
  89. %template(NotXYZKlass) Space::NotXYZ<Space::Klass>;
  90. %template(NotXYZEnu) Space::NotXYZ<Space::Enu>;