Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // |
2 | // SWIG typemaps for std::string | |
3 | // Luigi Ballabio | |
4 | // Apr 8, 2002 | |
5 | // | |
6 | // Guile implementation | |
7 | ||
8 | // ------------------------------------------------------------------------ | |
9 | // std::string is typemapped by value | |
10 | // This can prevent exporting methods which return a string | |
11 | // in order for the user to modify it. | |
12 | // However, I think I'll wait until someone asks for it... | |
13 | // ------------------------------------------------------------------------ | |
14 | ||
15 | %include exception.i | |
16 | ||
17 | %{ | |
18 | #include <string> | |
19 | %} | |
20 | ||
21 | namespace std { | |
22 | ||
23 | class string; | |
24 | ||
25 | %typemap(typecheck) string = char *; | |
26 | %typemap(typecheck) const string & = char *; | |
27 | ||
28 | %typemap(in) string (char* tempptr) { | |
29 | if (gh_string_p($input)) { | |
30 | tempptr = SWIG_scm2str($input); | |
31 | $1 = std::string(tempptr); | |
32 | if (tempptr) SWIG_free(tempptr); | |
33 | } else { | |
34 | SWIG_exception(SWIG_TypeError, "string expected"); | |
35 | } | |
36 | } | |
37 | ||
38 | %typemap(in) const string & (std::string temp, | |
39 | char* tempptr) { | |
40 | if (gh_string_p($input)) { | |
41 | tempptr = SWIG_scm2str($input); | |
42 | temp = std::string(tempptr); | |
43 | if (tempptr) SWIG_free(tempptr); | |
44 | $1 = &temp; | |
45 | } else { | |
46 | SWIG_exception(SWIG_TypeError, "string expected"); | |
47 | } | |
48 | } | |
49 | ||
50 | %typemap(out) string { | |
51 | $result = gh_str02scm($1.c_str()); | |
52 | } | |
53 | ||
54 | %typemap(out) const string & { | |
55 | $result = gh_str02scm($1->c_str()); | |
56 | } | |
57 | ||
58 | } |