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