import source from 1.3.40
[external/swig.git] / Lib / mzscheme / std_string.i
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 types
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
23 namespace std {
24
25     %naturalvar string;
26
27     class string;
28
29     /* Overloading check */
30
31     %typemap(typecheck) string = char *;
32     %typemap(typecheck) const string & = char *;
33
34     %typemap(in) string {
35         if (SCHEME_STRINGP($input))
36             $1.assign(SCHEME_STR_VAL($input));
37         else
38             SWIG_exception(SWIG_TypeError, "string expected");
39     }
40
41     %typemap(in) const string & (std::string temp) {
42         if (SCHEME_STRINGP($input)) {
43             temp.assign(SCHEME_STR_VAL($input));
44             $1 = &temp;
45         } else {
46             SWIG_exception(SWIG_TypeError, "string expected");
47         }
48     }
49
50     %typemap(out) string {
51         $result = scheme_make_string($1.c_str());
52     }
53
54     %typemap(out) const string & {
55         $result = scheme_make_string($1->c_str());
56     }
57
58 }
59
60