PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Lib/typemaps/cdata.swg

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