PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Swig | 77 lines | 62 code | 15 blank | 0 comment | 0 complexity | 2e2c21a38bc5ac6b75597c32af88fed0 MD5 | raw file
 1%module template_default_class_parms_typedef
 2
 3// Based on template_default_class_parms testcase but using typedefs in template
 4
 5%feature("python:nondynamic");
 6
 7%inline %{
 8namespace Space {
 9  struct SomeType {};
10  struct AnotherType {};
11  template<typename CC, typename DD = SomeType, typename EE = int> class Bar {
12  public:
13    typedef CC C;
14    typedef DD D;
15    typedef EE E;
16    C CType;
17    D DType;
18    E EType;
19    // Use typedef with no qualifiers
20    Bar(C c, D d, E e) {}
21    C method(C c, D d, E e) { return c; }
22
23    // Use typedef with classname qualifiers
24    Bar(bool, Bar::C c, Bar::D d, Bar::E e) {}
25    Bar::C method_1(Bar::C c, Bar::D d, Bar::E e) { return c; }
26
27    // Use typedef with classname and full template parameter qualifiers
28    Bar(bool, bool, Bar<CC, DD, EE>::C c, Bar<CC, DD, EE>::D d, Bar<CC, DD, EE>::E e) {}
29    Bar<CC, DD, EE>::C method_2(Bar<CC, DD, EE>::C c, Bar<CC, DD, EE>::D d, Bar<CC, DD, EE>::E e) { return c; }
30
31    // Use typedef with namespace and classname and full template parameter qualifiers
32    Bar(bool, bool, bool, Space::Bar<CC, DD, EE>::C c, Space::Bar<CC, DD, EE>::D d, Space::Bar<CC, DD, EE>::E e) {}
33    Space::Bar<CC, DD, EE>::C method_3(Space::Bar<CC, DD, EE>::C c, Space::Bar<CC, DD, EE>::D d, Space::Bar<CC, DD, EE>::E e) { return c; }
34  };
35  template<typename TT = SomeType> class Foo {
36  public:
37    typedef TT T;
38    T TType;
39
40    // Use typedef with no qualifiers
41    Foo(T t) {}
42    T method(T t) { return t; }
43
44    // Use typedef with classname qualifiers
45    Foo(const T &, T t) {}
46    Foo::T method_A(Foo::T t) { return t; }
47
48    // Use typedef with classname and full template parameter qualifiers
49    Foo(const Foo<TT>::T &, const Foo<TT>::T &, Foo<TT>::T t) {}
50    Foo<TT>::T method_B(Foo<TT>::T t) { return t; }
51
52    // Use typedef with namespace and classname and full template parameter qualifiers
53    Foo(const Foo<TT>::T &, const Foo<TT>::T &, const Foo<TT>::T &, Foo<TT>::T t) {}
54    Foo<TT>::T method_C(Foo<TT>::T t) { return t; }
55  };
56  template<typename T = int> class ATemplate {};
57
58  template<typename T> struct UsesBar {
59    void use_A(typename Bar<T>::C, typename Bar<T>::D, typename Bar<T>::E) {}
60    void use_B(const typename Bar<T>::C &, const typename Bar<T>::D &, const typename Bar<T>::E &) {}
61    void use_C(typename Space::Bar<T>::C, typename Space::Bar<T>::D, typename Space::Bar<T>::E) {}
62    void use_D(const typename Space::Bar<T>::C &, const typename Space::Bar<T>::D &, const typename Space::Bar<T>::E &) {}
63  };
64}
65%}
66
67// Use defaults
68%template(DefaultBar) Space::Bar<double>;
69%template(DefaultFoo) Space::Foo<>;
70
71// Don't use all defaults
72%template(BarAnotherTypeBool) Space::Bar<Space::AnotherType, bool>;
73%template(FooAnotherType) Space::Foo<Space::AnotherType>;
74
75%template() Space::ATemplate<>;
76
77%template(UsesBarDouble) Space::UsesBar<double>;