# User's Guide

## 3.1 Concepts

Overview
Device Concepts
Filter Concepts
Optional Behavior
Convenience Templates and `typedef`s

The fundamental building blocks of the Iostreams library are the concepts of a Source, which provides read access to a sequence of characters, a Sink, which provides write access to a sequence of characters, an InputFilter, which Filters input read from a Source, and an OutputFilter, which Filters output written to a Sink. Sources, Sinks and their refinements are called Devices. InputFilters, OutputFilter and their refinements are called Filters.

Standard streams and stream buffers are Devices; for example, input streams are Sources and output streams are Sinks.[1]

In general, a Filter or Device may provide access to an input sequence, for reading, an output sequence, for writing, or both. The relationship between the two sequences, as well as the operations that may be performed on them, depends on the Filter or Device type. The various possible relationships between input and output are referred to as modes.[2] The Iostreams library provides one Device concept and one Filter concept for each of eight modes. Source, Sink, InputFilter and OutputFilter correspond to the the modes input and output and are by far the most important of the Filter and Device concepts.

The most common Device and Filter concepts are documented individually. Readers new to the Iostreams library should familiarize themselves with the four central concepts Source, Sink, InputFilter and OutputFilter. The full sets of requirements for the Filter and Device concepts are summarized in the definitions of the concepts Device and Filter which form the roots of the concept hierarchies.

To ease the task of defining new Filter and Device types, the Iostreams library provides a number of convenience templates and `typedef`s.

## Device Concepts

The most important Device concepts are these:

- Device: Base for all Device concepts, provides associated character type and category.
- Source: Provides read-only access to a sequence of characters.
- Sink: Provides write-only access to a sequence of characters.
- Bidirectionaldevice: Provides access to two separate sequences of characters, one for reading and the other for writing.
- SeekableDevice: Provides read-write access to a single sequence of characters, with a single repositionable read/write head.

## Filter Concepts

The most important Filter concepts are these:

- Filter: Base for all Filter concepts, provides associated character type and category.
- InputFilter: Filters characters read from a stream buffer.
- OutputFilter: Filters characters written to a stream buffer.
- BidirectionalFilter: Filters two separate character sequences, one read from a stream buffer and the other written to a stream buffer.
- SeekableFilter: Filters a single characters sequence, controlled by a stream buffer, providing filtered input, output and random access with a single repositionable read/write head

## Optional Behavior

Boost.Iostreams prvides several concepts corresponding to optional behavior that a Filter or Device might implement:

- Blocking: A Device which blocks when it receives a read or write request until all requested characters are available, or until the end of a stream is reached.
- Direct: A Device which provides access to its controlled sequences as regions of memory rather than via a socket-like interface.
- Closable: A Filter or Device which receives notifications immediately before a stream is closed.
- Flushable A Filter or Device which receives notifications when a stream is flushed.
- Localizable: A Filter or Device which receives notifications when the `locale` of a stream or stream buffer is set using `basic_ios::imbue` or `basic_streambuf::pubimbue`.
- Multi-Character: A Filter which provides access to its controlled sequences several characters at a time, via a socket-like interface.
- OptimallyBuffered A Filter or Device which will be fitted with a buffer of custom size if no buffer size is explicitly requested by the user.
- Peekable: A source which allows characters to be put back to the input sequence.
- Pipable: A Filter which can appear in pipelines.

## Convenience Templates and `typedef`s

The Iostreams library provides several templates intended for derivation by user-defined Filter and Device types. They ease the task of defining Filters and Devices by providing member types and default implementations of several member functions.

The template `device` and its specializations `source` and `sink` help users define new Device types; the template `filter` and its specializations `input_filter` and `output_filter` help users define new Filter types; the template `multichar_filter` and its specializations `multichar_input_filter` and `multichar_output_filter` help users define new multichar Filter types. There are also wide-character versions of these templates, `wdevice`, `wfilter` and `multichar_wfilter`, as well as corresponding wide-character `typedef`s.

[1]For complete details, see `mode_of`.

[2]A more precise definition is given in Modes.

Revised 20 May, 2004

© Copyright Jonathan Turkanis, 2004

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)