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// std::string is typemapped by value
12// This can prevent exporting methods which return a string
13// in order for the user to modify it.
14// However, I think I'll wait until someone asks for it...
15// ------------------------------------------------------------------------
16
17%include <exception.i>
18
19%{
20#include <string>
21%}
22
23namespace std {
24
25    %naturalvar string;
26
27    class string;
28
29    %typemap(typecheck) string = char *;
30    %typemap(typecheck) const string & = char *;
31
32    %typemap(in) string (char* tempptr) {
33        if (gh_string_p($input)) {
34            tempptr = SWIG_scm2str($input);
35            $1.assign(tempptr);
36            if (tempptr) SWIG_free(tempptr);
37        } else {
38            SWIG_exception(SWIG_TypeError, "string expected");
39        }
40    }
41
42    %typemap(in) const string & (std::string temp,
43                                 char* tempptr) {
44        if (gh_string_p($input)) {
45            tempptr = SWIG_scm2str($input);
46            temp.assign(tempptr);
47            if (tempptr) SWIG_free(tempptr);
48            $1 = &temp;
49        } else {
50            SWIG_exception(SWIG_TypeError, "string expected");
51        }
52    }
53
54    %typemap(in) string * (char* tempptr) {
55        if (gh_string_p($input)) {
56            tempptr = SWIG_scm2str($input);
57            $1 = new std::string(tempptr);
58            if (tempptr) SWIG_free(tempptr);
59        } else {
60            SWIG_exception(SWIG_TypeError, "string expected");
61        }
62    }
63
64    %typemap(out) string {
65        $result = gh_str02scm($1.c_str());
66    }
67
68    %typemap(out) const string & {
69        $result = gh_str02scm($1->c_str());
70    }
71
72    %typemap(out) string * {
73        $result = gh_str02scm($1->c_str());
74    }
75
76    %typemap(varin) string {
77        if (gh_string_p($input)) {
78	    char *tempptr = SWIG_scm2str($input);
79            $1.assign(tempptr);
80            if (tempptr) SWIG_free(tempptr);
81        } else {
82            SWIG_exception(SWIG_TypeError, "string expected");
83        }
84    }
85
86    %typemap(varout) string {
87        $result = gh_str02scm($1.c_str());
88    }
89
90}
91