1 /* ----------------------------------------------------------------------------- 2 * std_string.i 3 * 4 * SWIG typemaps for std::string 5 * ----------------------------------------------------------------------------- */ 6 7 %{ 8 #include <string> 9 %} 10 11 namespace std { 12 %naturalvar string; 13 14 15 %insert(closprefix) %{ (declare (hide <std-string>)) %} 16 %nodefault string; 17 %rename("std-string") string; 18 class string { 19 public: 20 ~string() {} 21 }; 22 %extend string { 23 char *str; 24 } 25 %{ 26 #define std_string_str_get(s) ((char *)((s)->c_str())) 27 #define std_string_str_set(s,v) (s->assign((char *)(v))) 28 %} 29 30 %typemap(typecheck) string = char *; 31 %typemap(typecheck) const string & = char *; 32 33 %typemap(in) string (char * tempptr) { 34 if ($input == C_SCHEME_FALSE) { 35 $1.resize(0); 36 } else { 37 if (!C_swig_is_string ($input)) { 38 swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, 39 "Argument #$argnum is not a string"); 40 } 41 tempptr = SWIG_MakeString($input); 42 $1.assign(tempptr); 43 if (tempptr) SWIG_free(tempptr); 44 } 45 } 46 47 %typemap(in) const string& ($*1_ltype temp, char *tempptr) { 48 49 if ($input == C_SCHEME_FALSE) { 50 temp.resize(0); 51 $1 = &temp; 52 } else { 53 if (!C_swig_is_string ($input)) { 54 swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, 55 "Argument #$argnum is not a string"); 56 } 57 tempptr = SWIG_MakeString($input); 58 temp.assign(tempptr); 59 if (tempptr) SWIG_free(tempptr); 60 $1 = &temp; 61 } 62 } 63 64 %typemap(out) string { 65 int size = $1.size(); 66 C_word *space = C_alloc (C_SIZEOF_STRING (size)); 67 $result = C_string (&space, size, (char *) $1.c_str()); 68 } 69 70 %typemap(out) const string& { 71 int size = $1->size(); 72 C_word *space = C_alloc (C_SIZEOF_STRING (size)); 73 $result = C_string (&space, size, (char *) $1->c_str()); 74 } 75 76 %typemap(varin) string { 77 if ($input == C_SCHEME_FALSE) { 78 $1.resize(0); 79 } else { 80 char *tempptr; 81 if (!C_swig_is_string ($input)) { 82 swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, 83 "Argument #$argnum is not a string"); 84 } 85 tempptr = SWIG_MakeString($input); 86 $1.assign(tempptr); 87 if (tempptr) SWIG_free(tempptr); 88 } 89 } 90 91 %typemap(varout) string { 92 int size = $1.size(); 93 C_word *space = C_alloc (C_SIZEOF_STRING (size)); 94 $result = C_string (&space, size, (char *) $1.c_str()); 95 } 96 } 97