import source from 1.3.40
[external/swig.git] / Lib / csharp / wchar.i
1 /* -----------------------------------------------------------------------------\r
2  * See the LICENSE file for information on copyright, usage and redistribution\r
3  * of SWIG, and the README file for authors - http://www.swig.org/release.html.\r
4  *\r
5  * wchar.i\r
6  *\r
7  * Typemaps for the wchar_t type\r
8  * These are mapped to a C# String and are passed around by value.\r
9  *\r
10  * Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER\r
11  *\r
12  * ----------------------------------------------------------------------------- */\r
13 \r
14 #if !defined(SWIG_CSHARP_NO_WSTRING_HELPER)\r
15 #if !defined(SWIG_CSHARP_WSTRING_HELPER_)\r
16 #define SWIG_CSHARP_WSTRING_HELPER_\r
17 %insert(runtime) %{\r
18 /* Callback for returning strings to C# without leaking memory */\r
19 typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);\r
20 static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;\r
21 %}\r
22 \r
23 %pragma(csharp) imclasscode=%{\r
24   protected class SWIGWStringHelper {\r
25 \r
26     public delegate string SWIGWStringDelegate(IntPtr message);\r
27     static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);\r
28 \r
29     [DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")]\r
30     public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate);\r
31 \r
32     static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) {\r
33       return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);\r
34     }\r
35 \r
36     static SWIGWStringHelper() {\r
37       SWIGRegisterWStringCallback_$module(wstringDelegate);\r
38     }\r
39   }\r
40 \r
41   static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper();\r
42 %}\r
43 \r
44 %insert(runtime) %{\r
45 #ifdef __cplusplus\r
46 extern "C"\r
47 #endif\r
48 SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) {\r
49   SWIG_csharp_wstring_callback = callback;\r
50 }\r
51 %}\r
52 #endif // SWIG_CSHARP_WSTRING_HELPER_\r
53 #endif // SWIG_CSHARP_NO_WSTRING_HELPER\r
54 \r
55 \r
56 // wchar_t\r
57 %typemap(ctype) wchar_t "wchar_t"\r
58 %typemap(imtype) wchar_t "char"\r
59 %typemap(cstype) wchar_t "char"\r
60 \r
61 %typemap(csin) wchar_t "$csinput"\r
62 %typemap(csout, excode=SWIGEXCODE) wchar_t {\r
63     char ret = $imcall;$excode\r
64     return ret;\r
65   }\r
66 %typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{\r
67     set {\r
68       $imcall;$excode\r
69     } %}\r
70 %typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{\r
71     get {\r
72       char ret = $imcall;$excode\r
73       return ret;\r
74     } %}\r
75 \r
76 %typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %}\r
77 %typemap(out) wchar_t %{ $result = (wchar_t)$1; %}\r
78 \r
79 %typemap(typecheck) wchar_t = char;\r
80 \r
81 // wchar_t *\r
82 %typemap(ctype) wchar_t * "wchar_t *"\r
83 %typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string"\r
84 %typemap(cstype) wchar_t * "string"\r
85 \r
86 %typemap(csin) wchar_t * "$csinput"\r
87 %typemap(csout, excode=SWIGEXCODE) wchar_t * {\r
88     string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode\r
89     return ret;\r
90   }\r
91 %typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{\r
92     set {\r
93       $imcall;$excode\r
94     } %}\r
95 %typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{\r
96     get {\r
97       string ret = $imcall;$excode\r
98       return ret;\r
99     } %}\r
100 \r
101 %typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %}\r
102 %typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %}\r
103 \r
104 %typemap(typecheck) wchar_t * = char *;\r
105 \r