mirror of
https://github.com/boostorg/iostreams.git
synced 2026-02-22 15:32:20 +00:00
141 lines
6.0 KiB
HTML
Executable File
141 lines
6.0 KiB
HTML
Executable File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>Function Template putback</TITLE>
|
|
<LINK REL='stylesheet' HREF='../../../../boost.css'>
|
|
<LINK REL='stylesheet' HREF='../theme/iostreams.css'>
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<!-- Begin Banner -->
|
|
|
|
<H1 CLASS='title'>Function Template <CODE>putback</CODE></H1>
|
|
<HR CLASS='banner'>
|
|
|
|
<!-- End Banner -->
|
|
|
|
<DL class='page-index'>
|
|
<DT><A href='#overview'>Overview</A></DT>
|
|
<!-- <DT><A href='#example'>Example</A></DT> -->
|
|
<DT><A href='#headers'>Headers</A></DT>
|
|
<DT><A href='#reference'>Reference</A></DT>
|
|
</DL>
|
|
|
|
<A NAME='overview'>
|
|
<H2>Overview</H2>
|
|
|
|
<P>
|
|
The function template <CODE>put</CODE> provides a uniform interface for putting back characters read from models of <A HREF='../concepts/peekable.html'>Peekable</A>, for use in the definitions of new <A HREF='../concepts.html#filter_concepts'>Filter</A> types<!-- (<I>see</I> <A HREF='#example'>Example</A>) -->.
|
|
</P>
|
|
|
|
<!-- Example doesn't handle EOF properly -->
|
|
<!-- <A NAME='example'>
|
|
<H2>Example</H2>
|
|
|
|
<P>
|
|
The following code illustrates the use of the function <CODE>putback</CODE> in the definition of an <A HREF='../concepts/output_filter.html'>InputFilter</A>.
|
|
</P>
|
|
|
|
<PRE CLASS='broken_ie'> <SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/concepts.hpp'><SPAN CLASS='literal'><boost/iostreams/concepts.hpp></SPAN></A> <SPAN CLASS='comment'>// input_filter</SPAN>
|
|
<SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/operations.hpp'><SPAN CLASS='literal'><boost/iostreams/operations.hpp></SPAN></A> <SPAN CLASS='comment'>// get, putback</SPAN>
|
|
|
|
<SPAN CLASS="keyword">using</SPAN> <SPAN CLASS="keyword">namespace</SPAN> std;
|
|
<SPAN CLASS="keyword">using</SPAN> <SPAN CLASS="keyword">namespace</SPAN> boost::io;
|
|
|
|
<SPAN CLASS="keyword">struct</SPAN> skip_CRLF_filter : <SPAN CLASS="keyword">public</SPAN> input_filter {
|
|
<SPAN CLASS="keyword">static</SPAN> <SPAN CLASS="keyword">const</SPAN> <SPAN CLASS="keyword">char</SPAN> CR = <SPAN CLASS='numeric_literal'>0x0D</SPAN>;
|
|
<SPAN CLASS="keyword">static</SPAN> <SPAN CLASS="keyword">const</SPAN> <SPAN CLASS="keyword">char</SPAN> LF = <SPAN CLASS='numeric_literal'>0x0A</SPAN>;
|
|
|
|
<SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> Source>
|
|
<SPAN CLASS="keyword">streamsize</SPAN> get(Source& src)
|
|
{
|
|
<SPAN CLASS="keyword">int</SPAN> c;
|
|
<SPAN CLASS="keyword">while</SPAN> ((c = boost::iostreams::get(src)) == CR) {
|
|
<SPAN CLASS="keyword">int</SPAN> d;
|
|
<SPAN CLASS="keyword">if</SPAN> ((d = boost::iostreams::get(src)) != LF) {
|
|
boost::iostreams::putback(d);
|
|
<SPAN CLASS="keyword">return</SPAN> CR;
|
|
}
|
|
}
|
|
<SPAN CLASS="keyword">return</SPAN> c;
|
|
}
|
|
};</PRE> -->
|
|
|
|
<A NAME='headers'>
|
|
<H2>Headers</H2>
|
|
|
|
<DL>
|
|
<DT><A CLASS='header' HREF='../../../../boost/iostreams/operations.hpp'><CODE><boost/iostreams/operations.hpp></CODE></A></DT>
|
|
</DL>
|
|
|
|
<A NAME='reference'>
|
|
<H2>Reference</H2>
|
|
|
|
<A NAME='description'>
|
|
<H4>Description</H4>
|
|
|
|
<P>Puts back a character to a given instance of the template parameter <CODE>Peekable</CODE></P>
|
|
|
|
<A NAME='synopsis'>
|
|
<H4>Synopsis</H4>
|
|
|
|
<PRE CLASS='broken_ie'><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
|
|
|
|
<SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Peekable</A>>
|
|
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#semantics">putback</A>(Peekable& peekable, <SPAN CLASS="keyword">typename</SPAN> <A CLASS='documented' HREF='../traits.html#char_type_ref'>io_char</A><Peekable>::type c);
|
|
|
|
} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
|
|
|
|
<A NAME='template_params'></A>
|
|
<H4>Template Parameters</H4>
|
|
|
|
<TABLE STYLE='margin-left:2em' BORDER=0 CELLPADDING=2>
|
|
<TR>
|
|
<TR>
|
|
<TD VALIGN='top'><I>Peekable</I></TD><TD WIDTH='2em' VALIGN='top'>-</TD>
|
|
<TD>A model of <A HREF='../concepts/peekable.html'>Peekable</A> or a standard input stream or stream buffer type.
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME='semantics'></A>
|
|
<H4>Semantics</H4>
|
|
|
|
<P>The semantics of <CODE>putback</CODE> depends on the <A HREF="../traits.html#category">category</A> of <CODE>Peekable</CODE> as follows:</P>
|
|
|
|
<TABLE STYLE='margin:0,0,2em,2em' BORDER=1 CELLPADDING=4>
|
|
<TR><TH><CODE>io_category<Peekable>::type</CODE></TH><TH>semantics</TH></TR>
|
|
<TR>
|
|
<TD VALIGN='top'>convertible to <A HREF='../traits.html#category_tags'><CODE>istream_tag</CODE></A></TD>
|
|
<TD>invokes <CODE>peekable.putback(c)</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN='top'>convertible to <A HREF='../traits.html#category_tags'><CODE>streambuf_tag</CODE></A> but not to <A HREF='../traits.html#category_tags'><CODE>istream_tag</CODE></A></TD>
|
|
<TD>invokes <CODE>peekable.sputbackc(c)</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN='top'>convertible to <A HREF='../traits.html#category_tags'><CODE>peekable_tag</CODE></A> but not to <A HREF='../traits.html#category_tags'><CODE>streambuf_tag</CODE></A> or <A HREF='../traits.html#category_tags'><CODE>istream_tag</CODE></A></TD>
|
|
<TD>invokes <CODE>peekable.putback(c)</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN='top'>otherwise</TD>
|
|
<TD>compile-time error</CODE></TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<!-- Begin Footer -->
|
|
|
|
<HR>
|
|
<P CLASS='copyright'>Revised
|
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
|
20 May, 2004
|
|
<!--webbot bot="Timestamp" endspan i-checksum="38504" -->
|
|
</P>
|
|
|
|
<P CLASS='copyright'>© Copyright Jonathan Turkanis, 2004</P>
|
|
<P CLASS='copyright'>
|
|
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>)
|
|
</P>
|
|
|
|
<!-- End Footer -->
|
|
|
|
</BODY> |