PageRenderTime 34ms CodeModel.GetById 30ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/guile/std_string.i

#
Swig | 86 lines | 65 code | 16 blank | 5 comment | 0 complexity | fb216f4e37e96578ba2765ec943a56ba MD5 | raw file
 1/* -----------------------------------------------------------------------------
 2 * std_string.i
 3 *
 4 * SWIG typemaps for std::string
 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
20namespace std {
21
22    %naturalvar string;
23
24    class string;
25
26    %typemap(typecheck) string = char *;
27    %typemap(typecheck) const string & = char *;
28
29    %typemap(in) string (char * tempptr) {
30        if (gh_string_p($input)) {
31            tempptr = SWIG_scm2str($input);
32            $1.assign(tempptr);
33            if (tempptr) SWIG_free(tempptr);
34        } else {
35            SWIG_exception(SWIG_TypeError, "string expected");
36        }
37    }
38
39    %typemap(in) const string & (std::string temp, char *tempptr) {
40        if (gh_string_p($input)) {
41            tempptr = SWIG_scm2str($input);
42            temp.assign(tempptr);
43            if (tempptr) SWIG_free(tempptr);
44            $1 = &temp;
45        } else {
46            SWIG_exception(SWIG_TypeError, "string expected");
47        }
48    }
49
50    %typemap(in) string * (char *tempptr) {
51        if (gh_string_p($input)) {
52            tempptr = SWIG_scm2str($input);
53            $1 = new std::string(tempptr);
54            if (tempptr) SWIG_free(tempptr);
55        } else {
56            SWIG_exception(SWIG_TypeError, "string expected");
57        }
58    }
59
60    %typemap(out) string {
61        $result = gh_str02scm($1.c_str());
62    }
63
64    %typemap(out) const string & {
65        $result = gh_str02scm($1->c_str());
66    }
67
68    %typemap(out) string * {
69        $result = gh_str02scm($1->c_str());
70    }
71
72    %typemap(varin) string {
73        if (gh_string_p($input)) {
74	    char *tempptr = SWIG_scm2str($input);
75            $1.assign(tempptr);
76            if (tempptr) SWIG_free(tempptr);
77        } else {
78            SWIG_exception(SWIG_TypeError, "string expected");
79        }
80    }
81
82    %typemap(varout) string {
83        $result = gh_str02scm($1.c_str());
84    }
85
86}