1
2/* These map the primitive C types to the appropriate R type
3   for use in class representations. 
4 */
5
6%typemap("rtype") int, int *, int &      "integer";
7%apply int {size_t}
8%apply int {std::size_t}
9%apply int {ptrdiff_t}
10%apply int {std::ptrdiff_t}
11%apply int {signed int}
12%apply int {unsigned int}
13%apply int {short}
14%apply int {unsigned short}
15
16%typemap("rtype") long, long *, long &      "integer";
17%apply long {long long}
18%apply long {signed long long}
19%apply long {unsigned long long}
20%apply long {signed long}
21%apply long {unsigned long}
22
23%typemap("rtype") double, double*, double & "numeric";
24%typemap("rtype") float, float *, float &  "numeric";
25%typemap("rtype") char *, char ** "character";
26%typemap("rtype") char            "character";
27%typemap("rtype") string, string *, string & "character";
28%typemap("rtype") std::string, std::string *, std::string & "character";
29%typemap("rtype") bool, bool *    "logical";
30%typemap("rtype") enum SWIGTYPE   "character";
31%typemap("rtype") enum SWIGTYPE *   "character";
32%typemap("rtype") enum SWIGTYPE &  "character";
33%typemap("rtype") SWIGTYPE * "$R_class";
34%typemap("rtype") SWIGTYPE & "$R_class";
35%typemap("rtype") SWIGTYPE "$&R_class";
36
37
38
39/* Have to be careful that as(x, "numeric") is different from as.numeric(x).  
40   The latter makes a REALSXP, whereas the former leaves an INTSXP as an
41   INTSXP.
42*/
43
44/* Force coercion of integer, since by default R sets all constants to
45   numeric, which means that you can't directly call a function with an 
46   integer using an R numercal literal */
47
48%typemap(scoercein) int, int *, int &
49  %{  $input = as.integer($input);     %}
50%typemap(scoercein) long, long *, long &
51  %{  $input = as.integer($input);     %}
52%typemap(scoercein) double, double *, double &
53  %{ %}
54%typemap(scoercein) float, float *, float &
55  %{ %}
56%typemap(scoercein) char, char *, char &
57  %{  $input = as($input, "character");     %}
58%typemap(scoercein) string, string *, string &
59  %{  $input = as($input, "character");     %}
60%typemap(scoercein) std::string, std::string *, std::string &
61  %{  $input = as($input, "character");     %}
62%typemap(scoercein) enum SWIGTYPE 
63  %{  $input = enumToInteger($input, "$R_class") %}
64%typemap(scoercein) enum SWIGTYPE &
65  %{  $input = enumToInteger($input, "$R_class") %}
66%typemap(scoercein) enum SWIGTYPE *
67  %{  $input = enumToInteger($input, "$R_class") %}
68
69
70%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE &  
71  %{ %}
72
73/*
74%typemap(scoercein) SWIGTYPE * 
75  %{ $input = coerceIfNotSubclass($input, "$R_class") %}
76
77%typemap(scoercein) SWIGTYPE & 
78  %{ $input = coerceIfNotSubclass($input, "$R_class") %}
79
80%typemap(scoercein) SWIGTYPE  
81  %{ $input = coerceIfNotSubclass($input, "$&R_class") %}
82*/
83
84%typemap(scoercein) SWIGTYPE[ANY]  
85 %{
86    if(is.list($input))
87      assert(all(sapply($input, class) == "$R_class"))     
88 %}
89
90
91/* **************************************************************** */
92
93%typemap(scoercein) bool, bool *, bool & 
94		    "$input = as.logical($input) ";
95%typemap(scoercein) int, 
96                    int *, 
97		    int &,
98                    int[ANY],
99		    long,
100		    long *,
101		    long &,
102		    long[ANY]
103  "$input = as.integer($input) ";
104
105%typemap(scoercein) char *, string, std::string,
106string &, std::string &
107%{  $input = as($input, "character") %}
108
109%typemap(scoerceout) enum SWIGTYPE 
110  %{  $result = enumFromInteger($result, "$R_class") %}
111
112%typemap(scoerceout) enum SWIGTYPE &
113  %{  $result = enumFromInteger($result, "$R_class") %}
114
115%typemap(scoerceout) enum SWIGTYPE *
116  %{  $result = enumToInteger($result, "$R_class") %}
117
118
119%typemap(scoerceout) SWIGTYPE 
120  %{ class($result) <- "$&R_class" %}
121
122%typemap(scoerceout) SWIGTYPE & 
123  %{ class($result) <- "$R_class" %}
124
125%typemap(scoerceout) SWIGTYPE * 
126  %{ class($result) <- "$R_class" %}
127
128/* Override the SWIGTYPE * above. */
129%typemap(scoerceout) char,
130		     char *,
131		     char &,
132		     double, 
133		     double &,
134                     float,
135		     float &,
136                     int,
137		     int &,
138		     long,
139		     long &,
140                     bool,
141		     bool &,
142		     string,
143		     std::string,
144		     string &,
145		     std::string &, 
146		     void,
147		     signed int,
148		     signed int &,		     
149		     unsigned int,
150		     unsigned int &,		     
151		     short,
152		     short &,		     
153		     unsigned short,
154		     unsigned short &,		     
155		     long long,
156		     signed long long,
157		     signed long long &,		     
158		     unsigned long long,
159		     unsigned long long &,		     
160		     signed long,
161		     signed long &,		     
162		     unsigned long,
163		     unsigned long &		     
164 %{    %}
165
166
167#if 0
168 Just examining the values for a SWIGTYPE.
169
170%typemap(scoerceout) SWIGTYPE  %{
171
172  name = $1_name
173  type = $1_type
174  ltype = $1_ltype
175
176  mangle = $1_mangle
177  descriptor = $1_descriptor
178
179  pointer type = $*1_type
180  pointer ltype = $*1_ltype
181
182  pointer descriptor = $*1_descriptor
183  basetype = $*_basetype
184
185%}
186#endif
187
188
189