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

#include <StringPStreamBuf.h>

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

List of all members.

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

Detailed Description

Definition at line 53 of file StringPStreamBuf.h.


Member Typedef Documentation

Reimplemented from PLearn::PStreamBuf.

Reimplemented in PLearn::LogInterceptorPStreamBuf, and PLearn::PlideLogPStreamBuf.

Definition at line 58 of file StringPStreamBuf.h.


Constructor & Destructor Documentation

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.

References PLERROR, and st.

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

Here is the call graph for this function:


Member Function Documentation

void PLearn::StringPStreamBuf::clear ( ) [inline]

Definition at line 80 of file StringPStreamBuf.h.

References PLearn::flush().

Referenced by PLearn::_tostring_static_pstream_().

    { 
        flush();        
        st->clear();        
    }

Here is the call graph for this function:

Here is the caller graph for this function:

const string& PLearn::StringPStreamBuf::getString ( ) const [inline]

Definition at line 77 of file StringPStreamBuf.h.

References PLASSERT.

    { PLASSERT(st); return *st; }
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.

{
    while(n--)
        st->operator+=(*p++);
}

Member Data Documentation

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


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