traits.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>I/O Traits and Categories</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">I/O Traits and Categories</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="#char_type_of_ref">Class template <CODE>char_type_of</CODE></A></DT>
  17. <DT><A href="#int_type_of_ref">Class template <CODE>int_type_of</CODE></A></DT>
  18. <DT><A href="#category_ref">Class template <CODE>category_of</CODE></A></DT>
  19. <DT><A href="#category_tags">Category Tags</A></DT>
  20. </DT>
  21. </DL>
  22. <HR>
  23. <A NAME="overview"></A>
  24. <H2>Overview</H2>
  25. <P>
  26. The header <A CLASS="header" href="../../../../boost/iostreams/categories.hpp"><CODE>&lt;boost/iostreams/categories.hpp&gt;</CODE></A> contains <A href="#category_tags">category tags</A> for classifying models of the various <A href="concepts.html#filter_concepts">Filter</A> and <A href="concepts.html#device_concepts">Device</A> concepts. The header <A CLASS="header" href="../../../../boost/iostreams/traits.hpp"><CODE>&lt;boost/iostreams/traits.hpp&gt;</CODE></A> contains the definitions of the metafunctions <A HREF="#char_type_of_ref"><CODE>char_type_of</CODE></A> and <A HREF="#category_ref"><CODE>category</CODE></A>, used to associate two fundamental types with each model of one the <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> concepts:
  27. </P>
  28. <A NAME="char_type"></A>
  29. <H4>Character Type</H4>
  30. <P>The type of characters which a Filter or Device reads or writes.</P>
  31. <A NAME="category"></A>
  32. <H4>Category</H4>
  33. <P>
  34. A tag structure which the Iostreams library relies on to determine which operations a Filter or Device supports. It indicates, for a given type <CODE>T</CODE>:
  35. </P>
  36. <UL>
  37. <LI CLASS="square">whether <CODE>T</CODE> is a <A href="concepts.html#filter_concepts">Filter</A> or a <A href="concepts.html#device_concepts">Device</A>
  38. <LI CLASS="square">the <A href="modes.html">mode</A> of <CODE>T</CODE>
  39. <LI CLASS="square">any <A href="concepts.html#optional_behavior">optional_behavior</A> <CODE>T</CODE> implements
  40. </UL>
  41. <P>
  42. 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> Types which serve as categories are called <A HREF="#category_tags">category tags</A>.
  43. </P>
  44. <A NAME="headers"></A>
  45. <H2>Headers</H2>
  46. <DL class="page-index">
  47. <DT><A CLASS="header" href="../../../../boost/iostreams/categories.hpp"><CODE>&lt;boost/iostreams/categories.hpp&gt;</CODE></A></DT>
  48. <DT><A CLASS="header" href="../../../../boost/iostreams/traits.hpp"><CODE>&lt;boost/iostreams/traits.hpp&gt;</CODE></A></DT>
  49. </DL>
  50. <A NAME="char_type_of_ref"></A>
  51. <H2>Class Template <CODE>char_type_of</CODE></H2>
  52. <H4>Description</H4>
  53. <P><A HREF="http://www.boost.org/libs/mpl/doc/refmanual/metafunction.html" TARGET="_top">Metafunction</A> associating a <A HREF="#char_type">character type</A> to each <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> type. Although <CODE>char_type_of</CODE> is designed to be specialized for new Filter and Device types, the default implementation should be suitable for most purposes.
  54. <H4>Synopsis</H4>
  55. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  56. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A HREF="#char_type_template_params" CLASS="documented">T</A>&gt;
  57. <SPAN CLASS="keyword">struct</SPAN> <A CLASS="documented" HREF="#char_type_template_params">char_type_of</A> {
  58. <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">see below</SPAN> <A HREF="#char_type_of_type" CLASS="documented">type</A>;
  59. };
  60. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  61. <A NAME="char_type_template_params"></A>
  62. <H4>Template parameters</H4>
  63. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  64. <TR>
  65. <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  66. <TD>A model of one of the <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> concepts</TD>
  67. </TR>
  68. </TABLE>
  69. <A NAME="char_type_of_type"></A>
  70. <H4><CODE>io_traits::type</CODE></H4>
  71. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">see below</SPAN> char_type;</PRE>
  72. <P>The value of the nested type <CODE>type</CODE> depends on the template parameter <CODE>T</CODE> as follows:</P>
  73. <TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
  74. <TR><TH><CODE>T</CODE></TH><TH><CODE>char_type</CODE></TH></TR>
  75. <TR>
  76. <TD VALIGN="top">Sepcialization of <CODE>std::back_insert_iterator</CODE></TD>
  77. <TD>The <CODE>value_type</CODE> of the iterator's <CODE>container_type</CODE></TD>
  78. </TR>
  79. <TR>
  80. <TD VALIGN="top">All other types</TD>
  81. <TD><CODE>T::char_type</CODE></TD>
  82. </TR>
  83. </TABLE>
  84. <A NAME="int_type_of_ref"></A>
  85. <H2>Class Template <CODE>int_type_of</CODE></H2>
  86. <H4>Description</H4>
  87. <P><A HREF="http://www.boost.org/libs/mpl/doc/refmanual/metafunction.html" TARGET="_top">Metafunction</A> associating an integral type to each <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> type. Although <CODE>int_type_of</CODE> is designed to be specialized for new Filter and Device types, the default implementation should be suitable for most purposes.
  88. <H4>Synopsis</H4>
  89. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  90. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A HREF="#int_type_template_params" CLASS="documented">T</A>&gt;
  91. <SPAN CLASS="keyword">struct</SPAN> <A CLASS="documented" HREF="#int_type_template_params">int_type_of</A> {
  92. <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">see below</SPAN> <A HREF="#int_type_of_type" CLASS="documented">type</A>;
  93. };
  94. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  95. <A NAME="int_type_template_params"></A>
  96. <H4>Template parameters</H4>
  97. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  98. <TR>
  99. <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  100. <TD>A model of one of the <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> concepts</TD>
  101. </TR>
  102. </TABLE>
  103. <A NAME="int_type_of_type"></A>
  104. <H4><CODE>io_traits::type</CODE></H4>
  105. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">see below</SPAN> char_type;</PRE>
  106. <P>Equal to <CODE>std::char_traits&lt;char_type&gt;::int_type</CODE>, where <CODE>char_type</CODE> is <A HREF="#char_type_of_ref"><CODE>char_type_of&lt;T&gt;::type</CODE></A>.
  107. <A NAME="category_ref"></A>
  108. <H2>Class Template <CODE>category_of</CODE></H2>
  109. <H4>Description</H4>
  110. <P><A HREF="http://www.boost.org/libs/mpl/doc/refmanual/metafunction.html" TARGET="_top">Metafunction</A> associating a <A HREF="#category_tags">category tag</A> to each <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> type. Although <CODE>category</CODE> is designed to be specialized for new Filter and Device types, the default implementation should be suitable for most purposes.
  111. <H4>Synopsis</H4>
  112. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  113. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A HREF="#category_template_params" CLASS="documented">T</A>&gt;
  114. <SPAN CLASS="keyword">struct</SPAN> <A CLASS="documented" HREF="#category_template_params">category_of</A> {
  115. <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">see below</SPAN> <A HREF="#category_type" CLASS="documented">type</A>;
  116. };
  117. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  118. <A NAME="category_template_params"></A>
  119. <H4>Template parameters</H4>
  120. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  121. <TR>
  122. <TD VALIGN="top"><I>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  123. <TD>A model of one of the <A href="concepts.html#filter_concepts">Filter</A> or <A href="concepts.html#device_concepts">Device</A> concepts</TD>
  124. </TR>
  125. </TABLE>
  126. <A NAME="category_type"></A>
  127. <H4><CODE>category::type</CODE></H4>
  128. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">see below</SPAN> type;</PRE>
  129. <P>The value of the nested type <CODE>type</CODE> depends on the template parameter <CODE>T</CODE> as follows:</P>
  130. <TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
  131. <TR><TH><CODE>T</CODE></TH><TH><CODE>category</CODE></TH></TR>
  132. <TR>
  133. <TD VALIGN="top">Specialization of <CODE>std::basic_iostream</CODE>, or derived from such a specialization</TD>
  134. <TD><CODE>iostream_tag</CODE></TD>
  135. </TR>
  136. <TR>
  137. <TD VALIGN="top">Specialization of <CODE>std::basic_istream</CODE>, or derived from such a specialization</TD>
  138. <TD><CODE>istream_tag</CODE></TD>
  139. </TR>
  140. <TR>
  141. <TD VALIGN="top">Specialization of <CODE>std::basic_ostream</CODE>, or derived from such a specialization</TD>
  142. <TD><CODE>ostream_tag</CODE></TD>
  143. </TR>
  144. <TR>
  145. <TD VALIGN="top">Specialization of <CODE>std::basic_streambuf</CODE>, or derived from such a specialization</TD>
  146. <TD><CODE>streambuf_tag</CODE></TD>
  147. </TR>
  148. <TR>
  149. <TD VALIGN="top">Specialization of <CODE>std::back_insert_iterator</CODE>, or derived from such a specialization</TD>
  150. <TD><CODE>insert_iterator_tag</CODE></TD>
  151. </TR>
  152. <TR>
  153. <TD VALIGN="top">All other types</TD>
  154. <TD><CODE>T::category</CODE></TD>
  155. </TR>
  156. </TABLE>
  157. <P>For more information, see <A CLASS="header" href="../../../../boost/iostreams/traits.hpp"><CODE>&lt;boost/iostreams/traits.hpp&gt;</CODE></A>.</P>
  158. <A NAME="category_tags"></A>
  159. <H2>Category Tags</H2>
  160. <P>
  161. In addition to the various <A href="modes.html#mode_tags">mode tags</A>, the header <A CLASS="header" href="../../../../boost/iostreams/categories.hpp"><CODE>&lt;boost/iostreams/categories.hpp&gt;</CODE></A> provides the category tags shown in the following table. To produce a new category tag which combines several existing tags, simply define a <CODE>struct</CODE> extending the existing tags. <I>E.g.</I>,
  162. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">struct</SPAN> category
  163. : seekable,
  164. filter_tag,
  165. localizable_tag
  166. { };</PRE>
  167. This defines a category tag representing <A href="modes.html#seekable">Seekable</A>, <A href="../concepts/localizable.html">Localizable</A> <A href="../concepts/filter.html">Filters</A>.
  168. </P>
  169. <TABLE STYLE="margin-left:2em;margin-bottom:2em" BORDER="1" CELLPADDING="6">
  170. <TR><TH>Tag</TH><TH>Description</TH></TR>
  171. <TR>
  172. <TD VALIGN="top"><CODE>filter_tag</CODE></TD>
  173. <TD>Indicates that a type models <A href="../concepts/filter.html">Filter</A></TD>
  174. </TR>
  175. <TR>
  176. <TD VALIGN="top"><CODE>device_tag</CODE></TD>
  177. <TD>Indicates that a type models <A href="../concepts/device.html">Device</A></TD>
  178. </TR>
  179. <TR>
  180. <TD VALIGN="top">
  181. <CODE>closable_tag</CODE><BR><CODE>localizable_tag</CODE><BR>
  182. <CODE>direct_tag</CODE><BR><CODE>peekable_tag</CODE><BR>
  183. <CODE>multichar_tag</CODE>
  184. </TD>
  185. <TD>
  186. Used to indicate <A href="concepts.html#optional_behavior">optional behavior</A> implemented by a Filter or Device type
  187. </TD>
  188. </TR>
  189. <TR>
  190. <TD VALIGN="top">
  191. <CODE>source_tag</CODE><BR>
  192. <CODE>sink_tag</CODE><BR>
  193. <CODE>bidirectional_device_tag</CODE><BR>
  194. <CODE>seekable_device_tag</CODE><BR>
  195. <CODE>input_filter_tag</CODE><BR>
  196. <CODE>output_filter_tag</CODE><BR>
  197. <CODE>bidirectional_filter_tag</CODE><BR>
  198. <CODE>seekable_filter_tag</CODE><BR>
  199. <CODE>multichar_input_filter_tag</CODE><BR>
  200. <CODE>multichar_output_filter_tag</CODE><BR>
  201. <CODE>multichar_bidirectional_filter_tag</CODE><BR>
  202. <CODE>multichar_seekable_filter_tag</CODE>
  203. </TD>
  204. <TD>
  205. Convenience tags for defining models of the various <A href="../concepts/filter.html">Filter</A> and <A href="../concepts/device.html">Device</A> refinements
  206. </TD>
  207. </TR>
  208. <TR>
  209. <TD VALIGN="top">
  210. <CODE>istream_tag</CODE><BR>
  211. <CODE>ostream_tag</CODE><BR>
  212. <CODE>iostream_tag</CODE><BR>
  213. <CODE>streambuf_tag</CODE>
  214. </TD>
  215. <TD>
  216. Used internally to distinguish standard stream and stream buffer types
  217. </TD>
  218. </TR>
  219. <TR>
  220. <TD VALIGN="top"><CODE>insert_iterator_tag</CODE></TD>
  221. <TD>Used internally to distinguish specialization of <CODE>std::back_insert_iterator</CODE></TD>
  222. </TR>
  223. </TABLE>
  224. <!-- Begin Footnotes -->
  225. <HR>
  226. <P>
  227. <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.
  228. </P>
  229. <!-- End Footnotes -->
  230. <!-- Begin Footer -->
  231. <HR>
  232. <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>
  233. <P CLASS="copyright">
  234. Use modification and distribution are subject to the Boost Software License Version 1.0. (See accompanying file <A href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)
  235. </P>
  236. <!-- End Footer -->
  237. </BODY>