PLearn 0.1
|
#include <StringPStreamBuf.h>
Public Member Functions | |
StringPStreamBuf (string *ptrs, const string &openmode="r", bool own_string_=false, streamsize inbuf_capacity=1000, streamsize outbuf_capacity=1000, streamsize unget_capacity=100) | |
StringPStreamBuf (const string *ptrs, const string &openmode="r", bool own_string_=false, streamsize inbuf_capacity=1000, streamsize unget_capacity=100) | |
const string & | getString () const |
void | clear () |
virtual | ~StringPStreamBuf () |
Protected Member Functions | |
virtual streamsize | read_ (char *p, streamsize n) |
reads up to n characters into p You should override this call in subclasses. | |
virtual void | write_ (const char *p, streamsize n) |
writes exactly n characters from p (unbuffered, must flush) | |
Protected Attributes | |
string * | st |
string::size_type | read_index |
bool | own_string |
Private Types | |
typedef PStreamBuf | inherited |
Definition at line 53 of file StringPStreamBuf.h.
typedef PStreamBuf PLearn::StringPStreamBuf::inherited [private] |
Reimplemented from PLearn::PStreamBuf.
Reimplemented in PLearn::LogInterceptorPStreamBuf, and PLearn::PlideLogPStreamBuf.
Definition at line 58 of file StringPStreamBuf.h.
PLearn::StringPStreamBuf::StringPStreamBuf | ( | string * | ptrs, |
const string & | openmode = "r" , |
||
bool | own_string_ = false , |
||
streamsize | inbuf_capacity = 1000 , |
||
streamsize | outbuf_capacity = 1000 , |
||
streamsize | unget_capacity = 100 |
||
) |
Definition at line 50 of file StringPStreamBuf.cc.
:PStreamBuf(openmode=="r", openmode=="w" || openmode=="a", inbuf_capacity, outbuf_capacity, unget_capacity), st(ptrs), read_index(0), own_string(own_string_) { if(openmode=="w") // truncate it first st->clear(); else if(openmode!="r" && openmode!="a") PLERROR("In StringPStreamBuf invalid openmode %s, must be one of r, w, a",openmode.c_str()); }
PLearn::StringPStreamBuf::StringPStreamBuf | ( | const string * | ptrs, |
const string & | openmode = "r" , |
||
bool | own_string_ = false , |
||
streamsize | inbuf_capacity = 1000 , |
||
streamsize | unget_capacity = 100 |
||
) |
Definition at line 62 of file StringPStreamBuf.cc.
References PLERROR.
:PStreamBuf(true, false, inbuf_capacity, 0, unget_capacity), st(const_cast<string*>(ptrs)), read_index(0), own_string(own_string_) { if(openmode!="r") PLERROR("In StringPStreamBuf(const string*, ...) invalid openmode %s, must be one of r if giving a const string* ",openmode.c_str()); }
PLearn::StringPStreamBuf::~StringPStreamBuf | ( | ) | [virtual] |
Definition at line 71 of file StringPStreamBuf.cc.
References PLearn::PStreamBuf::flush(), own_string, and st.
{ flush(); if(own_string && st!=0) delete st; }
void PLearn::StringPStreamBuf::clear | ( | ) | [inline] |
Definition at line 80 of file StringPStreamBuf.h.
References PLearn::flush().
Referenced by PLearn::_tostring_static_pstream_().
const string& PLearn::StringPStreamBuf::getString | ( | ) | const [inline] |
StringPStreamBuf::streamsize PLearn::StringPStreamBuf::read_ | ( | char * | p, |
streamsize | n | ||
) | [protected, virtual] |
reads up to n characters into p You should override this call in subclasses.
Default version issues a PLERROR
On success, the number of bytes read is returned. Zero indicates end of file. If we are not at end of file, at least one character should be returned (the call must block until at least one char is available). It is not an error if the number returned is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal). If an error occurs, an exception should be thrown.
Reimplemented from PLearn::PStreamBuf.
Definition at line 79 of file StringPStreamBuf.cc.
References read_index, and st.
{ string::size_type nread = st->copy(p, string::size_type(n), read_index); read_index += nread; return streamsize(nread); }
void PLearn::StringPStreamBuf::write_ | ( | const char * | p, |
streamsize | n | ||
) | [protected, virtual] |
writes exactly n characters from p (unbuffered, must flush)
Reimplemented from PLearn::PStreamBuf.
Definition at line 87 of file StringPStreamBuf.cc.
References st.
bool PLearn::StringPStreamBuf::own_string [protected] |
Definition at line 67 of file StringPStreamBuf.h.
Referenced by ~StringPStreamBuf().
string::size_type PLearn::StringPStreamBuf::read_index [protected] |
Definition at line 66 of file StringPStreamBuf.h.
Referenced by read_().
string* PLearn::StringPStreamBuf::st [protected] |
Definition at line 65 of file StringPStreamBuf.h.
Referenced by read_(), StringPStreamBuf(), write_(), and ~StringPStreamBuf().