Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.5 KiB

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