Home | History | Annotate | Download | only in pike
      1 /* -----------------------------------------------------------------------------
      2  * std_string.i
      3  *
      4  * SWIG typemaps for std::string
      5  * ----------------------------------------------------------------------------- */
      6 
      7 %{
      8 #include <string>
      9 %}
     10 
     11 namespace 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 & ($*1_ltype 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 & ($*1_ltype 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 
     61