PLearn 0.1
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types
PLearn::FilePStreamBuf Class Reference

#include <FilePStreamBuf.h>

Inheritance diagram for PLearn::FilePStreamBuf:
Inheritance graph
[legend]
Collaboration diagram for PLearn::FilePStreamBuf:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

Definition at line 52 of file FilePStreamBuf.h.


Member Typedef Documentation

Reimplemented from PLearn::PStreamBuf.

Definition at line 57 of file FilePStreamBuf.h.


Constructor & Destructor Documentation

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;
    }        
}

Here is the call graph for this function:


Member Function Documentation

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.

{
    return fread(p, 1, n, 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.

References out, and PLERROR.

{
    streamsize nwritten = fwrite(p, 1, n, out);
    if(nwritten!=n)
        PLERROR("In FilePStreamBuf::write_ failed to write the requested number of bytes");
    fflush(out);
}

Member Data Documentation

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().

Definition at line 65 of file FilePStreamBuf.h.

Referenced by ~FilePStreamBuf().

true if {in|out} should be closed by this object upon destruction.

Definition at line 65 of file FilePStreamBuf.h.

Referenced by ~FilePStreamBuf().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines