PageRenderTime 42ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-15/SWIG/Examples/test-suite/template_typedef_cplx2.h

#
C++ Header | 156 lines | 123 code | 31 blank | 2 comment | 0 complexity | 0dfc7f6ff35812791b973fc8de08f654 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #ifndef ___typedef_import_h__
  2. #define ___typedef_import_h__
  3. #ifdef SWIG
  4. %module template_typedef_cplx2;
  5. #endif
  6. #include <complex>
  7. typedef std::complex<double> Complex;
  8. namespace vfncs {
  9. struct UnaryFunctionBase
  10. {
  11. int get_base_value()
  12. {
  13. return 0;
  14. }
  15. };
  16. template <class ArgType, class ResType>
  17. class UnaryFunction;
  18. template <class ArgType, class ResType>
  19. class ArithUnaryFunction;
  20. template <class ArgType, class ResType>
  21. struct UnaryFunction : UnaryFunctionBase
  22. {
  23. int get_value()
  24. {
  25. return 1;
  26. }
  27. };
  28. template <class ArgType, class ResType>
  29. struct ArithUnaryFunction : UnaryFunction<ArgType, ResType>
  30. {
  31. int get_arith_value()
  32. {
  33. return 2;
  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 = "double";
  58. static const char* const res_type = "double";
  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 = "complex";
  66. static const char* const res_type = "complex";
  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 = "double";
  74. static const char* const res_type = "complex";
  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 = "double";
  82. static const char* const res_type = "complex";
  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. }
  96. #ifdef SWIG
  97. namespace vfncs {
  98. %template(UnaryFunction_double_double) UnaryFunction<double, double >;
  99. %template(ArithUnaryFunction_double_double) ArithUnaryFunction<double, double >;
  100. %template() unary_func_traits<double, double >;
  101. %template() arith_traits<double, double >;
  102. %template(make_Identity_double) make_Identity<double >;
  103. %template(UnaryFunction_complex_complex) UnaryFunction<Complex, Complex >;
  104. %template(ArithUnaryFunction_complex_complex) ArithUnaryFunction<Complex, Complex >;
  105. %template() unary_func_traits<Complex, Complex >;
  106. %template() arith_traits<Complex, Complex >;
  107. %template(make_Identity_complex) make_Identity<Complex >;
  108. /* [beazley] Added this part */
  109. %template() unary_func_traits<double,Complex>;
  110. %template(UnaryFunction_double_complex) UnaryFunction<double,Complex>;
  111. %template(ArithUnaryFunction_double_complex) ArithUnaryFunction<double,Complex>;
  112. /* */
  113. %template() arith_traits<Complex, double >;
  114. %template() arith_traits<double, Complex >;
  115. %template(make_Multiplies_double_double_complex_complex)
  116. make_Multiplies<double, double, Complex, Complex>;
  117. %template(make_Multiplies_double_double_double_double)
  118. make_Multiplies<double, double, double, double>;
  119. %template(make_Multiplies_complex_complex_complex_complex)
  120. make_Multiplies<Complex, Complex, Complex, Complex>;
  121. %template(make_Multiplies_complex_complex_double_double)
  122. make_Multiplies<Complex, Complex, double, double>;
  123. }
  124. #endif
  125. #endif //___template_typedef_h__