classes for efficient and flexible counting of words and lines in a stream of characters