Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/iostreams/doc/functions/close.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 13.4 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4    <TITLE>Function Template close</TITLE>
5    <LINK REL="stylesheet" HREF="../../../../boost.css">
6    <LINK REL="stylesheet" HREF="../theme/iostreams.css">
7    <STYLE> H3 CODE { font-size: 120% } </STYLE>
8</HEAD>
9<BODY>
10
11<!-- Begin Banner -->
12
13    <H1 CLASS="title">Function Template <CODE>close</CODE></H1>
14    <HR CLASS="banner">
15
16<!-- End Banner -->
17
18<DL class="page-index">
19  <DT><A href="#description">Description</A></DT>
20  <DT><A href="#when">When is <CODE>close</CODE> invoked?</DT>
21  <DT><A href="#headers">Headers</A></DT>
22  <DT><A href="#reference">Reference</A></DT>
23</DL>
24
25<A NAME="description"></A>
26<H2>Description</H2>
27
28<P>
29    The two overloads of the function template <CODE>close</CODE> are invoked automatically by the Iostreams library to indicate to <A HREF="../guide/concepts.html#filter_concepts">Filters</A> and <A HREF="../guide/concepts.html#device_concepts">Devices</A> that a sequence of data is about to end. This gives Filters and Devices an opportunity to free resources or to reset their states in preparation for a new character sequence. Filters and Devices which perform output can use the opportunity to write additional data to the end of a stream.
30</P>
31
32<P>The details regarding when and how <CODE>close</CODE> is invoked are a bit messy:</P>
33
34<A NAME="when"></A>
35<H2>When is <CODE>close</CODE> invoked?</H2>
36
37<H4><CODE>stream_buffer</CODE> and <CODE>stream</CODE></H4>
38
39<P>When an instance of <CODE>stream_buffer</CODE> or <CODE>stream</CODE> based on a Device <CODE>d</CODE> is closed using member function <CODE>close</CODE>, the following sequence of functions calls is made:<P>
40<PRE CLASS="broken_ie">    boost::iostreams::close(d, std::ios_base::in);
41    boost::iostreams::close(d, std::ios_base::out);</PRE>
42<P>The effect, if <CODE>D</CODE> is <A HREF="../concepts/closable.html">Closable</A> and controls a single sequence, is as follows:</P>
43<PRE CLASS="broken_ie">    d.close();</PRE>
44<P>If <CODE>D</CODE> is <A HREF="../concepts/closable.html">Closable</A> and controls separate input and output sequences, the effect is as follows:</P>
45<PRE CLASS="broken_ie">    d.close(std::ios_base::in);
46    d.close(std::ios_base::out);</PRE>
47
48<P>(<I>See</I> the semantics of <CODE>close</CODE> for <A HREF="#close_device">Device types</A>, below.)
49
50<H4><CODE>filtering_streambuf</CODE> and <CODE>filtering_stream</CODE></H4>
51
52<P>
53    A <A HREF="../classes/filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A> or <A HREF="../classes/filtering_stream.html"><CODE>filtering_stream</CODE></A> is considered to be <I>closed</I> if its lifetime ends while its chain is complete or if its terminal Device is removed using <CODE>pop</CODE> or <CODE>reset</CODE>. When this occurs, the following sequence of calls is made, assuming that the underlying sequence of Filters and Devices is <CODE>f<SUB>1</SUB></CODE>, <CODE>f<SUB>1</SUB></CODE>, ..., <CODE>f<SUB>n-1</SUB></CODE>, <CODE>d</CODE> and the corresponding sequence of stream buffers is <CODE>buf<SUB>1</SUB></CODE>, <CODE>buf<SUB>2</SUB></CODE>, ..., <CODE>buf<SUB>n-1</SUB></CODE>, <CODE>buf<SUB>n</SUB></CODE>:<A CLASS='footnote_ref' NAME='note_1_ref' HREF="#note_1"><SUP>[1]</SUP></A>
54
55    <PRE CLASS="broken_ie">    <SPAN CLASS="keyword">using</SPAN> <SPAN CLASS="keyword">namespace</SPAN> std;
56   
57    <SPAN CLASS="comment">// Close each input sequence, in reverse order:</SPAN>
58    boost::iostreams::close(d,<SPAN STYLE="visibility:hidden"><SUB>n-1</SUB>, buf<SUB>n-1</SUB></SPAN> ios_base::in);
59    boost::iostreams::close(f<SUB>n-1</SUB>, buf<SUB>n</SUB>,<SPAN STYLE="visibility:hidden"><SUB>-1</SUB></SPAN> ios_base::in);
60    boost::iostreams::close(f<SUB>n-2</SUB>, buf<SUB>n-1</SUB>, ios_base::in);
61    <SPAN CLASS="omitted">...</SPAN>
62    boost::iostreams::close(f<SUB>1</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> buf<SUB>2</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> ios_base::in);
63
64    <SPAN CLASS="comment">// Close each output sequence, in order:</SPAN>
65    boost::iostreams::close(f<SUB>1</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> buf<SUB>2</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> ios_base::out);
66    boost::iostreams::close(f<SUB>2</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> buf<SUB>3</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> ios_base::out);
67    <SPAN CLASS="omitted">...</SPAN>
68    boost::iostreams::close(f<SUB>n-1</SUB>, buf<SUB>n</SUB>,<SPAN STYLE="visibility:hidden"><SUB>n-</SUB></SPAN> ios_base::out);
69    boost::iostreams::close(d,<SPAN STYLE="visibility:hidden"><SUB>n-1</SUB>, buf<SUB>n-1</SUB></SPAN> ios_base::out);</PRE>
70</P>
71<P>The effect is that with input streams, the elements of a chain are closed in reverse order; with output streams, they are closed in forward order; and with streams controlling separate input and output sequences, each element receives two closure notifications, the first with argument <CODE>ios_base::in</CODE> and the second with argument <CODE>ios_base::out</CODE>. (<I>See</I> the semantics of <CODE>close</CODE> for <A HREF="#close_filter">Filter</A> and <A HREF="#close_device">Device</A> types, below.)
72</P>
73
74<A NAME="headers"></A>
75<H2>Headers</H2>
76
77<DL>
78  <DT><A CLASS="header" HREF="../../../../boost/iostreams/close.hpp"><CODE>&lt;boost/iostreams/close.hpp&gt;</CODE></A></DT>
79  <DT><A CLASS="header" HREF="../../../../boost/iostreams/operations.hpp"><CODE>&lt;boost/iostreams/operations.hpp&gt;</CODE></A></DT>
80</DL>
81
82<A NAME="reference"></A>
83<H2>Reference</H2>
84
85<A NAME="synopsis"></A>
86<H3>Synopsis</H3>
87
88<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
89             
90<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">T</A>&gt;     
91<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#close_device">close</A>(T& t, std::ios_base::openmode which);
92
93<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">T</A>, <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Device</A>&gt;
94<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#close_filter">close</A>(T& t, Device& next, std::ios_base::openmode which);
95
96} } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
97
98<A NAME="close_device"></A>
99<H3>Function Template <CODE>close</CODE> &#8212; Device Types</H3>
100
101<A NAME="template_params"></A>
102<H4>Template Parameters</H4>
103
104<TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
105<TR>
106    <TR>
107        <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
108        <TD>A model of one of the <A HREF="../guide/concepts.html#device_concepts">Device</A> concepts.
109    </TR>
110</TABLE>
111
112<H4>Semantics</H4>
113
114<PRE CLASS="broken_ie"><SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> T&gt;     
115<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#close_device">close</A>(T& t, std::ios_base::openmode which);</PRE>
116
117<P>The semantics of <CODE>close</CODE> for a Device type <CODE>T</CODE> depends on its <A HREF="../guide/traits.html#category">category</A> as follows:</P>
118
119<TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
120    <TR><TH><CODE>category&lt;T&gt;::type</CODE></TH><TH>semantics</TH></TR>
121    <TR>
122        <TD VALIGN="top">not convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A></TD>
123        <TD>no-op</TD>
124    </TR>
125    <TR>
126        <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A> and to <A HREF="../guide/modes.html#bidirectional"><CODE>bidirectional</CODE></A></A></TD>
127        <TD>calls <CODE>t.close(which)</CODE></TD>
128    </TR>
129    <TR>
130        <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A> and to <A HREF="../guide/modes.html#input"><CODE>input</CODE></A> but not to <A HREF="../guide/modes.html#output"><CODE>output</CODE></A></TD>
131        <TD>calls <CODE>t.close()</CODE> if <CODE>(which & ios_base::in) != 0</CODE></TD>
132    </TR>
133    <TR>
134        <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A> and to <A HREF="../guide/modes.html#input"><CODE>output</CODE></A> but not to <A HREF="../guide/modes.html#bidirectional"><CODE>bidirectional</CODE></A></TD>
135        <TD>calls <CODE>t.close()</CODE> if <CODE>(which & ios_base::out) != 0</CODE></TD>
136    </TR>
137</TABLE>
138
139<P>In short:
140<UL>
141    <LI CLASS="square">If <CODE>T</CODE> is not <A HREF="../concepts/closable.html">Closable</A>, <CODE>close</CODE> does nothing.
142    <LI CLASS="square">If <CODE>T</CODE> is <A HREF="../concepts/closable.html">Closable</A> and controls two separate sequences, <CODE>close</CODE> delegates to a member function <CODE>close</CODE> taking a single <CODE>openmode</CODE> parameter.
143    <LI CLASS="square">Otherwise, <CODE>close</CODE> delegates to a member function <CODE>close</CODE> taking no parameters, but only if its <CODE>openmode</CODE> parameter is consistent with the mode of <CODE>T</CODE>.
144</UL>
145
146<P>The last condition prevents a Device controlling a single sequence from being closed twice in succession.</P>
147
148<A NAME="close_filter"></A>
149<H3>Function Template <CODE>close</CODE> &#8212; Filter Types</H3>
150
151<A NAME="template_params"></A>
152<H4>Template Parameters</H4>
153
154<TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
155<TR>
156    <TR>
157        <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
158        <TD>A model of one of the <A HREF="../guide/concepts.html#filter_concepts">Filter</A> concepts</TD>
159    </TR>
160    <TR>
161        <TD VALIGN="top"><I>Device</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
162        <TD>A <A HREF="../concepts/blocking.html">Blocking</A> <A HREF="../concepts/device.html">Device</A> whose <A HREF="../guide/modes.html">mode</A> refines that of <CODE>T</CODE>.</TD>
163    </TR>
164</TABLE>
165
166<H4>Semantics</H4>
167
168<PRE CLASS="broken_ie"><SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> T, <SPAN CLASS="keyword">typename</SPAN> Device&gt;
169<SPAN CLASS="keyword">void</SPAN> close(T& t, Device& next, std::ios_base::openmode which);</PRE>
170
171<P>The semantics of <CODE>close</CODE> for a Filter type <CODE>T</CODE> depends on its <A HREF="../guide/traits.html#category">category</A> as follows:</P>
172
173<TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
174    <TR><TH><CODE>category&lt;T&gt;::type</CODE></TH><TH>semantics</TH></TR>
175    <TR>
176        <TD VALIGN="top">not convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A></TD>
177        <TD>no-op</TD>
178    </TR>
179    <TR>
180        <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A> and to <A HREF="../guide/modes.html#bidirectional"><CODE>bidirectional</CODE></A></A></TD>
181        <TD>calls <CODE>t.close(next, which)</CODE></TD>
182    </TR>
183    <TR>
184        <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A> and to <A HREF="../guide/modes.html#input"><CODE>input</CODE></A> but not to <A HREF="../guide/modes.html#output"><CODE>output</CODE></A></TD>
185        <TD>calls <CODE>t.close(next)</CODE> if <CODE>(which & ios_base::in) != 0</CODE></TD>
186    </TR>
187    <TR>
188        <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>closable_tag</CODE></A> and to <A HREF="../guide/modes.html#input"><CODE>output</CODE></A> but not to <A HREF="../guide/modes.html#bidirectional"><CODE>bidirectional</CODE></A></TD>
189        <TD>calls <CODE>t.close(next)</CODE> if <CODE>(which & ios_base::out) != 0</CODE></TD>
190    </TR>
191</TABLE>
192
193<P>In short:
194<UL>
195    <LI CLASS="square">If <CODE>T</CODE> is not <A HREF="../concepts/closable.html">Closable</A>, <CODE>close</CODE> does nothing.
196    <LI CLASS="square">If <CODE>T</CODE> is <A HREF="../concepts/closable.html">Closable</A> and controls two separate sequences, <CODE>close</CODE> delegates to a member function <CODE>close</CODE> taking <CODE>openmode</CODE> and stream buffer parameters.
197    <LI CLASS="square">Otherwise, <CODE>close</CODE> delegates to a member function <CODE>close</CODE> taking a single stream buffer parameter, but only if its <CODE>openmode</CODE> parameter is consistent with the mode of <CODE>T</CODE>.
198</UL>
199
200<P>The last condition prevents a Filter controlling a single sequence from being closed twice in succession.</P>
201
202<!-- End Footnotes -->
203
204<HR>
205
206<P>
207<A CLASS='footnote_ref' NAME='note_1' HREF="#note_1_ref"><SUP>[1]</SUP></A>This behavior can be disabled in the case of <CODE>pop</CODE> by calling member function <CODE>set_auto_close</CODE> with the argument <CODE>false</CODE>. See, e.g., <A HREF="../classes/filtering_stream.html#set_auto_close"><CODE>filtering_stream::set_auto_close</CODE></A>.
208</P>
209
210<!-- Begin Footnotes -->
211
212<!-- Begin Footer -->
213
214<HR>
215<P CLASS="copyright">Revised
216<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
21720 May, 2004
218<!--webbot bot="Timestamp" endspan i-checksum="38504" -->
219</P>
220
221<P CLASS="copyright">&copy; Copyright <A HREF="http://www.kangaroologic.com" TARGET="_top">Jonathan Turkanis</A>, 2004</P>
222<P CLASS="copyright"> 
223    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>)
224</P>
225
226<!-- End Footer -->
227
228</BODY>
Note: See TracBrowser for help on using the repository browser.