2012-11-11 86 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中實現 –