我试图遵循的逻辑这个问题,创建一个自定义streambuf在Rcpp.有人贡献了基本行为,允许我们写出类似的东西
Rcout << "some text" ;
Run Code Online (Sandbox Code Playgroud)
我们在哪里实现xsputn并overflow重定向到Rprintf功能.
std::streamsize Rcpp::Rstreambuf::xsputn(const char *s, std::streamsize num ) {
Rprintf( "%.*s", num, s );
return num;
}
int Rcpp::Rstreambuf::overflow(int c ) {
if (c != EOF) {
Rprintf( "%.1s", &c );
}
return c;
}
Run Code Online (Sandbox Code Playgroud)
我也想实现刷新,即支持这种语法:
Rcout << "some text" << std::flush ;
Run Code Online (Sandbox Code Playgroud)
我需要实现哪种方法,以便flush操纵器在我的自定义流上工作?
它是sync()函数(就像在filebuf中一样):
protected:
virtual int sync()
Run Code Online (Sandbox Code Playgroud)
base_streambuf <> :: sync()的基本版本什么都不做,必须覆盖它以与底层流进行一些同步.