PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

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

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