#include <buf_rdwr.hpp>
Public Member Functions | |
buf_reader (mem_pool &m, readable &rdbl, int bufsz=4 *1024) | |
~buf_reader () | |
int | read (void *b, int n) |
int | read (sh_text &buf, int n) |
int | read () |
bool | read_line (sh_text &line, bool noendl=true) |
void | reset () |
const char * | begin () const |
const char * | end () const |
Definition at line 46 of file buf_rdwr.hpp.
Definition at line 37 of file buf_rdwr.cpp.
00037 : 00038 mp(m), rd(rdbl), bsz(bufsz) 00039 { 00040 assert(bsz>0); 00041 00042 buf=static_cast<unsigned char*>(mp.allocate(bsz)); 00043 reset(); 00044 }
ders::buf_reader::~buf_reader | ( | ) | [inline] |
int ders::buf_reader::read | ( | void * | b, | |
int | n | |||
) |
Definition at line 46 of file buf_rdwr.cpp.
00047 { 00048 assert(n>=0); 00049 00050 if (n==0) return 0; 00051 00052 if (it==lim) { 00053 int rc=rd.read(buf, bsz); 00054 switch (rc) { 00055 case -1: return -1; 00056 case 0: return 0; 00057 } 00058 00059 it=0; 00060 lim=rc; 00061 } 00062 00063 if (n<=lim-it) { 00064 memcpy(b, buf, n); 00065 it+=n; 00066 00067 return n; 00068 } 00069 00070 // n>lim-it 00071 int rdn=lim-it; 00072 memcpy(b, buf, rdn); 00073 reset(); 00074 00075 b=static_cast<unsigned char*>(b)+rdn; 00076 n-=rdn; 00077 00078 int rc=rd.read(b, n); 00079 return (rc!=-1) ? rdn+rc : rdn; 00080 }
int ders::buf_reader::read | ( | sh_text & | buf, | |
int | n | |||
) |
Definition at line 82 of file buf_rdwr.cpp.
00083 { 00084 assert(n>=0); 00085 00086 buf->clear(); 00087 buf->reserve(n); 00088 00089 int rc=read(buf->begin(), n); 00090 assert(rc<=n); 00091 if (rc!=-1) buf->uninitialized_resize(rc); 00092 00093 return rc; 00094 }
int ders::buf_reader::read | ( | ) | [inline] |
bool ders::buf_reader::read_line | ( | sh_text & | line, | |
bool | noendl = true | |||
) |
Definition at line 96 of file buf_rdwr.cpp.
00097 { 00098 line->clear(); 00099 00100 for (int ch; ; ) { 00101 if ((ch=read())==-1) return line->size()!=0; 00102 00103 if (ch!='\n') line->append(ch); 00104 else { 00105 if (!noendl) line->append(ch); 00106 else { 00107 if (line->size()>0 && line->back()=='\r') 00108 line->uninitialized_resize(line->size()-1); 00109 } 00110 00111 break; 00112 } 00113 } 00114 00115 return true; 00116 }
void ders::buf_reader::reset | ( | ) | [inline] |
const char* ders::buf_reader::begin | ( | ) | const [inline] |
const char* ders::buf_reader::end | ( | ) | const [inline] |