#define XERR "memorybuf"
#include "memorybuf.ih"

    // called when using e.g., file << memorystreamobj.rdbuf()

// overrides
int MemoryBuf::underflow()
{
    checkWrittenUntil();                // maybe update if pbase() != 0
        
    if (
        not (d_mode & ios::in)              // reading not OK or 
        or                                  // beyond the last written offset?
        getOffset() >= d_bridge.writtenUntil()
    )  
        return EOF;                         // then quit

    d_bridge.load();                        // load offset's segment
    setg(d_bridge.beginPtr(), d_bridge.offsetPtr(), d_bridge.endReadPtr());

    setp(0, 0);

    d_last = READ;
    return static_cast<unsigned char>(*gptr());
}
