File tree Expand file tree Collapse file tree 6 files changed +37
-2
lines changed Expand file tree Collapse file tree 6 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,8 @@ cppFunction <- function(code,
291
291
scaffolding <- c(scaffolding ,
292
292
" " ,
293
293
" using namespace Rcpp;" ,
294
+ " Rostream<true>& Rcpp::Rcout = Rcpp_cout_get();" ,
295
+ " Rostream<false>& Rcpp::Rcerr = Rcpp_cerr_get();" ,
294
296
" " ,
295
297
includes ,
296
298
" // [[Rcpp::export]]" ,
Original file line number Diff line number Diff line change @@ -80,8 +80,8 @@ namespace Rcpp {
80
80
::R_FlushConsole ();
81
81
return 0 ;
82
82
} // #nocov end
83
- static Rostream<true > Rcout;
84
- static Rostream<false > Rcerr;
83
+ extern Rostream<true >& Rcout;
84
+ extern Rostream<false >& Rcerr;
85
85
86
86
87
87
}
Original file line number Diff line number Diff line change 23
23
#ifndef RCPP_ROUTINE_H
24
24
#define RCPP_ROUTINE_H
25
25
26
+ #include < Rcpp/iostream/Rstreambuf.h>
27
+
26
28
#if defined(COMPILING_RCPP)
27
29
28
30
// the idea is that this file should be generated automatically by Rcpp::register
@@ -45,6 +47,9 @@ namespace Rcpp{
45
47
void Rcpp_precious_teardown ();
46
48
SEXP Rcpp_precious_preserve (SEXP object);
47
49
void Rcpp_precious_remove (SEXP token);
50
+
51
+ Rostream<true >& Rcpp_cout_get ();
52
+ Rostream<false >& Rcpp_cerr_get ();
48
53
}
49
54
50
55
SEXP rcpp_get_stack_trace ();
@@ -155,6 +160,17 @@ namespace Rcpp {
155
160
fun (token);
156
161
}
157
162
163
+ inline attribute_hidden Rostream<true >& Rcpp_cout_get () {
164
+ typedef Rostream<true >& (*Fun)();
165
+ static Fun fun = GET_CALLABLE (" Rcpp_cout_get" );
166
+ return fun ();
167
+ }
168
+ inline attribute_hidden Rostream<false >& Rcpp_cerr_get () {
169
+ typedef Rostream<false >& (*Fun)();
170
+ static Fun fun = GET_CALLABLE (" Rcpp_cerr_get" );
171
+ return fun ();
172
+ }
173
+
158
174
}
159
175
160
176
// The 'attribute_hidden' used here is a simple precessor defined from
Original file line number Diff line number Diff line change @@ -33,6 +33,18 @@ using namespace Rcpp;
33
33
#endif
34
34
35
35
namespace Rcpp {
36
+ // [[Rcpp::register]]
37
+ Rostream<true >& Rcpp_cout_get () {
38
+ static Rostream<true > Rcpp_cout;
39
+ return Rcpp_cout;
40
+ }
41
+ // [[Rcpp::register]]
42
+ Rostream<false >& Rcpp_cerr_get () {
43
+ static Rostream<false > Rcpp_cerr;
44
+ return Rcpp_cerr;
45
+ }
46
+ Rostream<true >& Rcout = Rcpp_cout_get();
47
+ Rostream<false >& Rcerr = Rcpp_cerr_get();
36
48
37
49
namespace internal {
38
50
Original file line number Diff line number Diff line change @@ -2127,6 +2127,9 @@ namespace attributes {
2127
2127
2128
2128
// always bring in Rcpp
2129
2129
ostr << " using namespace Rcpp;" << std::endl << std::endl;
2130
+ ostr << " Rostream<true> &Rcpp::Rcout = Rcpp_cout_get();" << std::endl;
2131
+ ostr << " Rostream<false> &Rcpp::Rcerr = Rcpp_cerr_get();" << std::endl;
2132
+ ostr << std::endl;
2130
2133
2131
2134
// commit with preamble
2132
2135
return ExportsGenerator::commit (ostr.str ());
Original file line number Diff line number Diff line change @@ -124,6 +124,8 @@ void registerFunctions(){
124
124
RCPP_REGISTER (Rcpp_precious_teardown)
125
125
RCPP_REGISTER (Rcpp_precious_preserve)
126
126
RCPP_REGISTER (Rcpp_precious_remove)
127
+ RCPP_REGISTER (Rcpp_cout_get)
128
+ RCPP_REGISTER (Rcpp_cerr_get)
127
129
#undef RCPP_REGISTER
128
130
}
129
131
You can’t perform that action at this time.
0 commit comments