summaryrefslogtreecommitdiff
path: root/Examples/test-suite/template_typedef_cplx2.h
blob: 17d065252edc1bc21a580b73fd8544306ab9418f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef ___typedef_import_h__
#define ___typedef_import_h__

#ifdef SWIG
%module template_typedef_cplx2;
#endif

#include <complex>
typedef std::complex<double> Complex;

namespace vfncs {

  struct UnaryFunctionBase
  {
    int get_base_value()
    {
      return 0;
    }
  };    
    
  template <class ArgType, class ResType>
  struct UnaryFunction;
    
  template <class ArgType, class ResType>
  struct ArithUnaryFunction;  
    
  template <class ArgType, class ResType>
  struct UnaryFunction : UnaryFunctionBase
  {
    int get_value()
    {
      return 1;
    }
  };

  template <class ArgType, class ResType>
  struct ArithUnaryFunction : UnaryFunction<ArgType, ResType>
  {
    int get_arith_value()
    {
      return 2;
    }
  };      
    
  template <class ArgType, class ResType>         
  struct unary_func_traits 
  {
    typedef ArithUnaryFunction<ArgType, ResType > base;
  };
  
  template <class ArgType>
  inline
  typename unary_func_traits< ArgType, ArgType >::base
  make_Identity()
  {
    return typename unary_func_traits< ArgType, ArgType >::base();
  }

  template <class Arg1, class Arg2>
  struct arith_traits 
  {
  };

  template<>
  struct arith_traits< double, double >
  {    
    typedef double argument_type;
    typedef double result_type;
    static const char* const arg_type;
    static const char* const res_type;
  };

  template<>
  struct arith_traits< Complex, Complex >
  {
    
    typedef Complex argument_type;
    typedef Complex result_type;
    static const char* const arg_type;
    static const char* const res_type;
  };

  template<>
  struct arith_traits< Complex, double >
  {
    typedef double argument_type;
    typedef Complex result_type;
    static const char* const arg_type;
    static const char* const res_type;
  };

  template<>
  struct arith_traits< double, Complex >
  {
    typedef double argument_type;
    typedef Complex result_type;
    static const char* const arg_type;
    static const char* const res_type;
  };

  template <class AF, class RF, class AG, class RG>
  inline
  ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
		     typename arith_traits< RF, RG >::result_type >
  make_Multiplies(const ArithUnaryFunction<AF, RF>& f,
		  const ArithUnaryFunction<AG, RG >& g)
  {
    return 
      ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
      typename arith_traits< RF, RG >::result_type>();
  }

#ifndef SWIG

// Initialize these static class members

const char* const arith_traits< double, double >::arg_type = "double";
const char* const arith_traits< double, double >::res_type = "double";

const char* const arith_traits< Complex, Complex >::arg_type = "complex";
const char* const arith_traits< Complex, Complex >::res_type = "complex";

const char* const arith_traits< Complex, double >::arg_type = "double";
const char* const arith_traits< Complex, double >::res_type = "complex";

const char* const arith_traits< double, Complex >::arg_type = "double";
const char* const arith_traits< double, Complex >::res_type = "complex";

#endif

} // end namespace vfncs

#ifdef SWIG

namespace vfncs {
  %template(UnaryFunction_double_double) UnaryFunction<double, double >;  
  %template(ArithUnaryFunction_double_double) ArithUnaryFunction<double, double >;  
  %template() unary_func_traits<double, double >;
  %template() arith_traits<double, double >;
  %template(make_Identity_double) make_Identity<double >;

  %template(UnaryFunction_complex_complex) UnaryFunction<Complex, Complex >;  
  %template(ArithUnaryFunction_complex_complex) ArithUnaryFunction<Complex, Complex >;  

  %template() unary_func_traits<Complex, Complex >;
  %template() arith_traits<Complex, Complex >;
  %template(make_Identity_complex) make_Identity<Complex >;

  /* [beazley] Added this part */
  %template() unary_func_traits<double,Complex>;
  %template(UnaryFunction_double_complex) UnaryFunction<double,Complex>;
  %template(ArithUnaryFunction_double_complex) ArithUnaryFunction<double,Complex>;

  /* */

  %template() arith_traits<Complex, double >;
  %template() arith_traits<double, Complex >;

  %template(make_Multiplies_double_double_complex_complex)
    make_Multiplies<double, double, Complex, Complex>;

  %template(make_Multiplies_double_double_double_double)
    make_Multiplies<double, double, double, double>;

  %template(make_Multiplies_complex_complex_complex_complex)
    make_Multiplies<Complex, Complex, Complex, Complex>;

  %template(make_Multiplies_complex_complex_double_double)
    make_Multiplies<Complex, Complex, double, double>;

}

#endif

#endif //___template_typedef_h__