Home | History | Annotate | Download | only in mzscheme
      1 /* -----------------------------------------------------------------------------
      2  * std_string.i
      3  *
      4  * SWIG typemaps for std::string types
      5  * ----------------------------------------------------------------------------- */
      6 
      7 // ------------------------------------------------------------------------
      8 // std::string is typemapped by value
      9 // This can prevent exporting methods which return a string
     10 // in order for the user to modify it.
     11 // However, I think I'll wait until someone asks for it...
     12 // ------------------------------------------------------------------------
     13 
     14 %include <exception.i>
     15 
     16 %{
     17 #include <string>
     18 %}
     19 
     20 namespace std {
     21 
     22     %naturalvar string;
     23 
     24     class string;
     25 
     26     /* Overloading check */
     27 
     28     %typemap(typecheck) string = char *;
     29     %typemap(typecheck) const string & = char *;
     30 
     31     %typemap(in) string {
     32         if (SCHEME_STRINGP($input))
     33             $1.assign(SCHEME_STR_VAL($input));
     34         else
     35             SWIG_exception(SWIG_TypeError, "string expected");
     36     }
     37 
     38     %typemap(in) const string & ($*1_ltype temp) {
     39         if (SCHEME_STRINGP($input)) {
     40             temp.assign(SCHEME_STR_VAL($input));
     41             $1 = &temp;
     42         } else {
     43             SWIG_exception(SWIG_TypeError, "string expected");
     44         }
     45     }
     46 
     47     %typemap(out) string {
     48         $result = scheme_make_string($1.c_str());
     49     }
     50 
     51     %typemap(out) const string & {
     52         $result = scheme_make_string($1->c_str());
     53     }
     54 
     55 }
     56 
     57 
     58