put.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Function Template put</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>put</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>put</CODE> provides a uniform interface for writing a character to a <A HREF="../concepts/sink.html">Sink</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>put</CODE> in the definition of an <A HREF="../concepts/output_filter.html">OutputFilter</A>.
  28. </P>
  29. <PRE CLASS="broken_ie"> <SPAN CLASS="preprocessor">#include</SPAN> <SPAN CLASS="literal">&lt;ctype.h&gt;</SPAN> <SPAN CLASS="comment">// toupper</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">// output_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">// put</SPAN>
  32. <SPAN CLASS="keyword">using</SPAN> <SPAN CLASS="keyword">namespace</SPAN> std;
  33. <SPAN CLASS="keyword">namespace</SPAN> io = boost::iostreams;
  34. <SPAN CLASS="keyword">struct</SPAN> toupper_filter : <SPAN CLASS="keyword">public</SPAN> io::output_filter {
  35. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Sink&gt;
  36. <SPAN CLASS="keyword">bool</SPAN> put(Sink&amp; snk, <SPAN CLASS="keyword">char</SPAN> c)
  37. {
  38. <SPAN CLASS="keyword">return</SPAN> io::put(snk, toupper((<SPAN CLASS="keyword">unsigned</SPAN> <SPAN CLASS="keyword">char</SPAN>) c));
  39. }
  40. };</PRE>
  41. <A NAME="headers"></A>
  42. <H2>Headers</H2>
  43. <DL>
  44. <DT><A CLASS="header" HREF="../../../../boost/iostreams/operations.hpp"><CODE>&lt;boost/iostreams/operations.hpp&gt;</CODE></A></DT>
  45. <DT><A CLASS="header" HREF="../../../../boost/iostreams/put.hpp"><CODE>&lt;boost/iostreams/put.hpp&gt;</CODE></A></DT>
  46. </DL>
  47. <A NAME="reference"></A>
  48. <H2>Reference</H2>
  49. <A NAME="description"></A>
  50. <H4>Description</H4>
  51. <P>Attempts to write a character to a given instance of the template parameter <CODE>Sink</CODE>, returning <CODE>true</CODE> for success.</P>
  52. <A NAME="synopsis"></A>
  53. <H4>Synopsis</H4>
  54. <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
  55. <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Sink</A>&gt;
  56. <SPAN CLASS="keyword">void</SPAN> put(Sink&amp; <A CLASS="documented" HREF="#function_params">snk</A>, <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="../guide/traits.html#char_type_of_ref">char_type_of</A>&lt;Sink&gt;::type c);
  57. } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
  58. <A NAME="template_params"></A>
  59. <H4>Template Parameters</H4>
  60. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  61. <TR>
  62. <TR>
  63. <TD VALIGN="top"><I>Sink</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  64. <TD>A <A HREF="../concepts/direct.html">indirect</A> model of <A HREF="../concepts/sink.html">Sink</A> or a standard output stream or stream buffer type.
  65. </TR>
  66. </TABLE>
  67. <A NAME="function_params"></A>
  68. <H4>Function Parameters</H4>
  69. <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
  70. <TR>
  71. <TR>
  72. <TD VALIGN="top"><I>snk</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
  73. <TD>An instance of <CODE>Sink</CODE></TD>
  74. </TR>
  75. </TABLE>
  76. <A NAME="semantics"></A>
  77. <H4>Semantics</H4>
  78. <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Sink&gt;
  79. <SPAN CLASS="keyword">void</SPAN> put(Sink&amp; snk, <SPAN CLASS="keyword">typename</SPAN> char_type_of&lt;Sink&gt;::type c);</PRE>
  80. <P>The semantics of <CODE>put</CODE> depends on the <A HREF="../guide/traits.html#category">category</A> of <CODE>Sink</CODE> as follows:</P>
  81. <TABLE STYLE="margin:0,0,2em,2em" BORDER=1 CELLPADDING=4>
  82. <TR><TH><CODE>category_of&lt;Sink&gt;::type</CODE></TH><TH>semantics</TH></TR>
  83. <TR>
  84. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>direct_tag</CODE></A></TD>
  85. <TD>compile-time error</CODE></TD>
  86. </TR>
  87. <TR>
  88. <TD VALIGN="top">convertible to <A HREF="../guide/traits.html#category_tags"><CODE>ostream_tag</CODE></A></TD>
  89. <TD>invokes <CODE>snk.put(c)</CODE></TD>
  90. </TR>
  91. <TR>
  92. <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>ostream_tag</CODE></A></TD>
  93. <TD>invokes <CODE>snk.sputc(c)</CODE></TD>
  94. </TR>
  95. <TR>
  96. <TD VALIGN="top">otherwise</TD>
  97. <TD>invokes <CODE>snk.write(&amp;c, 1)</CODE></TD>
  98. </TR>
  99. </TABLE>
  100. <!-- Begin Footer -->
  101. <HR>
  102. <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>
  103. <P CLASS="copyright">
  104. 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>)
  105. </P>
  106. <!-- End Footer -->
  107. </BODY>