PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/typemaps/cdata.swg

#
Unknown | 76 lines | 61 code | 15 blank | 0 comment | 0 complexity | 90302f136c1e40fcab5f31a819c3ea8a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * cdata.swg
  3. *
  4. * This library file contains macros for manipulating raw C data as strings.
  5. * ----------------------------------------------------------------------------- */
  6. %{
  7. typedef struct SWIGCDATA {
  8. char *data;
  9. size_t len;
  10. } SWIGCDATA;
  11. %}
  12. /* -----------------------------------------------------------------------------
  13. * Typemaps for returning binary data
  14. * ----------------------------------------------------------------------------- */
  15. %typemap(out,noblock=1,fragment="SWIG_FromCharPtrAndSize") SWIGCDATA {
  16. %set_output(SWIG_FromCharPtrAndSize($1.data,$1.len));
  17. }
  18. %typemap(in) (const void *indata, size_t inlen) = (char *STRING, size_t SIZE);
  19. /* -----------------------------------------------------------------------------
  20. * %cdata(TYPE [, NAME])
  21. *
  22. * Convert raw C data to a binary string.
  23. * ----------------------------------------------------------------------------- */
  24. %define %cdata(TYPE,NAME...)
  25. %insert("header") {
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #if #NAME == ""
  30. static SWIGCDATA cdata_##TYPE(TYPE *ptr, size_t nelements)
  31. #else
  32. static SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements)
  33. #endif
  34. {
  35. SWIGCDATA d;
  36. d.data = (char *) ptr;
  37. #if #TYPE != "void"
  38. d.len = nelements*sizeof(TYPE);
  39. #else
  40. d.len = nelements;
  41. #endif
  42. return d;
  43. }
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. }
  48. #ifdef __cplusplus
  49. extern "C"
  50. #endif
  51. #if #NAME == ""
  52. SWIGCDATA cdata_##TYPE(TYPE *ptr, size_t nelements = 1);
  53. #else
  54. SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements = 1);
  55. #endif
  56. %enddef
  57. %rename(cdata) ::cdata_void(void *ptr, size_t nelements = 1);
  58. %cdata(void);
  59. /* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
  60. void memmove(void *data, const char *s); */
  61. void memmove(void *data, const void *indata, size_t inlen);