PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/csharp/wchar.i

#
Swig | 102 lines | 74 code | 18 blank | 10 comment | 0 complexity | 41b57da414c6b78f8d56725032d9b338 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. #if !defined(SWIG_CSHARP_NO_WSTRING_HELPER)
  11. #if !defined(SWIG_CSHARP_WSTRING_HELPER_)
  12. #define SWIG_CSHARP_WSTRING_HELPER_
  13. %insert(runtime) %{
  14. /* Callback for returning strings to C# without leaking memory */
  15. typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);
  16. static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
  17. %}
  18. %pragma(csharp) imclasscode=%{
  19. protected class SWIGWStringHelper {
  20. public delegate string SWIGWStringDelegate(IntPtr message);
  21. static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);
  22. [DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")]
  23. public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate);
  24. static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) {
  25. return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);
  26. }
  27. static SWIGWStringHelper() {
  28. SWIGRegisterWStringCallback_$module(wstringDelegate);
  29. }
  30. }
  31. static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper();
  32. %}
  33. %insert(runtime) %{
  34. #ifdef __cplusplus
  35. extern "C"
  36. #endif
  37. SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) {
  38. SWIG_csharp_wstring_callback = callback;
  39. }
  40. %}
  41. #endif // SWIG_CSHARP_WSTRING_HELPER_
  42. #endif // SWIG_CSHARP_NO_WSTRING_HELPER
  43. // wchar_t
  44. %typemap(ctype) wchar_t "wchar_t"
  45. %typemap(imtype) wchar_t "char"
  46. %typemap(cstype) wchar_t "char"
  47. %typemap(csin) wchar_t "$csinput"
  48. %typemap(csout, excode=SWIGEXCODE) wchar_t {
  49. char ret = $imcall;$excode
  50. return ret;
  51. }
  52. %typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{
  53. set {
  54. $imcall;$excode
  55. } %}
  56. %typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{
  57. get {
  58. char ret = $imcall;$excode
  59. return ret;
  60. } %}
  61. %typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %}
  62. %typemap(out) wchar_t %{ $result = (wchar_t)$1; %}
  63. %typemap(typecheck) wchar_t = char;
  64. // wchar_t *
  65. %typemap(ctype) wchar_t * "wchar_t *"
  66. %typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string"
  67. %typemap(cstype) wchar_t * "string"
  68. %typemap(csin) wchar_t * "$csinput"
  69. %typemap(csout, excode=SWIGEXCODE) wchar_t * {
  70. string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
  71. return ret;
  72. }
  73. %typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{
  74. set {
  75. $imcall;$excode
  76. } %}
  77. %typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
  78. get {
  79. string ret = $imcall;$excode
  80. return ret;
  81. } %}
  82. %typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %}
  83. %typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %}
  84. %typemap(typecheck) wchar_t * = char *;