PageRenderTime 57ms CodeModel.GetById 54ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/csharp/wchar.i

#
Swig | 102 lines | 74 code | 18 blank | 10 comment | 0 complexity | 41b57da414c6b78f8d56725032d9b338 MD5 | raw file
  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 */
 16typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);
 17static 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
 43extern "C"
 44#endif
 45SWIGEXPORT 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