PageRenderTime 39ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 178 lines | 132 code | 44 blank | 2 comment | 0 complexity | 0c02963de750757dabf20cb0c17bed82 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module template_typedef_cplx
  2. //
  3. // Change this to #if 1 to test the 'test'
  4. //
  5. #if 0
  6. %{
  7. #include <complex>
  8. typedef std::complex<double> cmplx;
  9. %}
  10. %inline %{
  11. typedef cmplx Complex;
  12. %}
  13. #else
  14. %inline %{
  15. #include <complex>
  16. typedef std::complex<double> Complex;
  17. %}
  18. #endif
  19. %inline %{
  20. namespace vfncs {
  21. struct UnaryFunctionBase
  22. {
  23. };
  24. template <class ArgType, class ResType>
  25. struct UnaryFunction;
  26. template <class ArgType, class ResType>
  27. struct ArithUnaryFunction;
  28. template <class ArgType, class ResType>
  29. struct UnaryFunction : UnaryFunctionBase
  30. {
  31. };
  32. template <class ArgType, class ResType>
  33. struct ArithUnaryFunction : UnaryFunction<ArgType, ResType>
  34. {
  35. };
  36. template <class ArgType, class ResType>
  37. struct unary_func_traits
  38. {
  39. typedef ArithUnaryFunction<ArgType, ResType > base;
  40. };
  41. template <class ArgType>
  42. inline
  43. typename unary_func_traits< ArgType, ArgType >::base
  44. make_Identity()
  45. {
  46. return typename unary_func_traits< ArgType, ArgType >::base();
  47. }
  48. template <class Arg1, class Arg2>
  49. struct arith_traits
  50. {
  51. };
  52. template<>
  53. struct arith_traits< double, double >
  54. {
  55. typedef double argument_type;
  56. typedef double result_type;
  57. static const char* const arg_type;
  58. static const char* const res_type;
  59. };
  60. template<>
  61. struct arith_traits< Complex, Complex >
  62. {
  63. typedef Complex argument_type;
  64. typedef Complex result_type;
  65. static const char* const arg_type;
  66. static const char* const res_type;
  67. };
  68. template<>
  69. struct arith_traits< Complex, double >
  70. {
  71. typedef double argument_type;
  72. typedef Complex result_type;
  73. static const char* const arg_type;
  74. static const char* const res_type;
  75. };
  76. template<>
  77. struct arith_traits< double, Complex >
  78. {
  79. typedef double argument_type;
  80. typedef Complex result_type;
  81. static const char* const arg_type;
  82. static const char* const res_type;
  83. };
  84. template <class AF, class RF, class AG, class RG>
  85. inline
  86. ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
  87. typename arith_traits< RF, RG >::result_type >
  88. make_Multiplies(const ArithUnaryFunction<AF, RF>& f,
  89. const ArithUnaryFunction<AG, RG >& g)
  90. {
  91. return
  92. ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
  93. typename arith_traits< RF, RG >::result_type>();
  94. }
  95. #ifndef SWIG
  96. // Initialize these static class members
  97. const char* const arith_traits< double, double >::arg_type = "double";
  98. const char* const arith_traits< double, double >::res_type = "double";
  99. const char* const arith_traits< Complex, Complex >::arg_type = "complex";
  100. const char* const arith_traits< Complex, Complex >::res_type = "complex";
  101. const char* const arith_traits< Complex, double>::arg_type = "double";
  102. const char* const arith_traits< Complex, double >::res_type = "complex";
  103. const char* const arith_traits< double, Complex >::arg_type = "double";
  104. const char* const arith_traits< double, Complex >::res_type = "complex";
  105. #endif
  106. }
  107. %}
  108. namespace vfncs {
  109. %template(UnaryFunction_double_double) UnaryFunction<double, double >;
  110. %template(ArithUnaryFunction_double_double) ArithUnaryFunction<double, double >;
  111. %template() unary_func_traits<double, double >;
  112. %template() arith_traits<double, double >;
  113. %template(make_Identity_double) make_Identity<double >;
  114. %template(UnaryFunction_complex_complex) UnaryFunction<Complex, Complex >;
  115. %template(ArithUnaryFunction_complex_complex) ArithUnaryFunction<Complex, Complex >;
  116. %template() unary_func_traits<Complex, Complex >;
  117. %template() arith_traits<Complex, Complex >;
  118. %template(make_Identity_complex) make_Identity<Complex >;
  119. /* [beazley] Added this part */
  120. %template() unary_func_traits<double,Complex>;
  121. %template(UnaryFunction_double_complex) UnaryFunction<double,Complex>;
  122. %template(ArithUnaryFunction_double_complex) ArithUnaryFunction<double,Complex>;
  123. /* */
  124. %template() arith_traits<Complex, double >;
  125. %template() arith_traits<double, Complex >;
  126. %template(make_Multiplies_double_double_complex_complex)
  127. make_Multiplies<double, double, Complex, Complex>;
  128. %template(make_Multiplies_double_double_double_double)
  129. make_Multiplies<double, double, double, double>;
  130. %template(make_Multiplies_complex_complex_complex_complex)
  131. make_Multiplies<Complex, Complex, Complex, Complex>;
  132. %template(make_Multiplies_complex_complex_double_double)
  133. make_Multiplies<Complex, Complex, double, double>;
  134. }