PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/typemaps/typemaps.swg

#
Unknown | 157 lines | 118 code | 39 blank | 0 comment | 0 complexity | b5a49bb17c8f177cd6f4ee787b06322b MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * typemaps.swg
  3. *
  4. * Tcl Pointer handling
  5. *
  6. * These mappings provide support for input/output arguments and common
  7. * uses for C/C++ pointers.
  8. * ----------------------------------------------------------------------------- */
  9. // INPUT typemaps.
  10. // These remap a C pointer to be an "INPUT" value which is passed by value
  11. // instead of reference.
  12. /*
  13. The following methods can be applied to turn a pointer into a simple
  14. "input" value. That is, instead of passing a pointer to an object,
  15. you would use a real value instead.
  16. int *INPUT
  17. short *INPUT
  18. long *INPUT
  19. long long *INPUT
  20. unsigned int *INPUT
  21. unsigned short *INPUT
  22. unsigned long *INPUT
  23. unsigned long long *INPUT
  24. unsigned char *INPUT
  25. bool *INPUT
  26. float *INPUT
  27. double *INPUT
  28. To use these, suppose you had a C function like this :
  29. double fadd(double *a, double *b) {
  30. return *a+*b;
  31. }
  32. You could wrap it with SWIG as follows :
  33. %include <typemaps.i>
  34. double fadd(double *INPUT, double *INPUT);
  35. or you can use the %apply directive :
  36. %include <typemaps.i>
  37. %apply double *INPUT { double *a, double *b };
  38. double fadd(double *a, double *b);
  39. */
  40. // OUTPUT typemaps. These typemaps are used for parameters that
  41. // are output only. The output value is appended to the result as
  42. // a list element.
  43. /*
  44. The following methods can be applied to turn a pointer into an "output"
  45. value. When calling a function, no input value would be given for
  46. a parameter, but an output value would be returned. In the case of
  47. multiple output values, they are returned in the form of a Tcl tuple.
  48. int *OUTPUT
  49. short *OUTPUT
  50. long *OUTPUT
  51. long long *OUTPUT
  52. unsigned int *OUTPUT
  53. unsigned short *OUTPUT
  54. unsigned long *OUTPUT
  55. unsigned long long *OUTPUT
  56. unsigned char *OUTPUT
  57. bool *OUTPUT
  58. float *OUTPUT
  59. double *OUTPUT
  60. For example, suppose you were trying to wrap the modf() function in the
  61. C math library which splits x into integral and fractional parts (and
  62. returns the integer part in one of its parameters).K:
  63. double modf(double x, double *ip);
  64. You could wrap it with SWIG as follows :
  65. %include <typemaps.i>
  66. double modf(double x, double *OUTPUT);
  67. or you can use the %apply directive :
  68. %include <typemaps.i>
  69. %apply double *OUTPUT { double *ip };
  70. double modf(double x, double *ip);
  71. The Tcl output of the function would be a tuple containing both
  72. output values.
  73. */
  74. // INOUT
  75. // Mappings for an argument that is both an input and output
  76. // parameter
  77. /*
  78. The following methods can be applied to make a function parameter both
  79. an input and output value. This combines the behavior of both the
  80. "INPUT" and "OUTPUT" methods described earlier. Output values are
  81. returned in the form of a Tcl tuple.
  82. int *INOUT
  83. short *INOUT
  84. long *INOUT
  85. long long *INOUT
  86. unsigned int *INOUT
  87. unsigned short *INOUT
  88. unsigned long *INOUT
  89. unsigned long long *INOUT
  90. unsigned char *INOUT
  91. bool *INOUT
  92. float *INOUT
  93. double *INOUT
  94. For example, suppose you were trying to wrap the following function :
  95. void neg(double *x) {
  96. *x = -(*x);
  97. }
  98. You could wrap it with SWIG as follows :
  99. %include <typemaps.i>
  100. void neg(double *INOUT);
  101. or you can use the %apply directive :
  102. %include <typemaps.i>
  103. %apply double *INOUT { double *x };
  104. void neg(double *x);
  105. Unlike C, this mapping does not directly modify the input value (since
  106. this makes no sense in Tcl). Rather, the modified input value shows
  107. up as the return value of the function. Thus, to apply this function
  108. to a Tcl variable you might do this :
  109. x = neg(x)
  110. Note : previous versions of SWIG used the symbol 'BOTH' to mark
  111. input/output arguments. This is still supported, but will be slowly
  112. phased out in future releases.
  113. */
  114. #if defined(SWIG_INOUT_NODEF)
  115. %apply_checkctypes(%typemaps_inoutn)
  116. %apply size_t& { std::size_t& };
  117. %apply ptrdiff_t& { std::ptrdiff_t& };
  118. #endif