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

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

#
Swig | 116 lines | 101 code | 15 blank | 0 comment | 0 complexity | 571d77d10e14fef3baaf0337cb3777b8 MD5 | raw file
  1%module template_nested
  2
  3// Test nested templates - that is template classes and template methods within a class.
  4
  5%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner1;
  6%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner2;
  7%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate1;
  8%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate2;
  9%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate3;
 10%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedStruct;
 11
 12namespace ns {
 13template <class T> struct ForwardTemplate;
 14}
 15%{
 16namespace ns {
 17  template <class T> struct ForwardTemplate {
 18    void tmethod(T t) {}
 19  };
 20}
 21%}
 22
 23%inline %{
 24
 25namespace ns {
 26
 27  class NormalClass {
 28  public:
 29    NormalClass() {}
 30    ~NormalClass() {}
 31  };
 32
 33  template <class T> struct NormalTemplate {
 34    void tmethod(T t) {}
 35  };
 36
 37  class OuterClass {
 38  public:
 39    template <class T> struct Inner1 {
 40      template <class U> struct SuperInner1 {
 41        void method1(U t) {}
 42      };
 43      template <class V> struct SuperInner2 {
 44        void method1(V t) {}
 45      };
 46      template <class W> void tmethod(W w) {}
 47      template <class X> void tmethodAgain(X x) {}
 48      template <class Y> struct SuperBase : public SuperInner1<Y> {
 49        void method1(Y y) {}
 50      };
 51    };
 52    Inner1<int> useInner1(const Inner1<int>& inner) { return inner; }
 53
 54    template <class Z> void InnerTMethod(Z z) {}
 55
 56    template <class T> class Inner2 : public NormalTemplate<T> {
 57    public:
 58      template <class U> class SuperInner1 {
 59      public:
 60        SuperInner1() {}
 61        void method1(U t) {}
 62      };
 63      template <class V> struct SuperInner2 {
 64        void method1(V t) {}
 65      };
 66      int embeddedVar;
 67      template <class X> void tmethod(X x) {}
 68      template <class Y> struct SuperBase : public SuperInner1<Y> {
 69        void method1(Y y) {}
 70      };
 71    };
 72    Inner2<int> useInner2(const Inner2<int>& inner) { return inner; }
 73    int iii;
 74  };
 75  struct ABC {
 76    ABC() {}
 77    ~ABC() {}
 78  };
 79
 80  struct TemplateFuncs {
 81    template <class X> X templateMethod1(X x) { return x; }
 82    template <class X> X templateMethod2(X x) { return x; }
 83  };
 84
 85  template <typename UU> struct OuterTemplate {
 86    template <typename VV> struct NestedInnerTemplate1 {
 87      template <typename Z> void NestedInnerInnerTMethod(Z z) {}
 88      void hohum() {}
 89    };
 90    template <typename W> void NestedInnerTMethod(UU u, W w) {}
 91    template <typename VV> struct NestedInnerTemplate2 {
 92      void hohum() {}
 93    };
 94    UU hohum(UU u) { return u; }
 95    template <typename VV> struct NestedInnerTemplate3 : public NestedInnerTemplate2<VV> {
 96      void hohum() {}
 97    };
 98    struct NestedStruct {
 99      NestedStruct() {}
100      void hohum() {}
101    };
102    NestedInnerTemplate1<short> useNestedInnerTemplate1(const NestedInnerTemplate1<short>& inner) { return inner; }
103    NestedInnerTemplate2<short> useNestedInnerTemplate2(const NestedInnerTemplate2<short>& inner) { return inner; }
104    NestedInnerTemplate3<short> useNestedInnerTemplate3(const NestedInnerTemplate3<short>& inner) { return inner; }
105    NestedStruct useNestedStruct(const NestedStruct& inner) { return inner; }
106  };
107}
108
109%}
110
111%template(T_NormalTemplateNormalClass) ns::NormalTemplate<ns::NormalClass>;
112%template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod<ns::NormalClass>;
113%template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1<int>;
114%template(T_TemplateFuncs2Double) ns::TemplateFuncs::templateMethod2<double>;
115%template(T_NestedOuterTemplateDouble) ns::OuterTemplate<double>;
116