PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/Lib/allegrocl/inout_typemaps.i

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