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
16    %naturalvar string;
17
18    class string;
19
20    /* Overloading check */
21
22    %typemap(typecheck) string = char *;
23    %typemap(typecheck) const string & = char *;
24
25    %typemap(in, pikedesc="tStr") string {
26      if ($input.type != T_STRING)
27        Pike_error("Bad argument: Expected a string.\n");
28      $1.assign(STR0($input.u.string));
29    }
30
31    %typemap(in, pikedesc="tStr") const string & (std::string temp) {
32      if ($input.type != T_STRING)
33        Pike_error("Bad argument: Expected a string.\n");
34      temp.assign(STR0($input.u.string));
35      $1 = &temp;
36    }
37
38    %typemap(out, pikedesc="tStr") string "push_text($1.c_str());";
39
40    %typemap(out, pikedesc="tStr") const string & "push_text($1->c_str());";
41
42    %typemap(directorin) string, const string &, string & "$1_name.c_str()";
43
44    %typemap(directorin) string *, const string * "$1_name->c_str()";
45
46    %typemap(directorout) string {
47      if ($input.type == T_STRING)
48        $result.assign(STR0($input.u.string));
49      else
50        throw Swig::DirectorTypeMismatchException("string expected");
51    }
52
53    %typemap(directorout) const string & (std::string temp) {
54      if ($input.type == T_STRING) {
55        temp.assign(STR0($input.u.string));
56        $result = &temp;
57      } else {
58        throw Swig::DirectorTypeMismatchException("string expected");
59      }
60    }
61
62}
63
64