PLearn 0.1
|
#include <StdPStreamBuf.h>
Public Member Functions | |
StdPStreamBuf () | |
StdPStreamBuf (istream *pin_, bool own_pin_=false) | |
ctor. from an istream (I) | |
StdPStreamBuf (ostream *pout_, bool own_pout_=false) | |
ctor. from an ostream (O) | |
StdPStreamBuf (iostream *pios_, bool own_pios_=false) | |
ctor. from an iostream (IO) | |
StdPStreamBuf (istream *pin_, ostream *pout_, bool own_pin_=false, bool own_pout_=false) | |
ctor. from an istream and an ostream (IO) | |
virtual | ~StdPStreamBuf () |
void | setIn (istream *pin_, bool own_pin_=false) |
void | setOut (ostream *pout_, bool own_pout_=false) |
istream * | rawin () |
access to underlying istream | |
ostream * | rawout () |
virtual bool | good () const |
Checks if the streambuf is valid and can be written to or read from. | |
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 | |
istream * | pin |
underlying input stream | |
ostream * | pout |
underlying output stream | |
bool | own_pin |
bool | own_pout |
true if {pin|pout} was created internally | |
Private Types | |
typedef PStreamBuf | inherited |
Definition at line 54 of file StdPStreamBuf.h.
typedef PStreamBuf PLearn::StdPStreamBuf::inherited [private] |
Reimplemented from PLearn::PStreamBuf.
Definition at line 59 of file StdPStreamBuf.h.
PLearn::StdPStreamBuf::StdPStreamBuf | ( | ) |
Definition at line 50 of file StdPStreamBuf.cc.
:PStreamBuf(false,false), pin(0), pout(0), own_pin(false), own_pout(false) {}
PLearn::StdPStreamBuf::StdPStreamBuf | ( | istream * | pin_, |
bool | own_pin_ = false |
||
) |
ctor. from an istream (I)
Definition at line 56 of file StdPStreamBuf.cc.
:PStreamBuf(true,false), pin(pin_), pout(0), own_pin(own_pin_), own_pout(false) { }
PLearn::StdPStreamBuf::StdPStreamBuf | ( | ostream * | pout_, |
bool | own_pout_ = false |
||
) |
ctor. from an ostream (O)
Definition at line 63 of file StdPStreamBuf.cc.
:PStreamBuf(false,true), pin(0), pout(pout_), own_pin(false), own_pout(own_pout_) {}
ctor. from an iostream (IO)
Definition at line 69 of file StdPStreamBuf.cc.
:PStreamBuf(true,true), pin(pios_), pout(pios_), own_pin(own_pios_), own_pout(own_pios_) { }
PLearn::StdPStreamBuf::StdPStreamBuf | ( | istream * | pin_, |
ostream * | pout_, | ||
bool | own_pin_ = false , |
||
bool | own_pout_ = false |
||
) |
ctor. from an istream and an ostream (IO)
Definition at line 76 of file StdPStreamBuf.cc.
:PStreamBuf(true,true), pin(pin_), pout(pout_), own_pin(own_pin_), own_pout(own_pout_) { }
PLearn::StdPStreamBuf::~StdPStreamBuf | ( | ) | [virtual] |
Definition at line 82 of file StdPStreamBuf.cc.
References PLearn::PStreamBuf::flush(), own_pin, own_pout, pin, and pout.
{ flush(); if (own_pin && pin) delete pin; // delete pin if we created it if (own_pout && pout) delete pout; // delete pout if we created it }
bool PLearn::StdPStreamBuf::good | ( | ) | const [virtual] |
Checks if the streambuf is valid and can be written to or read from.
Reimplemented from PLearn::PStreamBuf.
Definition at line 135 of file StdPStreamBuf.cc.
References PLearn::PStreamBuf::eof(), PLearn::PStreamBuf::is_readable, PLearn::PStreamBuf::is_writable, and pout.
{ if (is_readable && is_writable) return !eof() && pout->good(); else if (is_readable && !is_writable) return !eof(); else if (!is_readable && is_writable) return pout->good(); else return false; }
istream* PLearn::StdPStreamBuf::rawin | ( | ) | [inline] |
access to underlying istream
Definition at line 108 of file StdPStreamBuf.h.
References PLearn::pin.
ostream* PLearn::StdPStreamBuf::rawout | ( | ) | [inline] |
StdPStreamBuf::streamsize PLearn::StdPStreamBuf::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 113 of file StdPStreamBuf.cc.
void PLearn::StdPStreamBuf::setIn | ( | istream * | pin_, |
bool | own_pin_ = false |
||
) |
Definition at line 93 of file StdPStreamBuf.cc.
References PLearn::PStreamBuf::is_readable, own_pin, and pin.
{ if (own_pin) delete pin; pin = pin_; own_pin = own_pin_; is_readable = (pin_!=0); }
void PLearn::StdPStreamBuf::setOut | ( | ostream * | pout_, |
bool | own_pout_ = false |
||
) |
Definition at line 102 of file StdPStreamBuf.cc.
References PLearn::PStreamBuf::is_writable, own_pout, and pout.
{ if (own_pout) delete pout; pout= pout_; own_pout = own_pout_; is_writable = (pout_!=0); }
void PLearn::StdPStreamBuf::write_ | ( | const char * | p, |
streamsize | n | ||
) | [protected, virtual] |
writes exactly n characters from p (unbuffered, must flush)
Reimplemented from PLearn::PStreamBuf.
Definition at line 127 of file StdPStreamBuf.cc.
bool PLearn::StdPStreamBuf::own_pin [protected] |
Definition at line 67 of file StdPStreamBuf.h.
Referenced by setIn(), and ~StdPStreamBuf().
bool PLearn::StdPStreamBuf::own_pout [protected] |
true if {pin|pout} was created internally
Definition at line 67 of file StdPStreamBuf.h.
Referenced by setOut(), and ~StdPStreamBuf().
istream* PLearn::StdPStreamBuf::pin [protected] |
underlying input stream
Definition at line 65 of file StdPStreamBuf.h.
Referenced by read_(), setIn(), and ~StdPStreamBuf().
ostream* PLearn::StdPStreamBuf::pout [protected] |
underlying output stream
Definition at line 66 of file StdPStreamBuf.h.
Referenced by good(), setOut(), write_(), and ~StdPStreamBuf().