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