import source from 1.3.40
[external/swig.git] / Examples / test-suite / template_typedef_cplx.i
1 %module template_typedef_cplx
2
3 //
4 // Change this to #if 1 to test the 'test'
5 //
6 #if 0
7
8 %{
9 #include <complex>
10 typedef std::complex<double> cmplx;
11 %}
12   
13 %inline %{
14   typedef cmplx Complex;
15 %}
16
17 #else
18
19 %inline %{
20 #include <complex>
21   typedef std::complex<double> Complex;
22 %}
23
24 #endif
25
26
27 %inline %{
28
29   namespace vfncs {
30
31     struct UnaryFunctionBase
32     {
33     };    
34     
35     template <class ArgType, class ResType>
36     struct UnaryFunction;
37     
38     template <class ArgType, class ResType>
39     struct ArithUnaryFunction;  
40     
41     template <class ArgType, class ResType>
42     struct UnaryFunction : UnaryFunctionBase
43     {
44     };
45
46     template <class ArgType, class ResType>
47     struct ArithUnaryFunction : UnaryFunction<ArgType, ResType>
48     {
49     };      
50     
51     template <class ArgType, class ResType>         
52     struct unary_func_traits 
53     {
54       typedef ArithUnaryFunction<ArgType, ResType > base;
55     };
56   
57     template <class ArgType>
58     inline
59     typename unary_func_traits< ArgType, ArgType >::base
60     make_Identity()
61     {
62       return typename unary_func_traits< ArgType, ArgType >::base();
63     }
64
65     template <class Arg1, class Arg2>
66     struct arith_traits 
67     {
68     };
69
70     template<>
71     struct arith_traits< double, double >
72     {
73     
74       typedef double argument_type;
75       typedef double result_type;
76       static const char* const arg_type;
77       static const char* const res_type;
78     };
79
80     template<>
81     struct arith_traits< Complex, Complex >
82     {
83     
84       typedef Complex argument_type;
85       typedef Complex result_type;
86       static const char* const arg_type;
87       static const char* const res_type;
88     };
89
90     template<>
91     struct arith_traits< Complex, double >
92     {
93       typedef double argument_type;
94       typedef Complex result_type;
95       static const char* const arg_type;
96       static const char* const res_type;
97     };
98
99     template<>
100     struct arith_traits< double, Complex >
101     {
102       typedef double argument_type;
103       typedef Complex result_type;
104       static const char* const arg_type;
105       static const char* const res_type;
106     };
107
108     template <class AF, class RF, class AG, class RG>
109     inline
110     ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
111                        typename arith_traits< RF, RG >::result_type >
112     make_Multiplies(const ArithUnaryFunction<AF, RF>& f,
113                     const ArithUnaryFunction<AG, RG >& g)
114     {
115       return 
116         ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
117                            typename arith_traits< RF, RG >::result_type>();
118     }
119
120 #ifndef SWIG
121
122     // Initialize these static class members
123
124     const char* const arith_traits< double, double >::arg_type = "double";
125     const char* const arith_traits< double, double >::res_type = "double";
126
127     const char* const arith_traits< Complex, Complex >::arg_type = "complex";
128     const char* const arith_traits< Complex, Complex >::res_type = "complex";
129
130     const char* const arith_traits< Complex, double>::arg_type = "double";
131     const char* const arith_traits< Complex, double >::res_type = "complex";
132
133     const char* const arith_traits< double, Complex >::arg_type = "double";
134     const char* const arith_traits< double, Complex >::res_type = "complex";
135
136 #endif
137
138   }
139 %}
140
141 namespace vfncs {  
142   %template(UnaryFunction_double_double) UnaryFunction<double, double >;  
143   %template(ArithUnaryFunction_double_double) ArithUnaryFunction<double, double >;  
144   %template() unary_func_traits<double, double >;
145   %template() arith_traits<double, double >;
146   %template(make_Identity_double) make_Identity<double >;
147
148   %template(UnaryFunction_complex_complex) UnaryFunction<Complex, Complex >;  
149   %template(ArithUnaryFunction_complex_complex) ArithUnaryFunction<Complex, Complex >;  
150
151   %template() unary_func_traits<Complex, Complex >;
152   %template() arith_traits<Complex, Complex >;
153   %template(make_Identity_complex) make_Identity<Complex >;
154
155   /* [beazley] Added this part */
156   %template() unary_func_traits<double,Complex>;
157   %template(UnaryFunction_double_complex) UnaryFunction<double,Complex>;
158   %template(ArithUnaryFunction_double_complex) ArithUnaryFunction<double,Complex>;
159
160   /* */
161
162   %template() arith_traits<Complex, double >;
163   %template() arith_traits<double, Complex >;
164
165   %template(make_Multiplies_double_double_complex_complex)
166     make_Multiplies<double, double, Complex, Complex>;
167
168   %template(make_Multiplies_double_double_double_double)
169     make_Multiplies<double, double, double, double>;
170
171   %template(make_Multiplies_complex_complex_complex_complex)
172     make_Multiplies<Complex, Complex, Complex, Complex>;
173
174   %template(make_Multiplies_complex_complex_double_double)
175     make_Multiplies<Complex, Complex, double, double>;
176
177 }
178