PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 179 lines | 135 code | 42 blank | 2 comment | 0 complexity | 7e291d85477cb6e6dfd08210d74d4610 MD5 | raw file
  1#ifdef SWIGPYTHON
  2%module("templatereduce") template_typedef
  3#else
  4%module template_typedef
  5#endif
  6//
  7// Change this to #if 1 to test the 'test'
  8//
  9#if 0
 10
 11#define reald double
 12%{
 13#define reald double
 14%}
 15
 16#else
 17
 18%inline %{
 19  typedef double reald;
 20%}
 21
 22#endif
 23
 24
 25%inline %{
 26
 27  //  typedef double reald;
 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< float, float >
 72    {
 73    
 74      typedef float argument_type;
 75      typedef float result_type;
 76      static const char* const arg_type;
 77      static const char* const res_type;
 78    };
 79
 80    template<>
 81    struct arith_traits< reald, reald >
 82    {
 83    
 84      typedef reald argument_type;
 85      typedef reald result_type;
 86      static const char* const arg_type;
 87      static const char* const res_type;
 88    };
 89
 90    template<>
 91    struct arith_traits< reald, float >
 92    {
 93      typedef float argument_type;
 94      typedef reald result_type;
 95      static const char* const arg_type;
 96      static const char* const res_type;
 97    };
 98
 99    template<>
100    struct arith_traits< float, reald >
101    {
102      typedef float argument_type;
103      typedef reald 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< float, float >::arg_type = "float";
125    const char* const arith_traits< float, float >::res_type = "float";
126
127    const char* const arith_traits< reald, reald >::arg_type = "reald";
128    const char* const arith_traits< reald, reald >::res_type = "reald";
129
130    const char* const arith_traits< reald, float >::arg_type = "float";
131    const char* const arith_traits< reald, float >::res_type = "reald";
132
133    const char* const arith_traits< float, reald >::arg_type = "float";
134    const char* const arith_traits< float, reald >::res_type = "reald";
135
136#endif
137
138  }
139%}
140
141namespace vfncs {  
142  %template(UnaryFunction_float_float) UnaryFunction<float, float >;  
143  %template(ArithUnaryFunction_float_float) ArithUnaryFunction<float, float >;  
144  %template() unary_func_traits<float, float >;
145  %template() arith_traits<float, float >;
146  %template(make_Identity_float) make_Identity<float >;
147
148  %template(UnaryFunction_reald_reald) UnaryFunction<reald, reald >;  
149  %template(ArithUnaryFunction_reald_reald) ArithUnaryFunction<reald, reald >;  
150
151  %template() unary_func_traits<reald, reald >;
152  %template() arith_traits<reald, reald >;
153  %template(make_Identity_reald) make_Identity<reald >;
154
155  /* [beazley] Added this part */
156  %template() unary_func_traits<float,reald>;
157  %template(UnaryFunction_float_reald) UnaryFunction<float,reald>;
158  %template(ArithUnaryFunction_float_reald) ArithUnaryFunction<float,reald>;
159
160  /* */
161
162  %template() arith_traits<reald, float >;
163  %template() arith_traits<float, reald >;
164  %template() arith_traits<float, float >;
165
166  %template(make_Multiplies_float_float_reald_reald)
167    make_Multiplies<float, float, reald, reald>;
168
169  %template(make_Multiplies_float_float_float_float)
170    make_Multiplies<float, float, float, float>;
171
172  %template(make_Multiplies_reald_reald_reald_reald)
173    make_Multiplies<reald, reald, reald, reald>;
174
175}
176
177#ifdef SWIGPYTHON
178swig_type_info *SWIG_TypeQuery(const char* name);
179#endif