|
|
The underflow function is called when characters are needed for fetching and none are available in the get area. Its general outline is similar to overflow(), but it deals with the get area rather than the put area.
int fctbuf::underflow() {
// Check that input is allowed
if ( !(mode&ios::in) ) return EOF ;
// Make sure there is a holding area.
if (allocate()==EOF) return EOF ;
// If there are characters waiting for output
// send them ;
if ( pptr() && pptr() > pbase() ) overflow(EOF) ;
// Reset put area
setp(0,0) ;
// Setup get area ;
if ( blen() > 1 ) setg(base(),base()+1,ebuf()) ;
else setg(base(),base(),ebuf()) ;
// Produce characters
int ok = (*fct)(base(),blen(),ios::in) ;
if ( ok ) {
return zapeof(*base()) ;
}
else {
setg(0,0,0) ;
return EOF ;
}
}
Some explanations: