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