1
- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2
- //
1
+
3
2
// Language.h: Rcpp R/C++ interface class library -- language objects (calls)
4
3
//
5
- // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
4
+ // Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
6
5
//
7
6
// This file is part of Rcpp.
8
7
//
@@ -35,8 +34,8 @@ namespace Rcpp{
35
34
{
36
35
public:
37
36
38
- typedef typename DottedPairProxyPolicy<Language_Impl>::DottedPairProxy Proxy ;
39
- typedef typename DottedPairProxyPolicy<Language_Impl>::const_DottedPairProxy const_Proxy ;
37
+ typedef typename DottedPairProxyPolicy<Language_Impl>::DottedPairProxy Proxy;
38
+ typedef typename DottedPairProxyPolicy<Language_Impl>::const_DottedPairProxy const_Proxy;
40
39
41
40
RCPP_GENERATE_CTOR_ASSIGN (Language_Impl)
42
41
@@ -49,7 +48,7 @@ namespace Rcpp{
49
48
* to a call using as.call
50
49
*/
51
50
Language_Impl (SEXP x){
52
- Storage::set__ ( r_cast<LANGSXP>(x) ) ;
51
+ Storage::set__ ( r_cast<LANGSXP>(x) );
53
52
}
54
53
55
54
/* *
@@ -62,7 +61,7 @@ namespace Rcpp{
62
61
* > call( "rnorm" )
63
62
*/
64
63
explicit Language_Impl ( const std::string& symbol ){
65
- Storage::set__ ( Rf_lang1 ( Rf_install (symbol.c_str ()) ) ) ;
64
+ Storage::set__ ( Rf_lang1 ( Rf_install (symbol.c_str ()) ) );
66
65
}
67
66
68
67
/* *
@@ -74,7 +73,7 @@ namespace Rcpp{
74
73
* > call( "rnorm" )
75
74
*/
76
75
explicit Language_Impl ( const Symbol& symbol ){
77
- Storage::set__ ( Rf_lang1 ( symbol ) ) ;
76
+ Storage::set__ ( Rf_lang1 ( symbol ) );
78
77
}
79
78
80
79
/* *
@@ -83,7 +82,7 @@ namespace Rcpp{
83
82
* @param function function to call
84
83
*/
85
84
explicit Language_Impl ( const Function& function) {
86
- Storage::set__ ( Rf_lang1 ( function ) ) ;
85
+ Storage::set__ ( Rf_lang1 ( function ) );
87
86
}
88
87
89
88
/* *
@@ -109,23 +108,23 @@ namespace Rcpp{
109
108
* sets the symbol of the call
110
109
*/
111
110
void setSymbol ( const std::string& symbol){
112
- setSymbol ( Symbol ( symbol ) ) ;
111
+ setSymbol ( Symbol ( symbol ) );
113
112
}
114
113
115
114
/* *
116
115
* sets the symbol of the call
117
116
*/
118
117
void setSymbol ( const Symbol& symbol ){
119
- SEXP x = Storage::get__ () ;
120
- SETCAR ( x, symbol ) ;
118
+ SEXP x = Storage::get__ ();
119
+ SETCAR ( x, symbol );
121
120
SET_TAG (x, R_NilValue);
122
121
}
123
122
124
123
/* *
125
124
* sets the function
126
125
*/
127
126
void setFunction ( const Function& function){
128
- SEXP x = Storage::get__ () ;
127
+ SEXP x = Storage::get__ ();
129
128
SETCAR ( x, function );
130
129
SET_TAG (x, R_NilValue); /* probably not necessary */
131
130
}
@@ -134,83 +133,91 @@ namespace Rcpp{
134
133
* eval this call in the global environment
135
134
*/
136
135
SEXP eval () const {
137
- return Rcpp_fast_eval ( Storage::get__ (), R_GlobalEnv ) ;
136
+ return Rcpp_fast_eval ( Storage::get__ (), R_GlobalEnv );
138
137
}
139
138
140
139
/* *
141
140
* eval this call in the requested environment
142
141
*/
143
142
SEXP eval (SEXP env) const {
144
- return Rcpp_fast_eval ( Storage::get__ (), env ) ;
143
+ return Rcpp_fast_eval ( Storage::get__ (), env );
145
144
}
146
145
147
146
SEXP fast_eval () const {
148
- return internal::Rcpp_eval_impl ( Storage::get__ (), R_GlobalEnv) ;
147
+ return internal::Rcpp_eval_impl ( Storage::get__ (), R_GlobalEnv);
149
148
}
150
149
SEXP fast_eval (SEXP env ) const {
151
- return internal::Rcpp_eval_impl ( Storage::get__ (), env) ;
150
+ return internal::Rcpp_eval_impl ( Storage::get__ (), env);
152
151
}
153
152
154
153
void update ( SEXP x){
155
- SET_TYPEOF ( x, LANGSXP ) ;
156
- SET_TAG ( x, R_NilValue ) ;
154
+ SET_TYPEOF ( x, LANGSXP );
155
+ SET_TAG ( x, R_NilValue );
157
156
}
158
157
159
158
};
160
159
161
- typedef Language_Impl<PreserveStorage> Language ;
160
+ typedef Language_Impl<PreserveStorage> Language;
162
161
163
162
template <typename RESULT_TYPE=SEXP>
164
163
class fixed_call {
165
164
public:
166
- typedef RESULT_TYPE result_type ;
165
+ typedef RESULT_TYPE result_type;
167
166
168
167
fixed_call ( Language call_ ) : call(call_){}
169
168
fixed_call ( Function fun ) : call(fun){}
170
169
171
170
RESULT_TYPE operator ()(){
172
- return as<RESULT_TYPE>( call.eval () ) ;
171
+ return as<RESULT_TYPE>( call.eval () );
173
172
}
174
173
175
174
private:
176
- Language call ;
177
- } ;
175
+ Language call;
176
+ };
178
177
179
178
template <typename T, typename RESULT_TYPE = SEXP>
180
- class unary_call : public std ::unary_function<T,RESULT_TYPE> {
179
+ #if __cplusplus < 201103L
180
+ class unary_call : public std ::unary_function<T,RESULT_TYPE> {
181
+ #else
182
+ class unary_call : public std ::function<RESULT_TYPE(T)> {
183
+ #endif
181
184
public:
182
185
unary_call ( Language call_ ) : call(call_), proxy(call_,1 ) {}
183
186
unary_call ( Language call_, R_xlen_t index ) : call(call_), proxy(call_,index){}
184
187
unary_call ( Function fun ) : call( fun, R_NilValue), proxy(call,1 ) {}
185
188
186
189
RESULT_TYPE operator ()( const T& object ){
187
- proxy = object ;
188
- return as<RESULT_TYPE>( call.eval () ) ;
190
+ proxy = object;
191
+ return as<RESULT_TYPE>( call.eval () );
189
192
}
190
193
191
194
private:
192
- Language call ;
193
- Language::Proxy proxy ;
194
- } ;
195
+ Language call;
196
+ Language::Proxy proxy;
197
+ };
195
198
196
199
template <typename T1, typename T2, typename RESULT_TYPE = SEXP>
200
+ #if __cplusplus < 201103L
197
201
class binary_call : public std ::binary_function<T1,T2,RESULT_TYPE> {
202
+ #else
203
+ class binary_call : public std ::function<RESULT_TYPE(T1,T2)> {
204
+ #endif
198
205
public:
199
206
binary_call ( Language call_ ) : call(call_), proxy1(call_,1 ), proxy2(call_,2 ) {}
200
207
binary_call ( Language call_, R_xlen_t index1, R_xlen_t index2 ) : call(call_), proxy1(call_,index1), proxy2(call_,index2){}
201
208
binary_call ( Function fun) : call(fun, R_NilValue, R_NilValue), proxy1(call,1 ), proxy2(call,2 ){}
202
209
203
210
RESULT_TYPE operator ()( const T1& o1, const T2& o2 ){
204
- proxy1 = o1 ;
205
- proxy2 = o2 ;
206
- return as<RESULT_TYPE>( call.eval () ) ;
211
+ proxy1 = o1;
212
+ proxy2 = o2;
213
+ return as<RESULT_TYPE>( call.eval () );
207
214
}
208
215
209
216
private:
210
- Language call ;
211
- Language::Proxy proxy1 ;
212
- Language::Proxy proxy2 ;
213
- } ;
217
+ Language call;
218
+ Language::Proxy proxy1;
219
+ Language::Proxy proxy2;
220
+ };
214
221
215
222
} // namespace Rcpp
216
223
0 commit comments