1/* inout_typemaps.i
2
3   Support for INPUT, OUTPUT, and INOUT typemaps. OUTPUT variables are returned
4   as multiple values.
5
6*/
7
8
9/* Note that this macro automatically adds a pointer to the type passed in.
10   As a result, INOUT typemaps for char are for 'char *'. The definition
11   of typemaps for 'char' takes advantage of this, believing that it's more
12   likely to see an INOUT argument for strings, than a single char. */
13%define INOUT_TYPEMAP(type_, OUTresult_, INbind_)
14// OUTPUT map.
15%typemap(lin,numinputs=0) type_ *OUTPUT, type_ &OUTPUT
16%{(cl::let (($out (ff:allocate-fobject '$*in_fftype :c)))
17     $body
18     OUTresult_
19     (ff:free-fobject $out)) %}
20
21// INPUT map.
22%typemap(in) type_ *INPUT, type_ &INPUT
23%{ $1 = &$input; %}
24
25%typemap(ctype) type_ *INPUT, type_ &INPUT "$*1_ltype";
26
27
28// INOUT map.
29// careful here. the input string is converted to a C string
30// with length equal to the input string. This should be large
31// enough to contain whatever OUTPUT value will be stored in it.
32%typemap(lin,numinputs=1) type_ *INOUT, type_ &INOUT
33%{(cl::let (($out (ff:allocate-fobject '$*in_fftype :c)))
34     INbind_
35     $body
36     OUTresult_
37     (ff:free-fobject $out)) %}
38
39%enddef
40
41// $in, $out, $lclass,
42// $in_fftype, $*in_fftype
43
44INOUT_TYPEMAP(int,
45	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
46	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
47INOUT_TYPEMAP(short,
48	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
49	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
50INOUT_TYPEMAP(long,
51	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
52	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
53INOUT_TYPEMAP(unsigned int,
54	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
55	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
56INOUT_TYPEMAP(unsigned short,
57	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
58	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
59INOUT_TYPEMAP(unsigned long,
60	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
61	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
62// char * mapping for passing strings. didn't quite work
63// INOUT_TYPEMAP(char,
64//              (cl::push (excl:native-to-string $out) ACL_result),
65//	      (cl::setf (ff:fslot-value-typed (cl::quote $in_fftype) :c $out)
66//		    (excl:string-to-native $in)))
67INOUT_TYPEMAP(float,
68	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
69	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
70INOUT_TYPEMAP(double,
71	      (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result),
72	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
73INOUT_TYPEMAP(bool,
74	      (cl::push (not (zerop (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out)))
75		    ACL_result),
76	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) (if $in 1 0)));
77
78%typemap(lisptype) bool *INPUT, bool &INPUT "boolean";
79
80// long long support not yet complete
81// INOUT_TYPEMAP(long long);
82// INOUT_TYPEMAP(unsigned long long);
83
84// char *OUTPUT map.
85// for this to work, swig needs to know how large an array to allocate.
86// you can fake this by
87// %typemap(ffitype) char *myarg	"(:array :char 30)";
88// %apply char *OUTPUT { char *myarg };
89%typemap(lin,numinputs=0) char *OUTPUT, char &OUTPUT
90%{(cl::let (($out (ff:allocate-fobject '$*in_fftype :c)))
91     $body
92     (cl::push (excl:native-to-string $out) ACL_result)
93     (ff:free-fobject $out)) %}
94
95// char *INPUT map.
96%typemap(in) char *INPUT, char &INPUT
97%{ $1 = &$input; %}
98%typemap(ctype) char *INPUT, char &INPUT "$*1_ltype";
99
100// char *INOUT map.
101%typemap(lin,numinputs=1) char *INOUT, char &INOUT
102%{(cl::let (($out (excl:string-to-native $in)))
103     $body
104     (cl::push (excl:native-to-string $out) ACL_result)
105     (ff:free-fobject $out)) %}
106
107// uncomment this if you want INOUT mappings for chars instead of strings.
108// INOUT_TYPEMAP(char,
109// 	      (cl::push (code-char (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out))
110//		    ACL_result),
111//	      (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in));
112