Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // |
2 | // SWIG typemaps for std::string | |
3 | // Lyle Johnson | |
4 | // May 1, 2003 | |
5 | // | |
6 | // Pike implementation | |
7 | ||
8 | %{ | |
9 | #include <string> | |
10 | %} | |
11 | ||
12 | namespace std { | |
13 | ||
14 | class string; | |
15 | ||
16 | /* Overloading check */ | |
17 | ||
18 | %typemap(typecheck) string = char *; | |
19 | %typemap(typecheck) const string & = char *; | |
20 | ||
21 | %typemap(in, pikedesc="tStr") string { | |
22 | if ($input.type != T_STRING) | |
23 | Pike_error("Bad argument: Expected a string.\n"); | |
24 | $1 = std::string(STR0($input.u.string)); | |
25 | } | |
26 | ||
27 | %typemap(in, pikedesc="tStr") const string & (std::string temp) { | |
28 | if ($input.type != T_STRING) | |
29 | Pike_error("Bad argument: Expected a string.\n"); | |
30 | temp = std::string(STR0($input.u.string)); | |
31 | $1 = &temp; | |
32 | } | |
33 | ||
34 | %typemap(out, pikedesc="tStr") string "push_text($1.c_str());"; | |
35 | ||
36 | %typemap(out, pikedesc="tStr") const string & "push_text($1->c_str());"; | |
37 | ||
38 | %typemap(directorin) string, const string &, string & "$1_name.c_str()"; | |
39 | ||
40 | %typemap(directorin) string *, const string * "$1_name->c_str()"; | |
41 | ||
42 | %typemap(directorout) string { | |
43 | if ($input.type == T_STRING) | |
44 | $result = std::string(STR0($input.u.string)); | |
45 | else | |
46 | throw Swig::DirectorTypeMismatchException("string expected"); | |
47 | } | |
48 | ||
49 | %typemap(directorout) const string & (std::string temp) { | |
50 | if ($input.type == T_STRING) { | |
51 | temp = std::string(STR0($input.u.string)); | |
52 | $result = &temp; | |
53 | } else { | |
54 | throw Swig::DirectorTypeMismatchException("string expected"); | |
55 | } | |
56 | } | |
57 | ||
58 | } | |
59 |