modes.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Modes</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">User's Guide</H1>
  11. <HR CLASS="banner">
  12. <!-- End Banner -->
  13. <!-- Begin Nav -->
  14. <DIV CLASS='nav'>
  15. <A HREF='concepts.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/prev.png'></A>
  16. <A HREF='guide.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/up.png'></A>
  17. <A HREF='generic_streams.html'><IMG BORDER=0 WIDTH=19 HEIGHT=19 SRC='../../../../doc/src/images/next.png'></A>
  18. </DIV>
  19. <!-- End Nav -->
  20. <H2>3.2 Modes</H2>
  21. <DL class="page-index">
  22. <DT><A href="#overview">Overview</A></DT>
  23. <DT><A href="#definitions">Definitions of the Modes</A></DT>
  24. <DT><A href="#mode_hierarchy_diagrams">Mode Hierarchy Diagrams</A></DT>
  25. <DT><A href="#mode_tags">Mode Tags</A></DT>
  26. <DT><A href="#the_metafunction_mode">The metafunction <CODE>mode_of</CODE></A></DT>
  27. </DL>
  28. <HR STYLE="margin-top:1em">
  29. <A NAME="overview"></A>
  30. <H2>Overview</H2>
  31. <P>
  32. In order for a sequence of <A HREF="concepts.html#filter_concepts">Filters</A> and <A HREF="concepts.html#device_concepts">Devices</A> to work together they must have certain properties in common. The most basic requirement is that they have the same <A HREF="traits.html#char_type">character type</A>; a collection of additional properties which Filters and Devices must share to be used for a particular purpose is called a <SPAN CLASS="term">mode</SPAN>.
  33. </P>
  34. <P>
  35. The templates <A HREF="generic_streams.html#stream_buffer"><CODE>stream_buffer</CODE></A> and <A HREF="generic_streams.html#stream"><CODE>stream</CODE></A> are each parameterized by a mode, represented by a <A HREF="#mode_tags">mode tag</A>.
  36. </P>
  37. <P>
  38. The Iostreams library supports eight modes, described in the next section (<I>see also</I> <A CLASS="caption_ref" HREF="#mode_hierarchy_diagrams">Figure 2</A>). Of these, four are most import (<I>see </I> <A CLASS="caption_ref" HREF="#mode_hierarchy_diagrams">Figure 1</A>). The two modes <A HREF="#input">input</A> and <A HREF="#output">output</A> are by far the most common. Readers new to the Iostreams library should feel free to concentrate primarily on these two modes.
  39. </P>
  40. <A NAME="definitions"></A>
  41. <H2>Definitions of the Modes</H2>
  42. <P>Modes can be categorized in several ways:
  43. <UL>
  44. <LI>Whether input, output or both input and output can be performed.
  45. <LI>If both input and output are possible, whether there are two separate character sequences for input and output, or a single combined sequence.
  46. <LI>Whether the reading or writing heads are repositionable, and if so, whether there are separate heads for reading and writing or a single read/write head.
  47. </UL>
  48. <P>
  49. The concepts representing <A HREF="concepts.html#optional_behavior">optional behavior</A> are not related to mode, and so need not be shared in order for a collection of Filters and Devices to work together:
  50. </P>
  51. <P>Modes are summarized in the following table:</P>
  52. <TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
  53. <TR><TH>Mode</TH><TH>Definition/Examples</TH></TR>
  54. <!-- Input -->
  55. <TR>
  56. <TD VALIGN="top"><A NAME="input"></A><B>Input</B></TD>
  57. <TD>
  58. <TABLE>
  59. <TR><TD VALIGN="top"><B>Definition:</B></TD><TD>Involves a single sequence of characters, for input</TD></TR>
  60. <TR><TD VALIGN="top"><B>Example:</B></TD><TD><CODE>std::cin</CODE></TD></TR>
  61. </TABLE>
  62. </TD>
  63. </TR>
  64. <!-- Output -->
  65. <TR>
  66. <TD VALIGN="top"><A NAME="output"></A><B>Output</B></TD>
  67. <TD>
  68. <TABLE>
  69. <TR><TD VALIGN="top"><B>Definition:</B></TD><TD>Involves a single sequence of characters, for output</TD></TR>
  70. <TR><TD VALIGN="top"><B>Example:</B></TD><TD><CODE>std::cout</CODE></TD></TR>
  71. </TABLE>
  72. </TD>
  73. </TR>
  74. <!-- Bidirectional -->
  75. <TR>
  76. <TD VALIGN="top"><A NAME="bidirectional"></A><B>Bidirectional</B></TD>
  77. <TD>
  78. <TABLE>
  79. <TR><TD VALIGN="top"><B>Definition:</B></TD>
  80. <TD>Involves a two separate sequences of characters, one for input and one for output</TD></TR>
  81. <TR><TD VALIGN="top"><B>Example:</B></TD><TD>A <CODE>std::iostream</CODE> for accessing a TCP connection</TD></TR>
  82. </TABLE>
  83. </TD>
  84. </TR>
  85. <!-- Input-seekable -->
  86. <TR>
  87. <TD VALIGN="top"><A NAME="input_seekable"></A><B>Input-seekable</B></TD>
  88. <TD>
  89. <TABLE>
  90. <TR><TD VALIGN="top"><B>Definition:</B></TD>
  91. <TD>Involves a single sequence of characters, for input, with a repositionable reading head</TD></TR>
  92. <TR><TD VALIGN="top"><B>Examples:</B></TD><TD><CODE>std::ifstream</CODE>, <CODE>std::istringstream</CODE></TD></TR>
  93. </TABLE>
  94. </TD>
  95. </TR>
  96. <!-- Output-seekable -->
  97. <TR>
  98. <TD VALIGN="top"><A NAME="output_seekable"></A><B><PRE CLASS="plain_code"><P>Output-seekable</P></PRE></B></TD>
  99. <TD>
  100. <TABLE>
  101. <TR><TD VALIGN="top"><B>Definition:</B></TD>
  102. <TD>Involves a single sequence of characters, for output, with a repositionable writing head</TD></TR>
  103. <TR><TD VALIGN="top"><B>Examples:</B></TD><TD><CODE>std::ofstream</CODE>, <CODE>std::ostringstream</CODE></TD></TR>
  104. </TABLE>
  105. </TD>
  106. </TR>
  107. <!-- Seekable -->
  108. <TR>
  109. <TD VALIGN="top"><A NAME="seekable"></A><B>Seekable</B></TD>
  110. <TD>
  111. <TABLE>
  112. <TR><TD VALIGN="top"><B>Definition:</B></TD>
  113. <TD>Involves a single sequence of characters, for input and output, with a combined repositionable read/write head</TD></TR>
  114. <TR><TD VALIGN="top"><B>Example:</B></TD><TD><CODE>std::fstream</CODE></TD></TR>
  115. </TABLE>
  116. </TD>
  117. </TR>
  118. <!-- Dual-seekable -->
  119. <TR>
  120. <TD VALIGN="top"><A NAME="dual_seekable"></A><B>Dual-seekable</B></TD>
  121. <TD>
  122. <TABLE>
  123. <TR><TD VALIGN="top"><B>Definition:</B></TD>
  124. <TD>Involves a single sequence of characters, for input and output, with separate repositionable reading and writing heads</TD></TR>
  125. <TR><TD VALIGN="top"><B>Example:</B></TD><TD><CODE>std::stringstream</CODE></TD></TR>
  126. </TABLE>
  127. </TD>
  128. </TR>
  129. <!-- Bidirectional-seekable -->
  130. <TR>
  131. <TD VALIGN="top"><A NAME="bidirectional_seekable"></A><B>Bidirectional-seekable</B></TD>
  132. <TD>
  133. <TABLE>
  134. <TR><TD VALIGN="top"><B>Definition:</B></TD><TD>Involves a two separate sequences of characters, one for input and one for output, each with a repositionable head</TD></TR>
  135. <TR><TD VALIGN="top"><B>Example:</B></TD><TD>No known examples</TD></TR>
  136. </TABLE>
  137. </TD>
  138. </TR>
  139. </TR>
  140. </TABLE>
  141. <P>
  142. For more on the selection of modes, see the <A href="../rationale.html">Rationale</A>.
  143. </P>
  144. <A ID="mode_hierchy_diagrams"></A>
  145. <H2 ID="mode_hierarchy_diagrams">Mode Hierarchy Diagrams</H2>
  146. <P>The following diagrams display the refinement hierarchies among modes.</P>
  147. <TABLE STYLE="margin-left:2em" CELLSPACING=10>
  148. <TR>
  149. <TD VALIGN="top">
  150. <P CLASS="caption"><B>Figure 1.</B> The four most important modes</P>
  151. <IMG SRC="../graphics/important_modes.gif">
  152. </TD>
  153. <TD WIDTH="30"></TD>
  154. <TD ALIGN="right" VALIGN="top">
  155. <TABLE>
  156. <TR><TD><IMG SRC="../graphics/key_important.gif"></TD><TD CLASS="caption">Most important</TD></TR>
  157. <TR><TD><IMG SRC="../graphics/key_input_seq.gif"></TD><TD CLASS="caption">Input sequence</TD></TR>
  158. <TR><TD><IMG SRC="../graphics/key_output_seq.gif"></TD><TD CLASS="caption">Output sequence</TD></TR>
  159. <TR><TD><IMG SRC="../graphics/key_bidirectional_seq.gif"></TD><TD CLASS="caption">Combined input-output sequence</TD></TR>
  160. <TR><TD><IMG SRC="../graphics/key_read_head.gif"></TD><TD CLASS="caption">Repositionable file-pointer for reading</TD></TR>
  161. <TR><TD><IMG SRC="../graphics/key_write_head.gif"></TD><TD CLASS="caption">Repositionable file-pointer for writing</TD></TR>
  162. <TR><TD><IMG SRC="../graphics/key_read_write_head.gif"></TD><TD CLASS="caption">Combined file-pointer for reading and writing</TD></TR>
  163. </TABLE>
  164. </TD>
  165. </TR>
  166. <TR>
  167. <TD COLSPAN="3">
  168. <P CLASS="caption"><B>Figure 2.</B> The complete hierarchy of modes</P>
  169. <IMG SRC="../graphics/modes.gif">
  170. </TD>
  171. </TR>
  172. </TABLE>
  173. <A NAME="mode_tags"></A>
  174. <H2>Mode Tags</H2>
  175. <P>
  176. Each mode is represented by a <SPAN CLASS="term">mode tag</SPAN>, defined in the header <A href="../../../../boost/iostreams/traits.hpp"><CODE>&lt;boost/iostreams/traits.hpp&gt;</CODE></A>. There are eight tags for the eight modes: <CODE>input</CODE>, <CODE>output</CODE>, <CODE>bidirectional</CODE>, <CODE>input_seekable</CODE>, <CODE>output_seekable</CODE>, <CODE>seekable</CODE>, <CODE>dual_seekable</CODE> and <CODE>bidirectional_seekable</CODE>.<SUP><A CLASS="footnote_ref" NAME="note_1_ref" HREF="#note_1">[1]</A></SUP> As with standard library iterator category tags, the tag corresponding to a mode is convertible to each of the tags corresponding to modes which the first mode refines.
  177. </P>
  178. <P>
  179. In addition, there is a <SPAN CLASS="term">pseudo-mode tag</SPAN> <CODE>dual_use</CODE>, which is used to define <A href="../concepts/dual_use_filter.html">DualUseFilters</A> &#8212; which can perform input or output, but not both simultaneously. This is useful to help reduce the number of different of Filter types. The <A href="../classes/regex_filter.html">Regular Expression Filters</A>, <A href="../classes/newline_filter.html">Newline Filters</A> and compression and decompression filters all have mode <CODE>dual_use</CODE> so that they may be used with either input or output streams.
  180. </P>
  181. <A NAME="the_metafunction_mode"></A>
  182. <H2>The Metafunction <CODE>mode_of</CODE></H2>
  183. <P>
  184. To determine the mode of a model of a Filter or Device, use the metafunction <A href="../classes/mode.html"><CODE>mode_of</CODE></A>.
  185. </P>
  186. <!-- Begin Footnotes -->
  187. <HR>
  188. <P>
  189. <SUP><A CLASS="footnote_ref" NAME="note_1" HREF="#note_1_ref">[1]</A></SUP>It is traditional for tag structures to have names ending with "<CODE>_tag</CODE>". Since mode tags feature prominently in user code, this suffix was dropped to improve readability.
  190. </P>
  191. <!-- End Footnotes -->
  192. <!-- Begin Footer -->
  193. <HR>
  194. <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>
  195. <P CLASS="copyright">
  196. 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>)
  197. </P>
  198. <!-- End Footer -->
  199. </BODY>