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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/* These map the primitive C types to the appropriate R type
for use in class representations.
*/
%typemap("rtype") int, int *, int & "numeric";
%apply int {size_t}
%apply int {std::size_t}
%apply int {ptrdiff_t}
%apply int {std::ptrdiff_t}
%typemap("rtype") long, long * "numeric";
%typemap("rtype") unsigned long,
unsigned long * "numeric";
%typemap("rtype") unsigned int,
unsigned int * "numeric";
%typemap("rtype") double, double*, double & "numeric";
%typemap("rtype") float, float *, float & "numeric";
%typemap("rtype") char *, char ** "character";
%typemap("rtype") char "character";
%typemap("rtype") string, string *, string & "character";
%typemap("rtype") std::string, std::string *, std::string & "character";
%typemap("rtype") bool, bool * "logical";
%typemap("rtype") enum SWIGTYPE "character";
%typemap("rtype") enum SWIGTYPE * "character";
%typemap("rtype") enum SWIGTYPE & "character";
%typemap("rtype") SWIGTYPE * "$R_class";
%typemap("rtype") SWIGTYPE & "$R_class";
%typemap("rtype") SWIGTYPE "$&R_class";
/* Have to be careful that as(x, "numeric") is different from as.numeric(x).
The latter makes a REALSXP, whereas the former leaves an INTSXP as an
INTSXP.
*/
%typemap(scoercein) int, int *, int &
%{ $input = as($input, "integer"); %}
%typemap(scoercein) ptrdiff_t, ptrdiff_t *, ptrdiff_t &
%{ $input = as($input, "integer"); %}
%typemap(scoercein) unsigned long, unsigned long *, unsigned long &
%{ $input = as($input, "integer"); %}
%typemap(scoercein) unsigned int, unsigned int *, unsigned int &
%{ $input = as($input, "integer"); %}
%typemap(scoercein) double, double *, double &
%{ $input = as($input, "numeric"); %}
%typemap(scoercein) float, float *, float &
%{ $input = as($input, "numeric"); %}
%typemap(scoercein) char, char *, char &
%{ $input = as($input, "character"); %}
%typemap(scoercein) string, string *, string &
%{ $input = as($input, "character"); %}
%typemap(scoercein) std::string, std::string *, std::string &
%{ $input = as($input, "character"); %}
%typemap(scoercein) enum SWIGTYPE
%{ $input = enumToInteger($input, "$R_class") %}
%typemap(scoercein) enum SWIGTYPE &
%{ $input = enumToInteger($input, "$R_class") %}
%typemap(scoercein) enum SWIGTYPE *
%{ $input = enumToInteger($input, "$R_class") %}
%typemap(scoercein) SWIGTYPE *
%{ $input = coerceIfNotSubclass($input, "$R_class") %}
%typemap(scoercein) SWIGTYPE &
%{ $input = coerceIfNotSubclass($input, "$R_class") %}
%typemap(scoercein) SWIGTYPE
%{ $input = coerceIfNotSubclass($input, "$&R_class") %}
%typemap(scoercein) SWIGTYPE[ANY]
%{
if(is.list($input))
assert(all(sapply($input, class) == "$R_class"))
%}
/* **************************************************************** */
%typemap(scoercein) bool, bool *, bool &
"$input = as.logical($input) ";
%typemap(scoercein) int,
int *,
int &,
int[ANY],
size_t,
std::size_t,
size_t &,
std::size_t &
"$input = as.integer($input) ";
%typemap(scoercein) unsigned int,
unsigned long,
double,
float,
long,
long long,
unsigned int[],
unsigned long[],
double[],
float[],
long[],
long long[],
unsigned int[ANY],
unsigned long[ANY],
double[ANY],
float[ANY],
long[ANY],
long long[ANY],
unsigned int *,
unsigned long *,
double*,
float*,
long*,
long long *
%{ $input = as.numeric($input) %}
%typemap(scoercein) char *, string, std::string,
string &, std::string &
%{ $input = as($input, "character") %}
%typemap(scoerceout) enum SWIGTYPE
%{ $result = enumFromInteger($result, "$R_class") %}
%typemap(scoerceout) enum SWIGTYPE &
%{ $result = enumFromInteger($result, "$R_class") %}
%typemap(scoerceout) enum SWIGTYPE *
%{ $result = enumToInteger($result, "$R_class") %}
%typemap(scoerceout) SWIGTYPE
%{ class($result) <- "$&R_class" %}
%typemap(scoerceout) SWIGTYPE &
%{ class($result) <- "$R_class" %}
%typemap(scoerceout) SWIGTYPE *
%{ class($result) <- "$R_class" %}
/* Override the SWIGTYPE * above. */
%typemap(scoerceout) char,
char *,
char &,
unsigned int,
unsigned int &,
unsigned long,
unsigned long &,
double,
double &,
float,
float &,
long,
long &,
long long,
long long &,
int,
int &,
bool,
bool &,
string,
std::string,
string &,
std::string &,
size_t,
std::size_t,
size_t &,
std::size_t &,
void
%{ %}
#if 0
Just examining the values for a SWIGTYPE.
%typemap(scoerceout) SWIGTYPE %{
name = $1_name
type = $1_type
ltype = $1_ltype
mangle = $1_mangle
descriptor = $1_descriptor
pointer type = $*1_type
pointer ltype = $*1_ltype
pointer descriptor = $*1_descriptor
basetype = $*_basetype
%}
#endif
|