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