get.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Function Template get</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>get</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="#example">Example</A></DT>
  16. <DT><A href="#headers">Headers</A></DT>
  17. <DT><A href="#reference">Reference</A></DT>
  18. </DL>
  19. <A NAME="overview"></A>
  20. <H2>Overview</H2>
  21. <P>
  22. The function template <CODE>get</CODE> provides a uniform interface for reading a character from a <A HREF="../concepts/source.html">Source</A>, for use in the definitions of new <A HREF="../guide/concepts.html#filter_concepts">Filter</A> types (<I>see</I> <A HREF="#example">Example</A>).
  23. </P>
  24. <A NAME="example"></A>
  25. <H2>Example</H2>
  26. <P>
  27. The following code illustrates the use of the function <CODE>get</CODE> in the definition of an <A HREF="../concepts/input_filter.html">InputFilter</A>.
  28. </P>
  29. <PRE CLASS="broken_ie"> <SPAN CLASS="preprocessor">#include</SPAN> <SPAN CLASS="literal">&lt;ctype.h&gt;</SPAN> <SPAN CLASS="comment">// tolower</SPAN>
  30. <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/iostreams/concepts.hpp"><SPAN CLASS="literal">&lt;boost/iostreams/concepts.hpp&gt;</SPAN></A> <SPAN CLASS="comment">// input_filter</SPAN>
  31. <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/iostreams/operations.hpp"><SPAN CLASS="literal">&lt;boost/iostreams/operations.hpp&gt;</SPAN></A> <SPAN CLASS="comment">// get, EOF, WOULD_BLOCK</SPAN>
  32. <SPAN CLASS="keyword">using</SPAN> <SPAN CLASS="keyword">namespace</SPAN> std;
  33. <SPAN CLASS="keyword">using</SPAN> <SPAN CLASS="keyword">namespace</SPAN> boost::io;
  34. <SPAN CLASS="keyword">struct</SPAN> tolower_filter : <SPAN CLASS="keyword">public</SPAN> input_filter {
  35. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Source&gt;
  36. <SPAN CLASS="keyword">int</SPAN> get(Source&amp; src)
  37. {
  38. <SPAN CLASS="keyword">int</SPAN> c;
  39. <SPAN CLASS="keyword">return</SPAN> (c = boost::iostreams::get(src)) != <SPAN CLASS='numeric_literal'>EOF</SPAN> &amp;&amp;
  40. c != WOULD_BLOCK
  41. ?
  42. tolower((<SPAN CLASS="keyword">unsigned</SPAN> <SPAN CLASS="keyword">char</SPAN>) c) :
  43. c;
  44. }
  45. };</PRE>
  46. <A NAME="headers"></A>
  47. <H2>Headers</H2>
  48. <DL>
  49. <DT><A CLASS="header" HREF="../../../../boost/iostreams/get.hpp"><CODE>&lt;boost/iostreams/get.hpp&gt;</CODE></A></DT>
  50. <DT><A CLASS="header" HREF="../../../../boost/iostreams/operations.hpp"><CODE>&lt;boost/iostreams/operations.hpp&gt;</CODE></A></DT>
  51. </DL>
  52. <A NAME="reference"></A>
  53. <H2>Reference</H2>
  54. <A NAME="description"></A>
  55. <H4>Description</H4>
  56. <P>Attemps to extract a character from a given instance of the template parameter <CODE>Source</CODE>, returning the extracted character or one of the special values <CODE>traits_type::eof</CODE> or <A HREF="../classes/char_traits.html#would_block"><CODE>traits_type::would_block</CODE></A>, where <CODE>traits_type</CODE> is an appropriate specialization of <A HREF="../classes/char_traits.html"><CODE>boost::iostreams::char_traits</CODE></A></P>
  57. <A NAME="synopsis"></A>
  58. <H4>Synopsis</H4>
  59. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  60. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Source</A>&gt;
  61. <SPAN CLASS="keyword">typename</SPAN> <A CLASS='documented' HREF="../guide/traits.html#int_type_of_ref">int_type_of</A>&lt;Source&gt;::type
  62. <A CLASS="documented" HREF="#semantics">get</A>(<A CLASS="documented" HREF="#template_params">Source</A>&amp; <A CLASS="documented" HREF="#function_params">src</A>);
  63. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  64. <A NAME="template_params"></A>
  65. <H4>Template Parameters</H4>
  66. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  67. <TR>
  68. <TR>
  69. <TD VALIGN="top"><I>Source</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  70. <TD>A model of <A HREF="../concepts/source.html">Source</A>.
  71. </TR>
  72. </TABLE>
  73. <A NAME="function_params"></A>
  74. <H4>Function Parameters</H4>
  75. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  76. <TR>
  77. <TR>
  78. <TD VALIGN="top"><I>src</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  79. <TD>An instance of <CODE>Source</CODE></TD>
  80. </TR>
  81. </TABLE>
  82. <A NAME="semantics"></A>
  83. <H4>Semantics</H4>
  84. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Source&gt;
  85. <SPAN CLASS="keyword">typename</SPAN> int_type_of&lt;Source&gt;::type
  86. get(Source&amp; src);</PRE>
  87. <P>The semantics of <CODE>get</CODE> depends on the <A HREF="../guide/traits.html#category">category</A> of <CODE>Source</CODE> as follows:</P>
  88. <TABLE STYLE="margin:0,0,2em,2em" BORDER=1 CELLPADDING=4>
  89. <TR><TH><CODE>category_of&lt;Source&gt;::type</CODE></TH><TH>semantics</TH></TR>
  90. <TR>
  91. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>direct_tag</CODE></A></TD>
  92. <TD>compile-time error</CODE></TD>
  93. </TR>
  94. <TR>
  95. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>istream_tag</CODE></A></TD>
  96. <TD>returns <CODE>src.get()</CODE></TD>
  97. </TR>
  98. <TR>
  99. <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>
  100. <TD>returns <CODE>src.sbumpc()</CODE></TD>
  101. </TR>
  102. <TR>
  103. <TD VALIGN="top">otherwise</TD>
  104. <TD>
  105. attempts to extract a single character using <CODE>src.read()</CODE>, returning the extracted character if successful and one of the special values <CODE>traits_type::eof</CODE> or <A HREF="../classes/char_traits.html#would_block"><CODE>traits_type::would_block</CODE></A> otherwise, where <CODE>traits_type</CODE> is <A HREF="../classes/char_traits.html"><CODE>boost::iostreams::char_traits&lt;Source&gt;</CODE></A>
  106. </TD>
  107. </TR>
  108. </TABLE>
  109. <!-- Begin Footer -->
  110. <HR>
  111. <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>
  112. <P CLASS="copyright">
  113. 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>)
  114. </P>
  115. <!-- End Footer -->
  116. </BODY>