flush.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Function Template flush</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../../boost.css">
  6. <LINK REL="stylesheet" HREF="../theme/iostreams.css">
  7. </HEAD>
  8. <BODY>
  9. <!-- Begin Banner -->
  10. <H1 CLASS="title">Function Template <CODE>flush</CODE></H1>
  11. <HR CLASS="banner">
  12. <!-- End Banner -->
  13. <DL class="page-index">
  14. <DT><A href="#overview">Overview</A></DT>
  15. <DT><A href="#headers">Headers</A></DT>
  16. <DT><A href="#reference">Reference</A></DT>
  17. </DL>
  18. <A NAME="overview"></A></A>
  19. <H2>Overview</H2>
  20. <P>
  21. The function template <CODE>flush</CODE> attemps to flush all buffered characters downstream. It is provided to facilite modifiying a filter chain in the middle of a sequence of output operations; specifically, it is used to implement the function <CODE>strict_sync</CODE> (<I>see</I>, <I>e.g.</I>, <A HREF='../classes/filtering_stream.html#strict_sync'><CODE>filtering_stream::strict_sync</CODE></A>). If <CODE>strict_sync</CODE> succeeds, the auto-close feature of a filter chain can be safely disabled using <CODE>set_auto_close(false)</CODE> (<I>see</I>, <I>e.g.</I>, <A HREF='../classes/filtering_stream.html#set_auto_close'><CODE>filtering_stream::set_auto_close</CODE></A>). Filters can then be added to or removed from the chain with the knowledge that no characters remain buffered.
  22. </P>
  23. <P>
  24. For non-<A HREF='../concepts/flushable.html'>Flushable</A> devices, <CODE>flush</CODE> returns <CODE>true</CODE>, indicating that no error has occurred.<A CLASS='footnote_ref' NAME='note_1_ref' HREF="#note_1"><SUP>[1]</SUP></A> For non-<A HREF='../concepts/flushable.html'>Flushable</A> filters, however, <CODE>flush</CODE> returns <CODE>false</CODE>, indicating that some characters may remain buffered.
  25. </P>
  26. <P>
  27. When working with Devices, <CODE>flush</CODE> may be used as a generic version of <CODE>std::basic_ostream::flush()</CODE>.
  28. </P>
  29. <A NAME="headers"></A>
  30. <H2>Headers</H2>
  31. <DL>
  32. <DT><A CLASS="header" HREF="../../../../boost/iostreams/flush.hpp"><CODE>&lt;boost/iostreams/flush.hpp&gt;</CODE></A></DT>
  33. <DT><A CLASS="header" HREF="../../../../boost/iostreams/operations.hpp"><CODE>&lt;boost/iostreams/operations.hpp&gt;</CODE></A></DT>
  34. </DL>
  35. <A NAME="reference"></A>
  36. <H2>Reference</H2>
  37. <A NAME="description"></A>
  38. <H4>Description</H4>
  39. <P>Attempts to flush all buffered characters downstream. For <A HREF='../concepts/device.html'>Devices</A>, returns <CODE>true</CODE> unless an error occurs.<A CLASS='footnote_ref' NAME='note_1_ref2' HREF='#note_1'><SUP>[1]</SUP></A>. For <A HREF='../concepts/filter.html'>Filters</A>, returns <CODE>true</CODE> only if all buffered characters were successfully written to <CODE>snk</CODE>. </P>
  40. <A NAME="synopsis"></A>
  41. <H4>Synopsis</H4>
  42. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  43. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">T</A>&gt;
  44. <SPAN CLASS='keyword'>bool</SPAN> <A CLASS="documented" HREF="#flush_device">flush</A>(T&amp; t);
  45. <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">Sink</A>&gt;
  46. <SPAN CLASS='keyword'>bool</SPAN> <A CLASS="documented" HREF="#flush_filter">flush</A>(T&amp; t, Sink&amp; snk);
  47. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  48. <A NAME="template_params"></A>
  49. <H4>Template Parameters</H4>
  50. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  51. <TR>
  52. <TR>
  53. <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  54. <TD>For the first overload, a model of <A HREF="../concepts/device.html">Device</A>; for the second overload, a model of <A HREF="../concepts/filter.html">Filter</A>.
  55. </TR>
  56. <TR>
  57. <TD VALIGN="top"><I>Sink</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  58. <TD>A model of <A HREF="../concepts/sink.html">Sink</A> with the same <A HREF="../guide/traits.html#char_type">character type</A> as <CODE>T</CODE>.
  59. </TR>
  60. </TABLE>
  61. <A NAME="flush_device"></A>
  62. <H4>Semantics &#8212; Device Types</H4>
  63. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> T&gt;
  64. <SPAN CLASS='keyword'>bool</SPAN> flush(T&amp; t);</PRE>
  65. <P>The semantics of <CODE>flush</CODE> depends on the <A HREF="../guide/traits.html#category">category</A> of <CODE>T</CODE> as follows:</P>
  66. <TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
  67. <TR><TH><CODE>category_of&lt;T&gt;::type</CODE></TH><TH>semantics</TH></TR>
  68. <TR>
  69. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>ostream_tag</CODE></A></TD>
  70. <TD>Invokes <CODE>t.rdbuf()->pubsync()</CODE> and returns <CODE>true</CODE> if the operation succeeds.</TD>
  71. </TR>
  72. <TR>
  73. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>streambuf_tag</CODE></A> but not to <A HREF="../guide/traits.html#category_tags"><CODE>istream_tag</CODE></A></TD>
  74. <TD>Invokes <CODE>t.pubsync()</CODE> and returns <CODE>true</CODE> if the operation succeeds.</CODE></TD>
  75. </TR>
  76. <TR>
  77. <TD VALIGN="top"><I>not</I> convertible to <A HREF="../guide/traits.html#category_tags"><CODE>flushable_tag</CODE></A></TD>
  78. <TD>returns <CODE>t.flush()</CODE></TD>
  79. </TR>
  80. <TR>
  81. <TD VALIGN="top">otherwise</TD>
  82. <TD>returns <CODE>true</CODE></TD>
  83. </TR>
  84. </TABLE>
  85. <A NAME="flush_filter"></A>
  86. <H4>Semantics &#8212; Filter Types</H4>
  87. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> T, <SPAN CLASS="keyword">typename</SPAN> Sink&gt;
  88. <SPAN CLASS='keyword'>bool</SPAN> flush(T&amp; t, Sink&amp; snk);</PRE>
  89. <P>The semantics of <CODE>flush</CODE> depends on the <A HREF="../guide/traits.html#category">category</A> of <CODE>T</CODE> as follows:</P>
  90. <TABLE STYLE="margin-bottom:2em;margin-left:2em" BORDER=1 CELLPADDING=4>
  91. <TR><TH><CODE>category_of&lt;T&gt;::type</CODE></TH><TH>semantics</TH></TR>
  92. <TR>
  93. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>flushable_tag</CODE></A></TD>
  94. <TD>returns <CODE>t.flush(snk)</CODE></TD>
  95. </TR>
  96. <TR>
  97. <TD VALIGN="top">otherwise</TD>
  98. <TD>returns <CODE>false</CODE></TD>
  99. </TR>
  100. </TABLE>
  101. <!-- Begin Footnotes -->
  102. <HR>
  103. <P>
  104. <A CLASS='footnote_ref' NAME='note_1' HREF='#note_1_ref'><SUP>[1]</SUP></A>It was noticed late in developement that to be consistent with the policy of reporting errors using exceptions (<I>see</I> <A HREF='../guide/exceptions.html'>Exceptions</A>), <CODE>flush</CODE> should have been specified to return <CODE>void</CODE> when invoked on a Device. Until the specification is changed, Devices should always return <CODE>true</CODE> when flushed.
  105. </P>
  106. <!-- Begin Footer -->
  107. <HR>
  108. <P CLASS="copyright">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>&copy; Copyright 2004-2007 <a href="https://www.boost.org/users/people/jonathan_turkanis.html" target="_top">Jonathan Turkanis</a></P>
  109. <P CLASS="copyright">
  110. 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>)
  111. </P>
  112. <!-- End Footer -->
  113. </BODY>