PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/pike/std_string.i

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