summaryrefslogtreecommitdiff
path: root/Examples/test-suite/template_typedef.i
blob: b6128e1fa94142360ef05036df003430809abece (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
176
177
178
179
#ifdef SWIGPYTHON
%module("templatereduce") template_typedef
#else
%module template_typedef
#endif
//
// Change this to #if 1 to test the 'test'
//
#if 0

#define reald double
%{
#define reald double
%}

#else

%inline %{
  typedef double reald;
%}

#endif


%inline %{

  //  typedef double reald;

  namespace vfncs {

    struct UnaryFunctionBase
    {
    };    
    
    template <class ArgType, class ResType>
    struct UnaryFunction;
    
    template <class ArgType, class ResType>
    struct ArithUnaryFunction;  
    
    template <class ArgType, class ResType>
    struct UnaryFunction : UnaryFunctionBase
    {
    };

    template <class ArgType, class ResType>
    struct ArithUnaryFunction : UnaryFunction<ArgType, ResType>
    {
    };      
    
    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< float, float >
    {
    
      typedef float argument_type;
      typedef float result_type;
      static const char* const arg_type;
      static const char* const res_type;
    };

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

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

    template<>
    struct arith_traits< float, reald >
    {
      typedef float argument_type;
      typedef reald 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< float, float >::arg_type = "float";
    const char* const arith_traits< float, float >::res_type = "float";

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

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

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

#endif

  }
%}

namespace vfncs {  
  %template(UnaryFunction_float_float) UnaryFunction<float, float >;  
  %template(ArithUnaryFunction_float_float) ArithUnaryFunction<float, float >;  
  %template() unary_func_traits<float, float >;
  %template() arith_traits<float, float >;
  %template(make_Identity_float) make_Identity<float >;

  %template(UnaryFunction_reald_reald) UnaryFunction<reald, reald >;  
  %template(ArithUnaryFunction_reald_reald) ArithUnaryFunction<reald, reald >;  

  %template() unary_func_traits<reald, reald >;
  %template() arith_traits<reald, reald >;
  %template(make_Identity_reald) make_Identity<reald >;

  /* [beazley] Added this part */
  %template() unary_func_traits<float,reald>;
  %template(UnaryFunction_float_reald) UnaryFunction<float,reald>;
  %template(ArithUnaryFunction_float_reald) ArithUnaryFunction<float,reald>;

  /* */

  %template() arith_traits<reald, float >;
  %template() arith_traits<float, reald >;
  %template() arith_traits<float, float >;

  %template(make_Multiplies_float_float_reald_reald)
    make_Multiplies<float, float, reald, reald>;

  %template(make_Multiplies_float_float_float_float)
    make_Multiplies<float, float, float, float>;

  %template(make_Multiplies_reald_reald_reald_reald)
    make_Multiplies<reald, reald, reald, reald>;

}

#ifdef SWIGPYTHON
swig_type_info *SWIG_TypeQuery(const char* name);
#endif