PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
Swig | 130 lines | 113 code | 17 blank | 0 comment | 0 complexity | fa7706d3076a241708caaf64b8e5d188 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This testcase is almost identical to template_partial_specialization but uses typedefs for %template
  2. %module template_partial_specialization_typedef
  3. %inline %{
  4. namespace TypeDef {
  5. typedef double Double;
  6. typedef int * IntPtr;
  7. typedef double * DoublePtr;
  8. typedef double & DoubleRef;
  9. typedef const double & ConstDoubleRef;
  10. typedef double * const & DoublePtrConstRef;
  11. typedef int Int;
  12. typedef int * const & IntPtrConstRef;
  13. typedef int ** IntPtrPtr;
  14. typedef float Float;
  15. typedef float * FloatPtr;
  16. typedef float ** FloatPtrPtr;
  17. typedef float *** FloatPtrPtrPtr;
  18. typedef bool * BoolPtr;
  19. typedef char * CharPtr;
  20. typedef short * ShortPtr;
  21. typedef long * LongPtr;
  22. typedef unsigned int ** UnsignedIntPtrPtr;
  23. typedef unsigned int *** UnsignedIntPtrPtrPtr;
  24. typedef const unsigned int ** ConstUnsignedIntPtr;
  25. typedef const unsigned int *** ConstUnsignedIntPtrPtr;
  26. }
  27. namespace One {
  28. template <typename T> struct OneParm { void a() {} };
  29. template <typename T> struct OneParm<T *> { void b() {} };
  30. template <typename T> struct OneParm<T &> { void c() {} };
  31. template <typename T> struct OneParm<T const &> { void d() {} };
  32. template <typename T> struct OneParm<T * const &> { void e() {} };
  33. template <> struct OneParm<int> { void f() {} };
  34. template <> struct OneParm<int * const &> { void g() {} };
  35. template <> struct OneParm<int **> { void h() {} };
  36. template <> struct OneParm<float> { void i() {} };
  37. template <> struct OneParm<float *> { void j() {} };
  38. template <> struct OneParm<float **> { void k() {} };
  39. template <> struct OneParm<float ***> { void l() {} };
  40. }
  41. %}
  42. // partial specializations
  43. %template(A) One::OneParm<TypeDef::Double>;
  44. %template(B) One::OneParm<TypeDef::DoublePtr>;
  45. %template(C) One::OneParm<TypeDef::DoubleRef>;
  46. %template(D) One::OneParm<TypeDef::ConstDoubleRef>;
  47. %template(E) One::OneParm<TypeDef::DoublePtrConstRef>;
  48. // explicit specializations
  49. %template(F) One::OneParm<TypeDef::Int>;
  50. %template(G) One::OneParm<TypeDef::IntPtrConstRef>;
  51. %template(H) One::OneParm<TypeDef::IntPtrPtr>;
  52. // %template scope explicit specializations
  53. namespace ONE {
  54. %template(I) One::OneParm<TypeDef::Float>;
  55. %template(J) ::One::OneParm<TypeDef::FloatPtr>;
  56. }
  57. %template(K) ::One::OneParm<TypeDef::FloatPtrPtr>;
  58. namespace One {
  59. %template(L) OneParm<TypeDef::FloatPtrPtrPtr>;
  60. }
  61. // %template scope partial specializations
  62. namespace ONE {
  63. %template(BB) One::OneParm<TypeDef::BoolPtr>;
  64. %template(BBB) ::One::OneParm<TypeDef::CharPtr>;
  65. }
  66. %template(BBBB) ::One::OneParm<TypeDef::ShortPtr>;
  67. namespace One {
  68. %template(BBBBB) OneParm<TypeDef::LongPtr>;
  69. }
  70. // non-exact match
  71. %template(B1) One::OneParm<TypeDef::UnsignedIntPtrPtr>;
  72. %template(B2) One::OneParm<TypeDef::UnsignedIntPtrPtrPtr>;
  73. %template(B3) One::OneParm<TypeDef::ConstUnsignedIntPtr>;
  74. %template(B4) One::OneParm<TypeDef::ConstUnsignedIntPtrPtr>;
  75. // Two parameter specialization tests
  76. %inline %{
  77. struct Concrete {};
  78. namespace Two {
  79. template <typename T1, typename T2> struct TwoParm { void a() {} };
  80. template <typename T1, typename T2> struct TwoParm<T1 *, T2 *> { void b() {} };
  81. template <typename T1, typename T2> struct TwoParm<T1 *, const T2 *> { void c() {} };
  82. template <typename T1, typename T2> struct TwoParm<const T1 *, const T2 *> { void d() {} };
  83. template <typename T1> struct TwoParm<T1 *, int *> { void e() {} };
  84. template <typename T1> struct TwoParm<T1, int> { void f() {} };
  85. template <> struct TwoParm<int *, const int *> { void g() {} };
  86. }
  87. %}
  88. %inline %{
  89. namespace TypeDef {
  90. typedef const double * ConstDoublePtr;
  91. typedef const int * ConstIntPtr;
  92. typedef int * IntPtr;
  93. typedef Concrete * ConcretePtr;
  94. typedef const Concrete * ConstConcretePtr;
  95. typedef void * VoidPtr;
  96. }
  97. %}
  98. namespace Two {
  99. %template(A_) TwoParm<TypeDef::Double, TypeDef::Double>;
  100. %template(B_) TwoParm<TypeDef::DoublePtr, TypeDef::DoublePtr>;
  101. %template(C_) TwoParm<TypeDef::DoublePtr, TypeDef::ConstDoublePtr>;
  102. %template(D_) TwoParm<TypeDef::ConstIntPtr, TypeDef::ConstIntPtr>;
  103. %template(E_) TwoParm<TypeDef::IntPtr, TypeDef::IntPtr>;
  104. %template(F_) TwoParm<TypeDef::IntPtr, TypeDef::Int>;
  105. %template(G_) TwoParm<TypeDef::IntPtr, TypeDef::ConstIntPtr>;
  106. %template(C1_) TwoParm<TypeDef::ConcretePtr, TypeDef::ConstConcretePtr>;
  107. %template(C2_) TwoParm<TypeDef::IntPtr, TypeDef::ConstConcretePtr>;
  108. }
  109. %template(C3_) Two::TwoParm<TypeDef::DoublePtr, TypeDef::ConstConcretePtr>;
  110. %template(C4_) ::Two::TwoParm<TypeDef::VoidPtr, TypeDef::ConstConcretePtr>;
  111. %template(B1_) ::Two::TwoParm<TypeDef::CharPtr, TypeDef::ConcretePtr>;
  112. %template(E1_) Two::TwoParm<TypeDef::ConstIntPtr, TypeDef::IntPtr>;
  113. %template(E2_) Two::TwoParm<TypeDef::IntPtrPtr, TypeDef::IntPtr>;