PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. #define reald double
  11. %{
  12. #define reald double
  13. %}
  14. #else
  15. %inline %{
  16. typedef double reald;
  17. %}
  18. #endif
  19. %inline %{
  20. // typedef double reald;
  21. namespace vfncs {
  22. struct UnaryFunctionBase
  23. {
  24. };
  25. template <class ArgType, class ResType>
  26. struct UnaryFunction;
  27. template <class ArgType, class ResType>
  28. struct ArithUnaryFunction;
  29. template <class ArgType, class ResType>
  30. struct UnaryFunction : UnaryFunctionBase
  31. {
  32. };
  33. template <class ArgType, class ResType>
  34. struct ArithUnaryFunction : UnaryFunction<ArgType, ResType>
  35. {
  36. };
  37. template <class ArgType, class ResType>
  38. struct unary_func_traits
  39. {
  40. typedef ArithUnaryFunction<ArgType, ResType > base;
  41. };
  42. template <class ArgType>
  43. inline
  44. typename unary_func_traits< ArgType, ArgType >::base
  45. make_Identity()
  46. {
  47. return typename unary_func_traits< ArgType, ArgType >::base();
  48. }
  49. template <class Arg1, class Arg2>
  50. struct arith_traits
  51. {
  52. };
  53. template<>
  54. struct arith_traits< float, float >
  55. {
  56. typedef float argument_type;
  57. typedef float result_type;
  58. static const char* const arg_type;
  59. static const char* const res_type;
  60. };
  61. template<>
  62. struct arith_traits< reald, reald >
  63. {
  64. typedef reald argument_type;
  65. typedef reald result_type;
  66. static const char* const arg_type;
  67. static const char* const res_type;
  68. };
  69. template<>
  70. struct arith_traits< reald, float >
  71. {
  72. typedef float argument_type;
  73. typedef reald result_type;
  74. static const char* const arg_type;
  75. static const char* const res_type;
  76. };
  77. template<>
  78. struct arith_traits< float, reald >
  79. {
  80. typedef float argument_type;
  81. typedef reald result_type;
  82. static const char* const arg_type;
  83. static const char* const res_type;
  84. };
  85. template <class AF, class RF, class AG, class RG>
  86. inline
  87. ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
  88. typename arith_traits< RF, RG >::result_type >
  89. make_Multiplies(const ArithUnaryFunction<AF, RF>& f,
  90. const ArithUnaryFunction<AG, RG >& g)
  91. {
  92. return
  93. ArithUnaryFunction<typename arith_traits< AF, AG >::argument_type,
  94. typename arith_traits< RF, RG >::result_type>();
  95. }
  96. #ifndef SWIG
  97. // Initialize these static class members
  98. const char* const arith_traits< float, float >::arg_type = "float";
  99. const char* const arith_traits< float, float >::res_type = "float";
  100. const char* const arith_traits< reald, reald >::arg_type = "reald";
  101. const char* const arith_traits< reald, reald >::res_type = "reald";
  102. const char* const arith_traits< reald, float >::arg_type = "float";
  103. const char* const arith_traits< reald, float >::res_type = "reald";
  104. const char* const arith_traits< float, reald >::arg_type = "float";
  105. const char* const arith_traits< float, reald >::res_type = "reald";
  106. #endif
  107. }
  108. %}
  109. namespace vfncs {
  110. %template(UnaryFunction_float_float) UnaryFunction<float, float >;
  111. %template(ArithUnaryFunction_float_float) ArithUnaryFunction<float, float >;
  112. %template() unary_func_traits<float, float >;
  113. %template() arith_traits<float, float >;
  114. %template(make_Identity_float) make_Identity<float >;
  115. %template(UnaryFunction_reald_reald) UnaryFunction<reald, reald >;
  116. %template(ArithUnaryFunction_reald_reald) ArithUnaryFunction<reald, reald >;
  117. %template() unary_func_traits<reald, reald >;
  118. %template() arith_traits<reald, reald >;
  119. %template(make_Identity_reald) make_Identity<reald >;
  120. /* [beazley] Added this part */
  121. %template() unary_func_traits<float,reald>;
  122. %template(UnaryFunction_float_reald) UnaryFunction<float,reald>;
  123. %template(ArithUnaryFunction_float_reald) ArithUnaryFunction<float,reald>;
  124. /* */
  125. %template() arith_traits<reald, float >;
  126. %template() arith_traits<float, reald >;
  127. %template() arith_traits<float, float >;
  128. %template(make_Multiplies_float_float_reald_reald)
  129. make_Multiplies<float, float, reald, reald>;
  130. %template(make_Multiplies_float_float_float_float)
  131. make_Multiplies<float, float, float, float>;
  132. %template(make_Multiplies_reald_reald_reald_reald)
  133. make_Multiplies<reald, reald, reald, reald>;
  134. }
  135. #ifdef SWIGPYTHON
  136. swig_type_info *SWIG_TypeQuery(const char* name);
  137. #endif