PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/octave/std_basic_string.i

#
Swig | 89 lines | 75 code | 14 blank | 0 comment | 0 complexity | 9a3bc324573a48c7b75e5ce02ad6b748 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. #define SWIG_STD_MODERN_STL
  4. %include <octcontainer.swg>
  5. #define %swig_basic_string(Type...) %swig_sequence_methods_val(Type)
  6. %fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
  7. fragment="SWIG_AsCharPtrAndSize") {
  8. SWIGINTERN int
  9. SWIG_AsPtr(std::basic_string<char>)(octave_value obj, std::string **val)
  10. {
  11. if (obj.is_string()) {
  12. if (val)
  13. *val = new std::string(obj.string_value());
  14. return SWIG_NEWOBJ;
  15. }
  16. if (val)
  17. error("a string is expected");
  18. return 0;
  19. }
  20. }
  21. %fragment(SWIG_From_frag(std::basic_string<char>),"header",
  22. fragment="SWIG_FromCharPtrAndSize") {
  23. SWIGINTERNINLINE octave_value
  24. SWIG_From(std::basic_string<char>)(const std::string& s)
  25. {
  26. return SWIG_FromCharPtrAndSize(s.data(), s.size());
  27. }
  28. }
  29. %ignore std::basic_string::operator +=;
  30. %include <std/std_basic_string.i>
  31. %typemaps_asptrfromn(%checkcode(STRING), std::basic_string<char>);
  32. #endif
  33. #if !defined(SWIG_STD_WSTRING)
  34. %fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header",
  35. fragment="SWIG_AsWCharPtrAndSize") {
  36. SWIGINTERN int
  37. SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val)
  38. {
  39. static swig_type_info* string_info =
  40. SWIG_TypeQuery("std::basic_string<wchar_t> *");
  41. std::wstring *vptr;
  42. if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
  43. if (val) *val = vptr;
  44. return SWIG_OLDOBJ;
  45. } else {
  46. PyErr_Clear();
  47. wchar_t *buf = 0 ; size_t size = 0; int alloc = 0;
  48. if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
  49. if (buf) {
  50. if (val) *val = new std::wstring(buf, size - 1);
  51. if (alloc == SWIG_NEWOBJ) %delete_array(buf);
  52. return SWIG_NEWOBJ;
  53. }
  54. } else {
  55. PyErr_Clear();
  56. }
  57. if (val) {
  58. SWIG_PYTHON_THREAD_BEGIN_BLOCK;
  59. PyErr_SetString(PyExc_TypeError,"a wstring is expected");
  60. SWIG_PYTHON_THREAD_END_BLOCK;
  61. }
  62. return 0;
  63. }
  64. }
  65. }
  66. %fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header",
  67. fragment="SWIG_FromWCharPtrAndSize") {
  68. SWIGINTERNINLINE PyObject*
  69. SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s)
  70. {
  71. return SWIG_FromWCharPtrAndSize(s.data(), s.size());
  72. }
  73. }
  74. %typemaps_asptrfromn(%checkcode(UNISTRING), std::basic_string<wchar_t>);
  75. #endif