2012-11-11 90 views
5

我试图按照this question的逻辑在Rcpp中创建自定义streambuf。有人贡献了基本的行为,让我们写的东西像自定义冲洗实施

Rcout << "some text" ; 

我们实现xsputnoverflow重定向到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; 
} 

我想实现冲洗过,即支持这个语法:

Rcout << "some text" << std::flush ; 

哪一种方法做我需要实现,使得flush机械手工作在我的自定义流?

回答

6

这是sync()功能(如在filebuf):

protected: 
virtual int sync() 

base_streambuf<>::sync()基础版本什么都不做,就必须将其覆盖,以与底层的流一些同步。

+3

谢谢。在'Rcpp'的svn修订版本3935中实现 –