PageRenderTime 33ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/python/std_basic_string.i

#
Swig | 103 lines | 90 code | 13 blank | 0 comment | 0 complexity | 1f73ce7f1e479a864a3cc830f9efd263 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #if !defined(SWIG_STD_STRING)
  2. #define SWIG_STD_BASIC_STRING
  3. %include <pycontainer.swg>
  4. #define %swig_basic_string(Type...) %swig_sequence_methods_val(Type)
  5. %fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
  6. fragment="SWIG_AsCharPtrAndSize") {
  7. SWIGINTERN int
  8. SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val)
  9. {
  10. static swig_type_info* string_info =
  11. SWIG_TypeQuery("std::basic_string<char> *");
  12. std::string *vptr;
  13. if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
  14. if (val) *val = vptr;
  15. return SWIG_OLDOBJ;
  16. } else {
  17. PyErr_Clear();
  18. char* buf = 0 ; size_t size = 0; int alloc = 0;
  19. if (SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
  20. if (buf) {
  21. if (val) *val = new std::string(buf, size - 1);
  22. if (alloc == SWIG_NEWOBJ) %delete_array(buf);
  23. return SWIG_NEWOBJ;
  24. }
  25. } else {
  26. PyErr_Clear();
  27. }
  28. if (val) {
  29. SWIG_PYTHON_THREAD_BEGIN_BLOCK;
  30. PyErr_SetString(PyExc_TypeError,"a string is expected");
  31. SWIG_PYTHON_THREAD_END_BLOCK;
  32. }
  33. return 0;
  34. }
  35. }
  36. }
  37. %fragment(SWIG_From_frag(std::basic_string<char>),"header",
  38. fragment="SWIG_FromCharPtrAndSize") {
  39. SWIGINTERNINLINE PyObject*
  40. SWIG_From(std::basic_string<char>)(const std::string& s)
  41. {
  42. return SWIG_FromCharPtrAndSize(s.data(), s.size());
  43. }
  44. }
  45. %include <std/std_basic_string.i>
  46. %typemaps_asptrfromn(%checkcode(STRING), std::basic_string<char>);
  47. #endif
  48. #if !defined(SWIG_STD_WSTRING)
  49. %fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header",
  50. fragment="SWIG_AsWCharPtrAndSize") {
  51. SWIGINTERN int
  52. SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val)
  53. {
  54. static swig_type_info* string_info =
  55. SWIG_TypeQuery("std::basic_string<wchar_t> *");
  56. std::wstring *vptr;
  57. if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
  58. if (val) *val = vptr;
  59. return SWIG_OLDOBJ;
  60. } else {
  61. PyErr_Clear();
  62. wchar_t *buf = 0 ; size_t size = 0; int alloc = 0;
  63. if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
  64. if (buf) {
  65. if (val) *val = new std::wstring(buf, size - 1);
  66. if (alloc == SWIG_NEWOBJ) %delete_array(buf);
  67. return SWIG_NEWOBJ;
  68. }
  69. } else {
  70. PyErr_Clear();
  71. }
  72. if (val) {
  73. SWIG_PYTHON_THREAD_BEGIN_BLOCK;
  74. PyErr_SetString(PyExc_TypeError,"a wstring is expected");
  75. SWIG_PYTHON_THREAD_END_BLOCK;
  76. }
  77. return 0;
  78. }
  79. }
  80. }
  81. %fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header",
  82. fragment="SWIG_FromWCharPtrAndSize") {
  83. SWIGINTERNINLINE PyObject*
  84. SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s)
  85. {
  86. return SWIG_FromWCharPtrAndSize(s.data(), s.size());
  87. }
  88. }
  89. %typemaps_asptrfromn(%checkcode(UNISTRING), std::basic_string<wchar_t>);
  90. #endif