dprimitives.swg 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* -----------------------------------------------------------------------------
  2. * dprimitves.swg
  3. *
  4. * Typemaps for primitive types.
  5. * ----------------------------------------------------------------------------- */
  6. // C long/ulong width depends on the target arch, use stdlib aliases for them.
  7. #if (SWIG_D_VERSION == 1)
  8. %pragma(d) imdmoduleimports = "static import tango.stdc.config;"
  9. %pragma(d) globalproxyimports = "static import tango.stdc.config;"
  10. #define SWIG_LONG_DTYPE tango.stdc.config.c_long
  11. #define SWIG_ULONG_DTYPE tango.stdc.config.c_ulong
  12. #else
  13. %pragma(d) imdmoduleimports = "static import core.stdc.config;"
  14. %pragma(d) globalproxyimports = "static import core.stdc.config;"
  15. #define SWIG_LONG_DTYPE core.stdc.config.c_long
  16. #define SWIG_ULONG_DTYPE core.stdc.config.c_ulong
  17. #endif
  18. /*
  19. * The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive
  20. * types, because are more or less the same for all of them. The few special
  21. * cases are handeled below.
  22. */
  23. %define SWIG_D_PRIMITIVE(TYPE, DTYPE)
  24. %typemap(ctype) TYPE, const TYPE & "TYPE"
  25. %typemap(imtype) TYPE, const TYPE & "DTYPE"
  26. %typemap(dtype, cprimitive="1") TYPE, const TYPE & "DTYPE"
  27. %typemap(in) TYPE "$1 = ($1_ltype)$input;"
  28. %typemap(out) TYPE "$result = $1;"
  29. %typemap(directorin) TYPE "$input = $1;"
  30. %typemap(directorout) TYPE "$result = ($1_ltype)$input;"
  31. %typemap(ddirectorin) TYPE "$winput"
  32. %typemap(ddirectorout) TYPE "$dcall"
  33. %typemap(in) const TYPE & ($*1_ltype temp)
  34. %{ temp = ($*1_ltype)$input;
  35. $1 = &temp; %}
  36. %typemap(out) const TYPE & "$result = *$1;"
  37. %typemap(directorin) const TYPE & "$input = $1;"
  38. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const TYPE &
  39. %{ static $*1_ltype temp;
  40. temp = ($*1_ltype)$input;
  41. $result = &temp; %}
  42. %typemap(ddirectorin) const TYPE & "$winput"
  43. %typemap(ddirectorout) const TYPE & "$dcall"
  44. %typemap(din) TYPE, const TYPE & "$dinput"
  45. %typemap(dout, excode=SWIGEXCODE) TYPE, const TYPE & {
  46. auto ret = $imcall;$excode
  47. return ret;
  48. }
  49. %enddef
  50. SWIG_D_PRIMITIVE(bool, bool)
  51. SWIG_D_PRIMITIVE(char, char)
  52. SWIG_D_PRIMITIVE(signed char, byte)
  53. SWIG_D_PRIMITIVE(unsigned char, ubyte)
  54. SWIG_D_PRIMITIVE(short, short)
  55. SWIG_D_PRIMITIVE(unsigned short, ushort)
  56. SWIG_D_PRIMITIVE(int, int)
  57. SWIG_D_PRIMITIVE(unsigned int, uint)
  58. SWIG_D_PRIMITIVE(long, SWIG_LONG_DTYPE)
  59. SWIG_D_PRIMITIVE(unsigned long, SWIG_ULONG_DTYPE)
  60. SWIG_D_PRIMITIVE(size_t, size_t)
  61. SWIG_D_PRIMITIVE(long long, long)
  62. SWIG_D_PRIMITIVE(unsigned long long, ulong)
  63. SWIG_D_PRIMITIVE(float, float)
  64. SWIG_D_PRIMITIVE(double, double)
  65. // The C++ boolean type needs some special casing since it is not part of the
  66. // C standard and is thus represented as unsigned int in the C wrapper layer.
  67. %typemap(ctype) bool, const bool & "unsigned int"
  68. %typemap(imtype) bool, const bool & "uint"
  69. %typemap(in) bool "$1 = $input ? true : false;"
  70. %typemap(in) const bool & ($*1_ltype temp)
  71. %{ temp = $input ? true : false;
  72. $1 = &temp; %}
  73. %typemap(directorout) bool
  74. "$result = $input ? true : false;"
  75. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
  76. %{ static $*1_ltype temp;
  77. temp = $input ? true : false;
  78. $result = &temp; %}
  79. %typemap(ddirectorin) bool "($winput ? true : false)"
  80. %typemap(dout, excode=SWIGEXCODE) bool, const bool & {
  81. bool ret = $imcall ? true : false;$excode
  82. return ret;
  83. }
  84. // Judging from the history of the C# module, the explicit casts are needed for
  85. // certain versions of VC++.
  86. %typemap(out) unsigned long "$result = (unsigned long)$1;"
  87. %typemap(out) const unsigned long & "$result = (unsigned long)*$1;"
  88. /*
  89. * Typecheck typemaps.
  90. */
  91. %typecheck(SWIG_TYPECHECK_BOOL)
  92. bool,
  93. const bool &
  94. ""
  95. %typecheck(SWIG_TYPECHECK_CHAR)
  96. char,
  97. const char &
  98. ""
  99. %typecheck(SWIG_TYPECHECK_INT8)
  100. signed char,
  101. const signed char &
  102. ""
  103. %typecheck(SWIG_TYPECHECK_UINT8)
  104. unsigned char,
  105. const unsigned char &
  106. ""
  107. %typecheck(SWIG_TYPECHECK_INT16)
  108. short,
  109. const short &
  110. ""
  111. %typecheck(SWIG_TYPECHECK_UINT16)
  112. unsigned short,
  113. const unsigned short &
  114. ""
  115. %typecheck(SWIG_TYPECHECK_INT32)
  116. int,
  117. long,
  118. const int &,
  119. const long &
  120. ""
  121. %typecheck(SWIG_TYPECHECK_UINT32)
  122. unsigned int,
  123. unsigned long,
  124. const unsigned int &,
  125. const unsigned long &
  126. ""
  127. %typecheck(SWIG_TYPECHECK_INT64)
  128. long long,
  129. const long long &
  130. ""
  131. %typecheck(SWIG_TYPECHECK_UINT64)
  132. unsigned long long,
  133. const unsigned long long &
  134. ""
  135. %typecheck(SWIG_TYPECHECK_FLOAT)
  136. float,
  137. const float &
  138. ""
  139. %typecheck(SWIG_TYPECHECK_DOUBLE)
  140. double,
  141. const double &
  142. ""