faq.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Frequently Asked Questions</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">Frequently Asked Questions</H1>
  11. <HR CLASS="banner">
  12. <!-- End Banner -->
  13. <DL class="page-index" style="margin-top:1em">
  14. <DT><A href="#flush">Why is data I've written to a <CODE>filtering_stream</CODE> not reaching the Sink at the end of the chain?</A></DT>
  15. <DT><A href="#tee">How do I write to several ostreams at once?</A></DT>
  16. <DT><A href="#component_access">How do I access a Filter or Device after I've added it to a chain or attached it to a <CODE>stream</CODE> or <CODE>stream_buffer?</CODE></A></DT>
  17. <DT><A href="#offsets">How do perform file positioning operations with large (64-bit) offsets?</A></DT>
  18. <DT><A href="#stl">How do I read from or write to an STL sequence?</A></DT>
  19. <DT><A href="#multibyte">How do I write a stream which can read or write multibyte character encodings?</A></DT>
  20. <DT><A href="#auto_close">Can I swap Filters or Devices in the middle of a sequence of i/o operations?</CODE></A></DT>
  21. <DT><A href="#lifetime">Why does my filter chain work with <CODE>std::cout</CODE> but not with another <CODE>ostream</CODE>?</A></DT>
  22. <DT><A href="#pipe">Why do I get errors stating that <CODE>operator|</CODE> is ambiguous?</A></DT>
  23. <DT><A href="#finite_state">Why do I get errors when compiling the <CODE>finite_state_filter</CODE> examples?</A></DT>
  24. </DL>
  25. <HR style="margin-top:1em">
  26. <A NAME="flush"></A>
  27. <H4>Why is data I've written to a <CODE>filtering_stream</CODE> not reaching the Sink at the end of the chain?</H4>
  28. <P>
  29. You may need to flush the stream. Note, however, that there is no guarantee that all data written to a <A HREF="classes/filtering_stream.html"><CODE>filtering_stream</CODE></A> will be forwarded to the final Sink until the stream is closed, unless all the Filters in the underlying <A HREF="classes/chain.html"><CODE>chain</CODE></A> are <A HREF="concepts/flushable.html">Flushable</A>.
  30. </P>
  31. <P>
  32. It's also possible that a buggy Filter is modifying data in a way you don't expect, <I>e.g.</I>, by silently discarding data.
  33. </P>
  34. <A NAME="tee"></A>
  35. <H4>How do I write to several ostreams at once?</H4>
  36. <P>
  37. Use a <A HREF="functions/tee.html#tee_filter"><CODE>tee_filter</CODE></A> or <A HREF="functions/tee.html#tee_device"><CODE>tee_device</CODE></A>. <I>See</I> <A HREF="functions/tee.html"><CODE>tee</CODE></A>.
  38. </P>
  39. <A NAME="component_access"></A>
  40. <H4>How do I access a Filter or Device after I've added it to a chain or attached it to a <CODE>stream</CODE> or <CODE>stream_buffer?</CODE></H4>
  41. <P>
  42. If you're using a <A HREF="guide/generic_streams.html#stream"><CODE>stream</CODE></A> or <A HREF="guide/generic_streams.html#stream_buffer"><CODE>stream_buffer</CODE></A>, use <CODE>operator*</CODE> or <CODE>operator-&gt;</CODE>.
  43. </P>
  44. <P>
  45. If you're using a <A HREF="classes/filtering_stream.html"><CODE>filtering_stream</CODE></A>, <A HREF="classes/filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A> or <A HREF="classes/chain.html"><CODE>chain</CODE></A>, use the member function templates <A HREF="classes/chain.html#component_type"><CODE>component_type</CODE></A> and <A HREF="classes/chain.html#component"><CODE>component</CODE></A>. Alternatively, add your Filter or Device to the chain by reference, using a <A HREF="../../../doc/html/ref.html" TARGET="_top">reference wrapper</A>.
  46. </P>
  47. <A NAME="offsets"></A>
  48. <H4>How do perform file positioning operations with large (64-bit) offsets?</H4>
  49. <P>
  50. If you're using a raw Device and your compiler supports a 64-bit integral type, you can pass a large offset directly to <CODE>seek</CODE>. To convert the return value of seek to an integral type, use <A HREF="functions/positioning.html#position_to_offset"><CODE>position_to_offset</CODE></A>.
  51. </P>
  52. <P>
  53. If you're using a <A HREF="guide/generic_streams.html#stream_buffer"><CODE>stream_buffer</CODE></A> or <A HREF="classes/filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A>, convert the offset to a <CODE>std::streampos</CODE> using <A HREF="functions/positioning.html#offset_to_position"><CODE>offset_to_position</CODE></A>, then pass it to <CODE>pubseekpos</CODE>. To convert the return value of seek to an integral type, use <A HREF="functions/positioning.html#position_to_offset"><CODE>position_to_offset</CODE></A>.
  54. </P>
  55. <P>
  56. If you're using a <A HREF="guide/generic_streams.html#stream"><CODE>stream</CODE></A> or <A HREF="classes/filtering_stream.html"><CODE>filtering_stream</CODE></A>, convert the offset to a <CODE>std::streampos</CODE> using <A HREF="functions/positioning.html#offset_to_position"><CODE>offset_to_position</CODE></A>, then pass it to the overload of <CODE>seekg</CODE> or <CODE>seekp</CODE> which takes a single <CODE>std::streampos</CODE> argument. To convert the return value of seek to an integral type, use <A HREF="functions/positioning.html#position_to_offset"><CODE>position_to_offset</CODE></A>.
  57. </P>
  58. <P><I>See</I> <A HREF="functions/positioning.html">Stream Offsets</A>.</P>
  59. <A NAME="stl"></A>
  60. <H4>How do I read from or write to an STL sequence?</H4>
  61. <P>
  62. You can append to an STL sequence using a <A HREF="classes/back_inserter.html"><CODE>back_insert_device</CODE></A>, or the function <A HREF="classes/back_inserter.html#back_inserter"><CODE>boost::iostreams::back_inserter</CODE></A>. You can read from an STL sequence
  63. by adding an instance of <A HREF="../../range/doc/html/range/reference/utilities/iterator_range.html" TARGET="_top"><CODE>boost::itertator_range</CODE></A> to a <A HREF="classes/filtering_stream.html"><CODE>filtering_stream</CODE></A> or <A HREF="classes/filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A>.
  64. </P>
  65. <P><I>See</I> <A HREF="tutorial/container_source.html">Writing a <CODE>container_source</CODE></A> and <A HREF="tutorial/container_sink.html">Writing a <CODE>container_sink</CODE></A>.</P>
  66. <A NAME="multibyte"></A>
  67. <H4>How do I write a stream which can read or write multibyte character encodings?</H4>
  68. <P>
  69. Use a <A HREF="classes/code_converter.html"><CODE>code_converter</CODE></A>. <I>See</I> <A HREF="guide/code_conversion.html"><CODE>Code Conversion</CODE></A>.
  70. </P>
  71. <A NAME="auto_close"></A>
  72. <H4>Can I swap Filters or Devices in the middle of a sequence of i/o operations?</H4>
  73. <P>
  74. If you're performing output, and if all the Filters in you chain are <A HREF="concepts/flushable.html">Flushable</A>, then yes. First call <A HREF="classes/chain.html#strict_sync"><CODE>strict_sync</CODE></A>. If it returns <CODE>true</CODE>, you can safely call <CODE><A HREF="classes/chain.html#set_auto_close">set_auto_close</A>(false)</CODE> and <A HREF="classes/chain.html#pop"><CODE>pop</CODE></A> one or more components without closing the stream. This applies to instances of <A HREF="classes/filtering_stream.html"><CODE>filtering_stream</CODE></A>, <A HREF="classes/filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A> and <A HREF="classes/chain.html"><CODE>chain</CODE></A>.
  75. </P>
  76. <A NAME="lifetime"></A>
  77. <H4>Why does my filter chain work with <CODE>std::cout</CODE> but not with another <CODE>ostream</CODE>?</H4>
  78. <P>
  79. The Iostreams library stores streams and stream buffers by reference; consequently, streams and stream buffers must outlive any filter chain to which they are added. This is not a problem for <CODE>std::cout</CODE>, since it is guaranteed to live until the end of the program.
  80. </P>
  81. <P>
  82. Check to make sure that the <CODE>ostream</CODE> is not being destroyed before the <CODE>filtering_stream</CODE>. If both objects are constructed on the stack within the same block, make sure that the <CODE>ostream</CODE> is constructed <I>first</I>.
  83. </P>
  84. <A NAME="pipe"></A>
  85. <H4>Why do I get errors stating that <CODE>operator|</CODE> is ambiguous?</H4>
  86. <P>
  87. During overload resolution for an expression involving <CODE>operator|</CODE>, your compiler could be considering an implicit conversion from an intergral type to a <A HREF="concepts/pipable.html">Pipable</A> Filter. Make sure that all your Pipable Filters have <CODE>explicit</CODE> constructors. <I>See</I> <A HREF="guide/pipelines.html">Pipelines</A>.
  88. </P>
  89. <A NAME="finite_state"></A>
  90. <H4>Why do I get errors when compiling the <CODE>finite_state_filter</CODE> examples?</H4>
  91. <P>
  92. The template <CODE>finite_state_filter</CODE> requires a highly standard-conforming compiler. See <A HREF="portability.html">Portability</A> and the <A HREF="http://www.boost.org/status/compiler_status.html" TARGET="_top">Compiler Status Tables</A> for details.
  93. </P>
  94. <!-- Begin Footer -->
  95. <HR>
  96. <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>
  97. <P CLASS="copyright">
  98. 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>)
  99. </P>
  100. <!-- End Footer -->
  101. </BODY>