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