~ubuntu-branches/ubuntu/edgy/swig1.3/edgy

« back to all changes in this revision

Viewing changes to Examples/test-suite/template_default.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%module template_default
2
 
%inline %{
3
 
template <class T1, class T2 = T1>
4
 
class A
5
 
{
6
 
};
7
 
 %}
8
 
 
9
 
%template(A_ii) A<int, int>;       
10
 
%template(A_d) A<double>;
 
2
 
 
3
 
 
4
 
 
5
%warnfilter(801) ns1::Traits::c; /* Ruby, wrong constant name */
 
6
namespace ns1 {
 
7
  namespace ns2 {
 
8
  
 
9
    %feature("hello") A<int>;
 
10
    %feature("hello") A<double,double>;
 
11
    %feature("hi") A<int,int>;
 
12
    %feature("hi") A<double>;
 
13
    
 
14
    %extend A<int> 
 
15
    {
 
16
      int foo() { return 1; }
 
17
    }
 
18
    
 
19
    %extend A<double,double> 
 
20
    {
 
21
      int foo() { return 1; }
 
22
    }
 
23
    
 
24
    %extend A<int,int> 
 
25
    {
 
26
      int bar() { return 1; }
 
27
    }
 
28
    
 
29
    %extend A<double> 
 
30
    {
 
31
      int bar() { return 1; }
 
32
    }
 
33
 
 
34
    %extend N<double> 
 
35
    {
 
36
      int bar() { return 1; }
 
37
    }
 
38
  }
 
39
}
 
40
 
 
41
%inline %{
 
42
  
 
43
  namespace ns1 {
 
44
    namespace ns2 {
 
45
      
 
46
      struct Parm
 
47
      {
 
48
      };
 
49
      
 
50
      template <class T1, class T2 = T1>
 
51
      class A
 
52
      {
 
53
        
 
54
#ifdef SWIG      
 
55
        %typemap(in) A *  { /* in A */ }
 
56
  #ifdef SWIGCSHARP
 
57
        %typemap(out) A *  { /* out A */ $result=0; }
 
58
  #else
 
59
        %typemap(out) A *  { /* out A */ }
 
60
  #endif
 
61
#endif
 
62
      };
 
63
 
 
64
      typedef unsigned int category;
 
65
      
 
66
      const category one = 1;
 
67
      const category two = 1;
 
68
      
 
69
      
 
70
      template <class T1, category C = one, class T2 = Parm>
 
71
      class N
 
72
      {
 
73
        
 
74
#ifdef SWIG      
 
75
        %typemap(in) N *  { /* in N */ }
 
76
  #ifdef SWIGCSHARP
 
77
        %typemap(out) N *  { /* out N */ $result=0; }
 
78
  #else
 
79
        %typemap(out) N *  { /* out N */ }
 
80
  #endif
 
81
#endif
 
82
      };
 
83
    }
 
84
  }
 
85
%}
 
86
 
 
87
      
 
88
 
 
89
 
 
90
%template(A_p) ns1::ns2::A<double,ns1::ns2::Parm>;
 
91
%template(N_1p) ns1::ns2::N<int>;
 
92
 
 
93
 
 
94
namespace ns1 {
 
95
  namespace ns2 {
 
96
    %template(A_ii) A<int, int>;       
 
97
    %template(A_d) A<double>;
 
98
    %template(N_d) N<double>;
 
99
    
 
100
  }
 
101
}
 
102
 
 
103
 
 
104
%inline %{
 
105
  namespace ns1 {
 
106
    namespace ns2 {    
 
107
      namespace ns3 {  
 
108
 
 
109
        struct B : A<int> 
 
110
        {
 
111
        };
 
112
        
 
113
        struct C : N<double,ns1::ns2::one> 
 
114
        {         
 
115
        };
 
116
        
 
117
        
 
118
        A<int> *get_a1(A<int> *a) {
 
119
          return a;
 
120
        }
 
121
        
 
122
        A<int,int> *get_a2(A<int,int> *a) {
 
123
          return a;
 
124
        }
 
125
 
 
126
      }
 
127
    }
 
128
  }
 
129
%}
 
130
 
 
131
%inline %{
 
132
  namespace ns1 {    
 
133
    struct Traits
 
134
    {
 
135
      static const ns2::category c = ns2::one;
 
136
    };
 
137
    namespace ns4 {    
 
138
      
 
139
      template <class T>
 
140
      struct D : ns2::N<double,T::c>
 
141
      {
 
142
        D()
 
143
        {
 
144
        }
 
145
        
 
146
      };
 
147
 
 
148
      template <class T1, class T2 = D<T1> >
 
149
      struct Base : T2
 
150
      {
 
151
      };
 
152
    }
 
153
  }
 
154
%}
 
155
 
 
156
 
 
157
%template(Do) ns1::ns4::D<ns1::Traits>;
 
158
%template(Bo) ns1::ns4::Base<ns1::Traits, ns1::ns4::D<ns1::Traits> >;
 
159
 
 
160
 
 
161
 
 
162
%inline %{
 
163
  namespace ns1 {    
 
164
    namespace ns5 {    
 
165
      
 
166
      struct Der : ns4::Base<Traits>
 
167
      {
 
168
      };
 
169
    }
 
170
  }
 
171
  
 
172
%}
 
173
 
 
174
 
 
175
%inline %{
 
176
 
 
177
  namespace hi 
 
178
  {
 
179
    class CFoo
 
180
    {
 
181
    };
 
182
    
 
183
    template<class T1, class T2 = T1> class CTemplate
 
184
    {
 
185
    };
 
186
    
 
187
    typedef CTemplate<CFoo> TBla;                  // OK
 
188
    typedef void (*TFunc1)(CFoo arg);              // OK
 
189
    typedef void (*TFunc2)(CTemplate<CFoo> arg);   // OK
 
190
    typedef void (*TFunc3)(CTemplate<CFoo>* arg);  // OK
 
191
 
 
192
    int foo(TFunc1 a, TFunc2 b, TFunc3 c) 
 
193
    {
 
194
      return 0;
 
195
    }
 
196
  }  
 
197
%}
 
198
 
 
199
 
 
200
%include std_vector.i
 
201
 
 
202
%{
 
203
#include <vector>
 
204
%}
 
205
 
 
206
%inline %{
 
207
void g(std::vector<double>* s = 0) {}
 
208
void q(double = 0) {}
 
209
%}
 
210
 
 
211
 
 
212
%constant void (*Bf)(std::vector<double> *p = 0) = g; 
 
213
%constant void (*Cf)(double = 0) = q; 
 
214
 
 
215