PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Lib/csharp/wchar.i

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