PLearn 0.1
|
#include <FilePStreamBuf.h>
Public Member Functions | |
FilePStreamBuf (FILE *in_f=0, FILE *out_f=0, bool own_in=false, bool own_out=false) | |
virtual | ~FilePStreamBuf () |
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 | |
FILE * | in |
input FILE (0 if no input) | |
FILE * | out |
output FILE (0 if no output) | |
bool | own_in |
bool | own_out |
true if {in|out} should be closed by this object upon destruction. | |
Private Types | |
typedef PStreamBuf | inherited |
Definition at line 52 of file FilePStreamBuf.h.
typedef PStreamBuf PLearn::FilePStreamBuf::inherited [private] |
Reimplemented from PLearn::PStreamBuf.
Definition at line 57 of file FilePStreamBuf.h.
PLearn::FilePStreamBuf::FilePStreamBuf | ( | FILE * | in_f = 0 , |
FILE * | out_f = 0 , |
||
bool | own_in = false , |
||
bool | own_out = false |
||
) |
Definition at line 49 of file FilePStreamBuf.cc.
:PStreamBuf(in_f!=0, out_f!=0, 4096, 4096, default_ungetsize), in(in_f), out(out_f), own_in(own_in_), own_out(own_out_) {}
PLearn::FilePStreamBuf::~FilePStreamBuf | ( | ) | [virtual] |
Definition at line 55 of file FilePStreamBuf.cc.
References PLearn::PStreamBuf::flush(), in, out, own_in, and own_out.
{ const bool in_and_out_equal = (in == out); flush(); if(in && own_in) { fclose(in); in = 0; } if(out && own_out) { if (!in_and_out_equal) fclose(out); out = 0; } }
FilePStreamBuf::streamsize PLearn::FilePStreamBuf::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 73 of file FilePStreamBuf.cc.
References in.
void PLearn::FilePStreamBuf::write_ | ( | const char * | p, |
streamsize | n | ||
) | [protected, virtual] |
writes exactly n characters from p (unbuffered, must flush)
Reimplemented from PLearn::PStreamBuf.
Definition at line 79 of file FilePStreamBuf.cc.
FILE* PLearn::FilePStreamBuf::in [protected] |
input FILE (0 if no input)
Definition at line 63 of file FilePStreamBuf.h.
Referenced by read_(), and ~FilePStreamBuf().
FILE* PLearn::FilePStreamBuf::out [protected] |
output FILE (0 if no output)
Definition at line 64 of file FilePStreamBuf.h.
Referenced by write_(), and ~FilePStreamBuf().
bool PLearn::FilePStreamBuf::own_in [protected] |
Definition at line 65 of file FilePStreamBuf.h.
Referenced by ~FilePStreamBuf().
bool PLearn::FilePStreamBuf::own_out [protected] |
true if {in|out} should be closed by this object upon destruction.
Definition at line 65 of file FilePStreamBuf.h.
Referenced by ~FilePStreamBuf().