|
|
The virtual function overflow() is called to send some characters to the consumer, and establish the put area. Usually (but not always) when it is called, the put area has no space remaining.
int fctbuf::overflow(int c) { // check that output is allowed if ( !(mode&ios::out) ) return EOF ;Some explanations of this code:// Make sure there is a holding area if ( allocate()==EOF ) return EOF ;
// Verify that there are no characters in // get area. if ( gptr() && gptr() < egptr() ) return EOF ;
// Reset get area setg(0,0,0) ;
// Make sure there is a put area if ( !pptr() ) setp(base(),base()) ;
// Determine how many characters have been // inserted but not consumed. int w = pptr()-pbase() ;
// If c is not EOF it is a character that must // also be consumed. if ( c != EOF ) { // We always leave space *pptr() = c ; ++w ; }
// consume characters. int ok = (*fct)(pbase(), w, ios::out) ;
if ( ok ) { // Set up put area. Be sure that there // is space at end for one extra character. setp(base(),ebuf()-1) ; return zapeof(c) ; } else { // Indicate error. setp(0,0) ; return EOF ; } }