class Poco::CountingStreamBuf
Overview
This stream buffer counts all characters and lines going through it. Moreā¦
#include <CountingStream.h> class CountingStreamBuf: public Poco::BasicUnbufferedStreamBuf { public: // construction CountingStreamBuf(); CountingStreamBuf(std::istream& istr); CountingStreamBuf(std::ostream& ostr); // methods int chars() const; int lines() const; int pos() const; void reset(); void setCurrentLineNumber(int line); int getCurrentLineNumber() const; void addChars(int chars); void addLines(int lines); void addPos(int pos); protected: // methods virtual int readFromDevice(); int writeToDevice(char c); };
Inherited Members
public: // methods virtual int_type overflow(int_type c); virtual int_type underflow(); virtual int_type uflow(); virtual int_type pbackfail(int_type c); virtual std::streamsize xsgetn( char_type* p, std::streamsize count ); protected: // typedefs typedef std::basic_streambuf<ch, tr> Base; typedef std::basic_ios<ch, tr> IOS; typedef ch char_type; typedef tr char_traits; typedef Base::int_type int_type; typedef Base::pos_type pos_type; typedef Base::off_type off_type; typedef IOS::openmode openmode; // methods static int_type charToInt(char_type c);
Detailed Documentation
This stream buffer counts all characters and lines going through it.
Construction
CountingStreamBuf()
Creates an unconnected CountingStreamBuf.
CountingStreamBuf(std::istream& istr)
Creates the CountingStreamBuf and connects it to the given input stream.
CountingStreamBuf(std::ostream& ostr)
Creates the CountingStreamBuf and connects it to the given output stream.
Methods
int chars() const
Returns the total number of characters.
int lines() const
Returns the total number of lines.
int pos() const
Returns the number of characters on the current line.
void reset()
Resets all counters.
void setCurrentLineNumber(int line)
Sets the current line number.
This is mainly useful when parsing C/C++ preprocessed source code containing #line directives.
int getCurrentLineNumber() const
Returns the current line number (same as lines()).
void addChars(int chars)
Add to the total number of characters.
void addLines(int lines)
Add to the total number of lines.
void addPos(int pos)
Add to the number of characters on the current line.