1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// Test the goin and goout typemaps for directors.
%module(directors="1") go_director_inout
%{
#include <string>
%}
%inline
%{
struct MyStruct {
std::string str;
};
struct RetStruct {
std::string str;
};
%}
%go_import("encoding/json")
%insert(go_header)
%{
type GoRetStruct struct {
Str string
}
%}
%typemap(gotype) RetStruct "GoRetStruct"
%typemap(imtype) RetStruct "string"
%typemap(goin) RetStruct
%{
$result = $input.Str
%}
%typemap(in) RetStruct
%{
$result.str.assign($input.p, $input.n);
%}
%typemap(out,fragment="AllocateString") RetStruct
%{
$result = Swig_AllocateString($1.str.data(), $1.str.length());
%}
%typemap(goout,fragment="CopyString") RetStruct
%{
$result = GoRetStruct{Str: swigCopyString($input)}
%}
%typemap(godirectorout) RetStruct
%{
$result = $input.Str
%}
%typemap(directorout) RetStruct
%{
$result.str.assign($input.p, $input.n);
%}
%typemap(godirectorin) RetStruct
%{
%}
%typemap(gotype) MyStruct "map[string]interface{}"
%typemap(imtype) MyStruct "string"
%typemap(goin) MyStruct
%{
if b, err := json.Marshal($input); err != nil {
panic(err)
} else {
$result = string(b)
}
%}
%typemap(directorin,fragment="AllocateString") MyStruct
%{
$input = Swig_AllocateString($1.str.data(), $1.str.length());
%}
%typemap(godirectorin,fragment="CopyString") MyStruct
%{
if err := json.Unmarshal([]byte(swigCopyString($input)), &$result); err != nil {
panic(err)
}
%}
%typemap(out,fragment="AllocateString") MyStruct
%{
$result = Swig_AllocateString($1.str.data(), $1.str.length());
%}
%typemap(goout,fragment="CopyString") MyStruct
%{
$result = swigCopyString($input)
%}
%typemap(in) MyStruct
%{
$1.str.assign($input.p, $input.n);
%}
%feature("director") MyClass;
%inline
%{
class MyClass {
public:
virtual ~MyClass() {}
virtual RetStruct Adjust(MyStruct s) {
RetStruct r;
r.str = s.str;
return r;
}
};
%}
|