]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/doc/concepts/filter.html
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / iostreams / doc / concepts / filter.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Filter</TITLE>
5 <LINK REL="stylesheet" HREF="../../../../boost.css">
6 <LINK REL="stylesheet" HREF="../theme/iostreams.css">
7 <STYLE> P.concept { margin:.5em } </STYLE>
8 </HEAD>
9 <BODY>
10
11 <!-- Begin Banner -->
12
13 <H1 CLASS="title">Filter</H1>
14 <HR CLASS="banner">
15
16 <!-- End Banner -->
17
18 <H2>Description</H2>
19
20 <P>
21 A Filter operates on the character sequence or sequences controlled by a <A HREF="device.html">Device</A>, providing access to a filtered input sequence, output sequence or both. Informally, when a Filter <CODE>f</CODE> is used in conjunction with a Device <CODE>d</CODE>, data read from the input sequence of <CODE>d</CODE> is processed by <CODE>f</CODE> before being returned to the user, data written to the output sequence of <CODE>d</CODE> is first processed by <CODE>f</CODE>, and repositioning operations are processed by <CODE>f</CODE> before being conveyed to <CODE>d</CODE>.
22 </P>
23 <P>
24 Filters are class types which define one or more member functions <CODE>get</CODE>, <CODE>put</CODE>, <CODE>read</CODE>, <CODE>write</CODE> and <CODE>seek</CODE>; each function takes a reference to a Device as its first argument. Whenever a Filter is used to perform an i/o operation, a reference to the Device being filtered is passed to the Filter as a function argument.
25 </P>
26 <P>
27 Each Filter type has an associated character type and category. The <A HREF="../guide/traits.html#char_type">character type</A> is the type of the characters in the input and output sequences. The <A HREF="../guide/traits.html#category">category</A> is a tag structure which the Iostreams library relies on to determine which operations the Filter type supports. Its function is similar to the <CODE>iterator_category</CODE> member of <CODE>std::iterator_traits</CODE>.<A CLASS="footnote_ref" NAME="note_1_ref" HREF="#note_1"><SUP>[1]</SUP></A>
28 </P>
29 <P>
30 There is one refinement of Filter for each of the eight <A HREF="../guide/modes.html">modes</A>, and each such refinement corresponds to a refinement of <A HREF="device.html">Device</A>. In order to express this corresponce cleanly, it is helpful to include the requirements of the various refinements of Filter in the definition of Filter itself, qualified by category. The various refinements of Filter can then be characterized exactly by the following definitions. For convenience, the requirements of the four most common Filter refinements are also documented individually.
31 </P>
32
33 <TABLE CELLPADDING="5" BORDER="1">
34 <TR><TH>Concept</TH><TH>Definition</TH></TR>
35 <TR>
36 <TD><A href="input_filter.html">InputFilter</A></TD>
37 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#input"><CODE>input</CODE></A></TD>
38 </TR>
39 <TR>
40 <TD><A href="output_filter.html">OutputFilter</A></TD>
41 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#output"><CODE>output</CODE></A></TD>
42 </TR>
43 <TR>
44 <TD><A href="bidirectional_filter.html">BidirectionalFilter</A></TD>
45 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#bidirectional"><CODE>bidirectional</CODE></A></TD>
46 </TR>
47 <TR>
48 <TD><A href="seekable_filter.html">SeekableFilter</A></TD>
49 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#seekable"><CODE>seekable</CODE></A></TD>
50 </TR>
51 <TR>
52 <TD>InputSeekableFilter</TD>
53 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#input_seekable"><CODE>input_seekable</CODE></A></TD>
54 </TR>
55 <TR>
56 <TD>OutputSeekableFilter</TD>
57 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#output_seekable"><CODE>output_seekable</CODE></A></TD>
58 </TR>
59 <TR>
60 <TD>BidirectionalSeekableFilter</TD>
61 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#bidirectional_seekable"><CODE>bidirectional_seekable</CODE></A></TD>
62 </TR>
63 <TR>
64 <TD>DualSeekableFilter</TD>
65 <TD>Refinement of Filter with mode convertible to <A HREF="../guide/modes.html#dual_seekable"><CODE>dual_seekable</CODE></A></TD>
66 </TR>
67 </TABLE>
68
69 <H2>Refinement of</H2>
70
71 <A NAME="types"></A>
72 <H2>Associated Types</H2>
73
74 <TABLE CELLPADDING="5" BORDER="1">
75 <TR><TD>Character type</TD><TD>The type of the characters in the filtered sequences</TD></TR>
76 <TR>
77 <TD>Category</TD>
78 <TD>
79 A type convertible to <A HREF="../guide/traits.html#category_tags"><CODE>filter_tag</CODE></A> and to a unique <I>most-derived</I> <A HREF="../guide/modes.html#mode_tags">mode tag</A>
80 </TD>
81 </TR>
82 <TR>
83 <TD>Mode</TD>
84 <TD>
85 The unique <I>most-derived</I> <A HREF="../guide/modes.html#mode_tags">mode tag</A> to which Category is convertible
86 </TD>
87 </TR>
88 </TABLE>
89
90 <H2>Notation</H2>
91
92 <TABLE CELLPADDING="2">
93 <TR><TD><CODE>F</CODE></TD><TD>- A type which is a model of Filter</TD></TR>
94 <TR><TD><CODE>D</CODE></TD><TD>- A type which is a model of <A HREF="device.html">Device</A>, with the same character type as <CODE>F</CODE> and with mode refining the mode of <CODE>F</CODE></TD></TR>
95 <TR><TD><CODE>Ch</CODE></TD><TD>- The character type of <CODE>F</CODE></TD></TR>
96 <TR><TD><CODE>Tr</CODE></A></TD><TD>- <A HREF="../classes/char_traits.html"><CODE>boost::iostreams::char_traits&lt;Ch&gt;</CODE></A></TD></TR>
97 <TR><TD><CODE>f</CODE></TD><TD>- Object of type <CODE>F</CODE></TD></TR>
98 <TR><TD><CODE>d</CODE></TD><TD>- Object of type <CODE>D</CODE></TD></TR>
99 <TR><TD><CODE>c</CODE></TD><TD>- Object of type <CODE>Ch</CODE></TD></TR>
100 <TR><TD><CODE>s1</CODE></TD><TD>- Object of type <CODE>Ch*</CODE></TD></TR>
101 <TR><TD><CODE>s2</CODE></TD><TD>- Object of type <CODE>const Ch*</CODE></TD></TR>
102 <TR><TD><CODE>n</CODE></TD><TD>- Object of type <CODE>std::streamsize</CODE></TD></TR>
103 <TR><TD><CODE>off</CODE></TD><TD>- Object of type <A HREF="../functions/positioning.html#synopsis"><CODE>stream_offset</CODE></A></TD></TR>
104 <TR><TD><CODE>way</CODE></TD><TD>- Object of type <CODE>std::ios_base::seekdir</CODE></TD></TR>
105 <TR><TD><CODE>which</CODE></TD><TD>- Object of type <CODE>std::ios_base::openmode</CODE></TD></TR>
106 <TR><TD><CODE>io</CODE></TD><TD>- Alias for namespace <CODE>boost::iostreams</CODE></TD></TR>
107 </TABLE>
108
109
110 <A NAME="expressions"></A>
111 <H2>Valid Expressions &#8212; Typenames</H2>
112
113 <TABLE CELLPADDING="5" BORDER="1">
114 <TR><TH>Expression</TH><TH>Expression Type</TH></TR>
115 <TR>
116 <TD><CODE>typename <A HREF="../guide/traits.html#char_type_of_ref">char_type_of</A>&lt;F&gt;::type</CODE></TD>
117 <TD><CODE>typename</CODE> of the character type</TD>
118 </TR>
119 <TR>
120 <TD><CODE>typename <A HREF="../guide/traits.html#category_ref">category_of</A>&lt;F&gt;::type</CODE></TD>
121 <TD><CODE>typename</CODE> of the category</TD>
122 </TR>
123 </TABLE>
124
125 <H2>Valid Expressions / Semantics &#8212; Input</H2>
126
127 <TABLE CELLPADDING="5" BORDER="1">
128 <TR><TH>Expression</TH><TH>Expression Type</TH><TH>Category Precondition</TH><TH>Semantics</TH></TR>
129 <TR>
130 <TD><PRE CLASS="plain_code"><CODE>f.get(d)</CODE></PRE></TD>
131 <TD><CODE>Tr::int_type</CODE></TD>
132 <TD>
133 Convertible to <A HREF="../guide/modes.html#mode_tags"><CODE>input</CODE></A> but not to <A HREF="../guide/traits.html#category_tags"><CODE>multichar_tag</CODE></A>
134 </TD>
135 <TD>
136 Returns the next character in the input sequence controlled by <CODE>f</CODE>, <CODE>Tr::eof()</CODE> if the end of the sequence has been reached or <CODE>Tr::would_block()</CODE> if input is temporarily unavilable because a call to <CODE>d</CODE> has produced fewer characters than requested. The input sequence controlled by <CODE>d</CODE> may be accessed using <A HREF="../functions/get.html"><CODE>io::get</CODE></A>, <A HREF="../functions/read.html"><CODE>io::read</CODE></A> and <A HREF="../functions/putback.html"><CODE>io::putback</CODE></A>.
137 </TD>
138 </TR>
139 <TR>
140 <TD><PRE CLASS="plain_code"><CODE>f.read(d, s1, n)</CODE></PRE></TD>
141 <TD><PRE CLASS="plain_code"><CODE>std::streamsize</CODE></PRE></TD>
142 <TD>
143 Convertible to <A HREF="../guide/modes.html#mode_tags"><CODE>input</CODE></A> and to <A HREF="../guide/traits.html#category_tags"><CODE>multichar_tag</CODE></A>
144 </TD>
145 <TD>
146 Reads up to <CODE>n</CODE> characters from the input sequence controlled by <CODE>f</CODE> into the buffer <CODE>s1</CODE>, returning the number of characters read or <CODE>-1</CODE> to indicate end-of-sequence. A value less than <CODE>n</CODE> may be returned only at end-of-sequence or if input is temporarily unavilable because a call to <CODE>d</CODE> has produced fewer characters than requested. The input sequence controlled by <CODE>d</CODE> may be accessed using <A HREF="../functions/get.html"><CODE>io::get</CODE></A>, <A HREF="../functions/read.html"><CODE>io::read</CODE></A> and <A HREF="../functions/putback.html"><CODE>io::putback</CODE></A>.
147 </TD>
148 </TR>
149 </TABLE>
150
151 <H2>Valid Expressions / Semantics &#8212; Output</H2>
152
153 <TABLE CELLPADDING="5" BORDER="1">
154 <TR><TH>Expression</TH><TH>Expression Type</TH><TH>Category Precondition</TH><TH>Semantics</TH></TR>
155 <TR>
156 <TD><PRE CLASS="plain_code"><CODE>f.put(d, c)</CODE></PRE></TD>
157 <TD><CODE>bool</CODE></TD>
158 <TD>
159 Convertible to <A HREF="../guide/modes.html#mode_tags"><CODE>output</CODE></A> but not to <A HREF="../guide/traits.html#category_tags"><CODE>multichar_tag</CODE></A>
160 </TD>
161 <TD>
162 Attempts to writes the character <CODE>c</CODE> to the output sequence controlled by <CODE>f</CODE>, returning <CODE>false</CODE> if <CODE>c</CODE> cannot be consumed because a call to <CODE>d</CODE> has consumed fewer characters than requested. The output sequence controlled by <CODE>d</CODE> may be accessed using <A HREF="../functions/put.html"><CODE>io::put</CODE></A> and <A HREF="../functions/write.html"><CODE>io::write</CODE></A>.
163 </TD>
164 </TR>
165 <TR>
166 <TD><PRE CLASS="plain_code"><CODE>f.write(d, s2, n)</CODE></PRE></TD>
167 <TD><PRE CLASS="plain_code"><CODE>std::streamsize</CODE></PRE></TD>
168 <TD>
169 Convertible to <A HREF="../guide/modes.html#mode_tags"><CODE>output</CODE></A> and to <A HREF="../guide/traits.html#category_tags"><CODE>multichar_tag</CODE></A>
170 </TD>
171 <TD>
172 Writes up to <CODE>n</CODE> characters from the buffer <CODE>s2</CODE> to the output sequence controlled by <CODE>d</CODE>, returning the number of characters written. A value less than <CODE>n</CODE> may be returned only if a call to <CODE>d</CODE> has consumed fewer characters than requested. The output sequence controlled by <CODE>d</CODE> may be accessed using <A HREF="../functions/put.html"><CODE>io::put</CODE></A> and <A HREF="../functions/write.html"><CODE>io::write</CODE></A>.
173 </TD>
174 </TR>
175 </TABLE>
176
177 <H2>Valid Expressions / Semantics &#8212; Random-Access</H2>
178
179 <TABLE CELLPADDING="5" BORDER="1">
180 <TR><TH>Expression</TH><TH>Expression Type</TH><TH>Category Precondition</TH><TH>Semantics</TH></TR>
181 <TR>
182 <TD><PRE CLASS="plain_code"><CODE>f.seek(d, off, way)</CODE></PRE></TD>
183 <TD><CODE>std::streampos</CODE></TD>
184 <TD>
185 Convertible to <A HREF="../guide/modes.html#mode_tags"><CODE>seekable</CODE></A> but not to <A HREF="../guide/traits.html#category_tags"><CODE>direct_tag</CODE></A>
186 </TD>
187 <TD>
188 <P CLASS="concept">
189 Advances the read/write head by <CODE>off</CODE> characters, returning the new position, where the offset is calculated from:
190 </P>
191 <UL STYLE="margin:0,0,0,auto">
192 <LI STYLE="list-style-type:disc;list-style-image:none">the start of the sequence if <CODE>way</CODE> is <CODE>ios_base::beg</CODE>
193 <LI STYLE="list-style-type:disc;list-style-image:none">the current position if <CODE>way</CODE> is <CODE>ios_base::cur</CODE>
194 <LI STYLE="list-style-type:disc;list-style-image:none">the end of the sequence if <CODE>way</CODE> is <CODE>ios_base::end</CODE>
195 </UL>
196 <P CLASS="concept">
197 The input sequence controlled by <CODE>d</CODE> may be accessed using <A HREF="../functions/read.html"><CODE>io::seek</CODE></A> and using <A HREF="../functions/putback.html"><CODE>io::write</CODE></A> if the <A HREF="../guide/modes.html">mode</A> of <CODE>F</CODE> is convertible to <A HREF="../guide/modes.html#output"><CODE>output</CODE></A>.
198 </P>
199 </TD>
200 </TR>
201 <TR>
202 <TD><PRE CLASS="plain_code"><CODE>f.seek(d, off, way, which)</CODE></PRE></TD>
203 <TD><CODE>std::streampos</CODE></TD>
204 <TD>
205 Convertible to <A HREF="../guide/modes.html#mode_tags"><CODE>dual_seekable</CODE></A> or <A HREF="../guide/modes.html#mode_tags"><CODE>bidirectional_seekable</CODE></A> but not to <A HREF="../guide/traits.html#category_tags"><CODE>direct_tag</CODE></A>
206 </TD>
207 <TD>
208 <P CLASS="concept">
209 Advances the read head (if <CODE>which</CODE> is <CODE>std::ios_base::in</CODE>), the write head (if <CODE>which</CODE> is <CODE>std::ios_base::out</CODE>) or both heads (if <CODE>which</CODE> is <CODE>std::ios_base::in | std::ios_base::out</CODE>) by <CODE>off</CODE> characters, returning the new position, where the offset is calculated from
210 </P>
211 <UL STYLE="margin:0,0,0,auto">
212 <LI STYLE="list-style-type:disc;list-style-image:none">the start of the sequence if <CODE>way</CODE> is <CODE>ios_base::beg</CODE>
213 <LI STYLE="list-style-type:disc;list-style-image:none">the current position if <CODE>way</CODE> is <CODE>ios_base::cur</CODE>
214 <LI STYLE="list-style-type:disc;list-style-image:none">the end of the sequence if <CODE>way</CODE> is <CODE>ios_base::end</CODE>
215 </UL>
216 <P CLASS="concept">
217 The input sequence controlled by <CODE>d</CODE> may be accessed using <A HREF="../functions/read.html"><CODE>io::seek</CODE></A>, and using <A HREF="../functions/putback.html"><CODE>io::write</CODE></A> if the <A HREF="../guide/modes.html">mode</A> of <CODE>F</CODE> is convertible to <A HREF="../guide/modes.html#output"><CODE>output</CODE></A>.
218 </P>
219 <P CLASS="concept">
220 The result is undefined if <CODE>way</CODE> is <CODE>ios_base::cur</CODE> and <CODE>which</CODE> is <CODE>(std::ios_base::in | std::ios_base::out)</CODE>.
221 </P>
222 </TD>
223 </TR>
224 </TABLE>
225
226 <H2>Exceptions</H2>
227
228 <P>
229 Errors which occur during the execution of <CODE>get</CODE>, <CODE>put</CODE>, <CODE>read</CODE>, <CODE>write</CODE> or <CODE>seek</CODE> are indicated by throwing exceptions. Reaching the end of the input sequence is not an error, but attempting to write past the end of the output sequence is.
230 </P>
231
232 <P>
233 After an exception is thrown, a Filter must be in a consistent state; further i/o operations may throw exceptions but must have well-defined behaviour. Furthermore, unless it is <A HREF="closable.html">Closable</A>, it must be ready to begin processing a new character sequence.
234 </P>
235
236
237 <H2>Models</H2>
238
239 <P>
240 See <A HREF="input_filter.html">InputFilter</A>, <A HREF="output_filter.html">OutputFilter</A>, <A HREF="bidirectional_filter.html">BidirectionalFilter</A> and <A HREF="seekable_filter.html">SeekableFilter</A>.
241 </P>
242
243 <H2>Acknowledgments</H2>
244
245 <P>
246 The concept Filter was inspired by the <I>inserters</I> and <I>extractors</I> of <A CLASS="footnote_ref" HREF="../bibliography.html#kanze">[Kanze]</A>.
247 </P>
248
249 <!-- Begin Footnotes -->
250
251 <HR>
252
253 <P>
254 <A CLASS="footnote_ref" NAME="note_1" HREF="#note_1_ref"><SUP>[1]</SUP></A><A CLASS="bib_ref" HREF="../bibliography.html#iso">[I<SPAN STYLE="font-size:80%">SO</SPAN>]</A>, 24.3.1. <I>See</I> <A HREF="http://www.boost.org/more/generic_programming.html#tag_dispatching" TARGET="_top">Tag Dispatching</A> for a discussion.
255 </P>
256
257 <!-- End Footnotes -->
258
259 <!-- Begin Footer -->
260
261 <HR>
262
263 <P CLASS="copyright">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>&copy; Copyright 2004-2007 <a href="http://www.coderage.com/turkanis/" target="_top">Jonathan Turkanis</a></P>
264 <P CLASS="copyright">
265 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <A HREF="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)
266 </P>
267
268 <!-- End Footer -->
269
270 </BODY>