YGP::extStreambuf Class Reference

Extended streambuf, designed to parse text. More...

Inherited by YGP::extStream< std::ifstream > [private], and YGP::extStream< T > [private].

List of all members.

Public Member Functions

 extStreambuf ()
 extStreambuf (std::streambuf &source)
 extStreambuf (std::streambuf *source)
virtual ~extStreambuf ()
Exception-handling
virtual int overflow (int ch)
virtual int underflow ()
virtual int pbackfail (int c)
Position handling
virtual std::streampos seekoff (std::streamoff, std::ios_base::seekdir, std::ios_base::openmode mode=std::ios::in|std::ios::out)
virtual std::streampos seekpos (std::streampos pos, std::ios_base::openmode mode=std::ios::in|std::ios::out)
Setting of data-sink
void setSource (std::streambuf *source)
void setSource (std::streambuf &source)
Accessing stream values
unsigned int getLine () const
unsigned int getColumn () const


Detailed Description

Extended streambuf, designed to parse text.

It overcomes two drawbacks of the original streambuf:

Note:
This buffer only works for input and needs a "real" data-sink as source, so provide another streambuf-object to get its data from with the constructor or with the setSource-method!
Also note that after repositionating in the stream (with seekoff/seekpos) the line-information might not reflect the truth anymore (and also not the column, at least til the next end-of-line is reached).

Constructor & Destructor Documentation

YGP::extStreambuf::extStreambuf (  ) 

Defaultconstructor; Although reading from this object should work and should also return some "random" data, to provide a "real" data-sink is highly recommended.

This method might be declared private (or at least protected) in the future.

YGP::extStreambuf::extStreambuf ( std::streambuf &  source  ) 

Constructur; creates an extended streambuf which takes its input from the provided source.

Parameters:
source Actual datasink to use

YGP::extStreambuf::extStreambuf ( std::streambuf *  source  ) 

Constructur; creates an extended streambuf which takes its input from the provided source.

Parameters:
source Actual datasink to use

YGP::extStreambuf::~extStreambuf (  )  [virtual]

Destructor.


Member Function Documentation

unsigned int YGP::extStreambuf::getColumn (  )  const [inline]

Returns the actual column of the stream read from.

Reimplemented in YGP::extStream< T >, and YGP::extStream< std::ifstream >.

unsigned int YGP::extStreambuf::getLine (  )  const [inline]

Returns the actual line of the stream read from.

Reimplemented in YGP::extStream< T >, and YGP::extStream< std::ifstream >.

int YGP::extStreambuf::overflow ( int  ch  )  [virtual]

Called if output would cause the streambuf to overrun.

Because this class is designed for input, this method shouldn't be called.

Parameters:
ch Char to write, causing the overflow
Returns:
int EOF in case of error

int YGP::extStreambuf::pbackfail ( int  c  )  [virtual]

Manages the failure of a pushback of a character into the stream.

There are two reasons why this method could be called while pushing back characters:

  • A character is pushed back which doesn't fit the read character. This is propably due to a programming failure and the pushback is not performed. For the sake of performance this the class ignores that case.
  • A buffer underrun; caused by pushing characters back into the previous line (and - depending on the implementation of streambuf - maybe a few characters more). In this read-position of the data-sink is changed to the end of the previous line.
    Parameters:
    c Character to put back (not EOF)
    Returns:
    int Character putted back (EOF if an error occured)
    Remarks:
    For the sake of performance the check if the character pushed back matches the character in the stream is not performed (but the next read-operation returns the "right" character)!

std::streampos YGP::extStreambuf::seekoff ( std::streamoff  off,
std::ios_base::seekdir  dir,
std::ios_base::openmode  mode = std::ios::in|std::ios::out 
) [virtual]

Positionates the read pointer to the passed offset (either starting from the beginning or the end of the stream or from the current position).

Parameters:
off Offset to change in the stream
dir Direction to change offset to
mode Which pointer to move (get, put)
Returns:
std::streampos New position in the stream

std::streampos YGP::extStreambuf::seekpos ( std::streampos  pos,
std::ios_base::openmode  mode = std::ios::in|std::ios::out 
) [virtual]

Positionates the read pointer to the passed position.

Parameters:
pos New position in the stream
mode Which pointer to move (get, put)
Returns:
std::streampos New position in the stream

void YGP::extStreambuf::setSource ( std::streambuf &  source  )  [inline]

Sets the data sink to read from.

void YGP::extStreambuf::setSource ( std::streambuf *  source  )  [inline]

Sets the data sink to read from.

int YGP::extStreambuf::underflow (  )  [virtual]

Called if the object doesn't contain data in the input-buffer.

It then copies characters from its data-sink (the streambuf passed while constructing or defined with setSource) til the next line-feed character (10, 0x0a, '
') and sets this data as its input. This method is called automatically and should NOT be used. It also might be declared protected in the future.

Returns:
int EOF in case of an error, else 0
Precondition:
Readpointer equal or behind end-of-readbuffer


The documentation for this class was generated from the following files:

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:28 2009 by doxygen 1.5.8