PageRenderTime 27ms CodeModel.GetById 26ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Lib/pike/std_string.i

#
Swig | 63 lines | 38 code | 16 blank | 9 comment | 0 complexity | e2752c609355537ab67d66b2acf44ff0 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 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 = std::string(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 = std::string(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 = std::string(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 = std::string(STR0($input.u.string));
56        $result = &temp;
57      } else {
58        throw Swig::DirectorTypeMismatchException("string expected");
59      }
60    }
61
62}
63