#include <buf_rdwr.hpp>
Public Member Functions | |
buf_writer (mem_pool &m, writable &wrbl, int bufsz=4 *1024) | |
~buf_writer () | |
int | write (const void *b, int n) |
int | write (const ch_rng &r) |
int | write (char ch) |
bool | flush () |
void | reset () |
const char * | begin () const |
const char * | end () const |
Definition at line 77 of file buf_rdwr.hpp.
Definition at line 138 of file buf_rdwr.cpp.
00138 : 00139 mp(m), wr(wrbl), bsz(bufsz) 00140 { 00141 assert(bsz>0); 00142 00143 buf=static_cast<unsigned char*>(mp.allocate(bsz)); 00144 reset(); 00145 }
ders::buf_writer::~buf_writer | ( | ) |
Definition at line 147 of file buf_rdwr.cpp.
00148 { 00149 flush(); 00150 mp.deallocate(buf, bsz); 00151 }
int ders::buf_writer::write | ( | const void * | b, | |
int | n | |||
) |
Definition at line 153 of file buf_rdwr.cpp.
00154 { 00155 assert(n>=0); 00156 00157 if (n==0) return 0; 00158 00159 int wrn=bsz-it; 00160 if (n<=wrn) { 00161 memcpy(buf+it, b, n); 00162 it+=n; 00163 00164 return n; 00165 } 00166 00167 // n>wrn 00168 memcpy(buf+it, b, wrn); 00169 it=bsz; 00170 00171 if (!flush()) return wrn; 00172 00173 b=static_cast<const char*>(b)+wrn; 00174 n-=wrn; 00175 00176 int rc=wr.write(b, n); 00177 return (rc!=-1) ? wrn+rc : wrn; 00178 }
int ders::buf_writer::write | ( | const ch_rng & | r | ) | [inline] |
int ders::buf_writer::write | ( | char | ch | ) | [inline] |
bool ders::buf_writer::flush | ( | ) |
Definition at line 180 of file buf_rdwr.cpp.
00181 { 00182 if (it==0) return true; 00183 00184 int rc=wr.write(buf, it); 00185 if (rc==-1) return false; 00186 00187 memmove(buf, buf+rc, it-rc); 00188 it-=rc; 00189 00190 return it==0; 00191 }
void ders::buf_writer::reset | ( | ) | [inline] |
const char* ders::buf_writer::begin | ( | ) | const [inline] |
const char* ders::buf_writer::end | ( | ) | const [inline] |