# Poco

# class CountingStreamBuf

Library: Foundation
Package: Streams
Header: Poco/CountingStream.h

## Description

This stream buffer counts all characters and lines going through it.

## Inheritance

Direct Base Classes: UnbufferedStreamBuf

All Base Classes: UnbufferedStreamBuf

## Member Summary

Member Functions: addChars, addLines, addPos, chars, getCurrentLineNumber, lines, pos, readFromDevice, reset, setCurrentLineNumber, writeToDevice

## Constructors

### CountingStreamBuf

CountingStreamBuf();

Creates an unconnected CountingStreamBuf.

### CountingStreamBuf

CountingStreamBuf(
std::istream & istr
);

Creates the CountingStreamBuf and connects it to the given input stream.

### CountingStreamBuf

CountingStreamBuf(
std::ostream & ostr
);

Creates the CountingStreamBuf and connects it to the given output stream.

## Destructor

### ~CountingStreamBuf

~CountingStreamBuf();

Destroys the CountingStream.

## Member Functions

### addChars

void addChars(
std::streamsize chars
);

Add to the total number of characters.

### addLines

void addLines(
std::streamsize lines
);

Add to the total number of lines.

### addPos

void addPos(
std::streamsize pos
);

Add to the number of characters on the current line.

### chars

std::streamsize chars() const;

Returns the total number of characters.

### getCurrentLineNumber

std::streamsize getCurrentLineNumber() const;

Returns the current line number (same as lines()).

### lines

std::streamsize lines() const;

Returns the total number of lines.

### pos

std::streamsize pos() const;

Returns the number of characters on the current line.

### reset

void reset();

Resets all counters.

### setCurrentLineNumber

void setCurrentLineNumber(
std::streamsize line
);

Sets the current line number.

This is mainly useful when parsing C/C++ preprocessed source code containing #line directives.

### readFromDevice

int readFromDevice();

### writeToDevice

int writeToDevice(
char c
);