Chapter 11. IO filter classes

An input/output filter, or an IO filter, is a design pattern that originally came from several libraries that implement data compression, but is now found in other applications too. An IO filter transfers some chunk of data from an input buffer to an output buffer, using some transformation process. The input to the transformation process is a pointer to the input data, a count of how many input elements there are available, a pointer to the output buffer, and the size of the output buffer. The input buffer may not contain the entire set of data to be filtered. Typically, the input data gets presented in small portions or chunks, and gets filtered, or transformed, in small chunks.

Each transformation step can consume the entire input buffer, or some part of it, and produce a full output buffer, or fill a part of it. The transformation step updates the input pointer, the input count, the output buffer pointer, and the remaining unused output buffer size accordingly, to reflect the filtered data.

The x::iofilter class template defines an interface to a filter. The x::iofilter template takes two parameters: an input type and an output type. An x::iofilter does not necessarily convert between two same types, an implementation may convert an input sequence of one type to an input sequence of another type. An implementation must derive virtually from x::iofilter, in order to implement it.