7 #ifndef _ASYNC_FILEBUF_
8 #define _ASYNC_FILEBUF_
16 #include <condition_variable>
21 #define THIS_ASYNCFB "(" << (void*)this << ")"
26 async_filebuf(
int segsize=1000000,
int segcount=3,
int lookback=1);
30 #if VERBOSE_ASYNC_FILEBUF
31 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::open(" << fname <<
"," << mode <<
")" << std::endl;
35 shadow_ifs.open(fname, mode);
41 #if VERBOSE_ASYNC_FILEBUF
42 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::close()" << std::endl;
54 #if VERBOSE_ASYNC_FILEBUF
55 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::in_avail()" << std::endl;
59 return std::filebuf::in_avail();
63 #if VERBOSE_ASYNC_FILEBUF
64 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::snextc()" << std::endl;
73 return std::filebuf::snextc();
84 return std::filebuf::sbumpc();
94 return std::filebuf::sgetc();
106 return std::filebuf::sputbackc(c);
118 return std::filebuf::sungetc();
125 return std::filebuf::pbackfail(
c);
128 virtual std::streambuf*
setbuf(
char* s, std::streamsize n) {
129 #if VERBOSE_ASYNC_FILEBUF
130 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::setbuf(s," << n <<
")" << std::endl;
148 return std::filebuf::showmanyc();
152 #if VERBOSE_ASYNC_FILEBUF
153 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::uflow()" << std::endl;
160 return std::filebuf::uflow();
165 virtual std::streamsize
xsgetn(
char* s, std::streamsize n);
167 virtual std::streampos
seekoff(std::streamoff off, std::ios::seekdir way,
168 std::ios::openmode which);
170 virtual std::streampos
seekpos(std::streampos pos, std::ios::openmode which);
195 std::ifstream shadow_ifs;
208 return this->std::filebuf::seekoff(0, std::ios::cur, std::ios::in);
213 return this->std::filebuf::seekoff(0, std::ios::cur, std::ios::in);
216 #if VERBOSE_ASYNC_FILEBUF
217 std::cout <<
THIS_ASYNCFB <<
"async_filebuf::getpos() returns " << pos <<
" in segment " <<
segment() << std::endl;
async_filebuf * open(const std::string fname, std::ios::openmode mode)
std::vector< segment_state > segment_cond
textOut open("gains.txt")
virtual std::streampos seekpos(std::streampos pos, std::ios::openmode which)
std::condition_variable readloop_wake
std::condition_variable readloop_woke
std::thread * readloop_thread
async_filebuf(int segsize=1000000, int segcount=3, int lookback=1)
std::vector< std::streampos > segment_pos
std::streamsize in_avail()
virtual std::streamsize xsgetn(char *s, std::streamsize n)
int pbackfail(char c=EOF)
std::vector< std::streamsize > segment_len
virtual std::streambuf * setbuf(char *s, std::streamsize n)
virtual std::streamsize showmanyc()
virtual std::streampos seekoff(std::streamoff off, std::ios::seekdir way, std::ios::openmode which)