PageRenderTime 33ms CodeModel.GetById 17ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/template_typedef_cplx2.h

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