Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom flush implementation

Tags:

c++

iostream

I'm trying to follow the logic of this question to create a custom streambuf in Rcpp. Someone contributed the basic behaviour that allows us to write things like

Rcout << "some text" ;

where we implemented xsputn and overflow to redirect to Rprintf function.

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;
}

I would like to implement flushing too, i.e. support this syntax:

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

Which method do I need to implement so that the flush manipulator works on my custom stream ?

like image 351
Romain Francois Avatar asked Nov 11 '12 09:11

Romain Francois


1 Answers

It is sync() function (like in filebuf):

protected:
virtual int sync()

Base version of base_streambuf<>::sync() does nothing, one must overwrite it to make some synchronization with underlying stream.

like image 160
PiotrNycz Avatar answered Sep 30 '22 14:09

PiotrNycz