Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // SWIG typemaps for std::string |
2 | // copied from the guile std_string.i and modified | |
3 | ||
4 | %{ | |
5 | #include <string> | |
6 | %} | |
7 | ||
8 | namespace std { | |
9 | ||
10 | %insert(closprefix) %{ (declare (hide <std-string>)) %} | |
11 | %nodefault string; | |
12 | %rename("std-string") string; | |
13 | class string { | |
14 | public: | |
15 | ~string() {} | |
16 | }; | |
17 | %extend string { | |
18 | char *str; | |
19 | } | |
20 | %{ | |
21 | #define std_string_str_get(s) ((char *)((s)->c_str())) | |
22 | #define std_string_str_set(s,v) (s->assign((char *)(v))) | |
23 | %} | |
24 | ||
25 | %typemap(typecheck) string = char *; | |
26 | %typemap(typecheck) const string & = char *; | |
27 | ||
28 | %typemap(in) string (char* tempptr) { | |
29 | if ($input == C_SCHEME_FALSE) { | |
30 | $1 = std::string(); | |
31 | } else { | |
32 | if (!C_swig_is_string ($input)) { | |
33 | swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, | |
34 | "Argument #$argnum is not a string"); | |
35 | } | |
36 | tempptr = SWIG_MakeString($input); | |
37 | $1 = std::string(tempptr); | |
38 | if (tempptr) SWIG_free(tempptr); | |
39 | } | |
40 | } | |
41 | ||
42 | %typemap(in) const string& (std::string temp, | |
43 | char* tempptr) { | |
44 | ||
45 | if ($input == C_SCHEME_FALSE) { | |
46 | temp = std::string(); | |
47 | $1 = &temp; | |
48 | } else { | |
49 | if (!C_swig_is_string ($input)) { | |
50 | swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, | |
51 | "Argument #$argnum is not a string"); | |
52 | } | |
53 | tempptr = SWIG_MakeString($input); | |
54 | temp = std::string(tempptr); | |
55 | if (tempptr) SWIG_free(tempptr); | |
56 | $1 = &temp; | |
57 | } | |
58 | } | |
59 | ||
60 | %typemap(out) string { | |
61 | int size = $1.size(); | |
62 | C_word *space = C_alloc (C_SIZEOF_STRING (size)); | |
63 | $result = C_string (&space, size, (char *) $1.c_str()); | |
64 | } | |
65 | ||
66 | %typemap(out) const string& { | |
67 | int size = $1->size(); | |
68 | C_word *space = C_alloc (C_SIZEOF_STRING (size)); | |
69 | $result = C_string (&space, size, (char *) $1->c_str()); | |
70 | } | |
71 | ||
72 | %typemap(varin) string { | |
73 | if ($input == C_SCHEME_FALSE) { | |
74 | $1 = std::string(); | |
75 | } else { | |
76 | char *tempptr; | |
77 | if (!C_swig_is_string ($input)) { | |
78 | swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, | |
79 | "Argument #$argnum is not a string"); | |
80 | } | |
81 | tempptr = SWIG_MakeString($input); | |
82 | $1 = std::string(tempptr); | |
83 | if (tempptr) SWIG_free(tempptr); | |
84 | } | |
85 | } | |
86 | ||
87 | %typemap(varout) string { | |
88 | int size = $1.size(); | |
89 | C_word *space = C_alloc (C_SIZEOF_STRING (size)); | |
90 | $result = C_string (&space, size, (char *) $1.c_str()); | |
91 | } | |
92 | } |