PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/typemaps/std_strings.swg

#
Unknown | 78 lines | 69 code | 9 blank | 0 comment | 0 complexity | 82b594c02b07504f87e410b7e3f14a44 MD5 | raw file
 1
 2/* defining the String asptr/from methods */
 3
 4%define %std_string_asptr(String, Char, SWIG_AsCharPtrAndSize, Frag)
 5%fragment(SWIG_AsPtr_frag(String),"header",fragment=Frag) {
 6SWIGINTERN int
 7SWIG_AsPtr_dec(String)(SWIG_Object obj, String **val) 
 8{
 9  Char* buf = 0 ; size_t size = 0; int alloc = SWIG_OLDOBJ;
10  if (SWIG_IsOK((SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc)))) {
11    if (buf) {
12      if (val) *val = new String(buf, size - 1);
13      if (alloc == SWIG_NEWOBJ) %delete_array(buf);
14      return SWIG_NEWOBJ;
15    } else {
16      if (val) *val = 0;
17      return SWIG_OLDOBJ;
18    }
19  } else {
20    static int init = 0;
21    static swig_type_info* descriptor = 0;
22    if (!init) {
23      descriptor = SWIG_TypeQuery(#String " *");
24      init = 1;
25    }
26    if (descriptor) {
27      String *vptr;
28      int res = SWIG_ConvertPtr(obj, (void**)&vptr, descriptor, 0);
29      if (SWIG_IsOK(res) && val) *val = vptr;
30      return res;
31    }
32  }
33  return SWIG_ERROR;
34}
35}
36%enddef
37
38%define %std_string_from(String, SWIG_FromCharPtrAndSize, Frag)
39%fragment(SWIG_From_frag(String),"header",fragment=Frag) {
40SWIGINTERNINLINE SWIG_Object
41SWIG_From_dec(String)(const String& s)
42{
43  return SWIG_FromCharPtrAndSize(s.data(), s.size());
44}
45}
46%enddef
47
48%define %std_string_asval(String)
49%fragment(SWIG_AsVal_frag(String),"header", fragment=SWIG_AsPtr_frag(String)) {
50SWIGINTERN int
51SWIG_AsVal_dec(String)(SWIG_Object obj, String *val)
52{
53  String* v = (String *) 0;
54  int res = SWIG_AsPtr(String)(obj, &v);
55  if (!SWIG_IsOK(res)) return res;
56  if (v) {
57    if (val) *val = *v;
58    if (SWIG_IsNewObj(res)) {
59      %delete(v);
60      res = SWIG_DelNewMask(res);
61    }
62    return res;
63  }
64  return SWIG_ERROR;
65}
66}
67%enddef
68
69
70%define %typemaps_std_string(String, Char, AsPtrMethod, FromMethod, CheckCode)
71
72%std_string_asptr(String, Char, AsPtrMethod, #AsPtrMethod)
73%std_string_asval(String)
74%std_string_from(String, FromMethod, #FromMethod)
75
76%typemaps_asptrfromn(%arg(CheckCode), String);
77
78%enddef