mirror of
https://github.com/boostorg/iostreams.git
synced 2026-02-22 15:32:20 +00:00
98 lines
4.3 KiB
HTML
Executable File
98 lines
4.3 KiB
HTML
Executable File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>Function Template reverse</TITLE>
|
|
<LINK REL='stylesheet' HREF='../../../../boost.css'>
|
|
<LINK REL='stylesheet' HREF='../theme/iostreams.css'>
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<!-- Begin Banner -->
|
|
|
|
<H1 CLASS='title'>Function Template <CODE>reverse</CODE></H1>
|
|
<HR CLASS='banner'>
|
|
|
|
<!-- End Banner -->
|
|
|
|
<DL class='page-index'>
|
|
<DT><A href='#description'>Description</A></DT>
|
|
<DT><A href='#headers'>Headers</A></DT>
|
|
<DT><A href='#synopsis'>Synopsis</A></DT>
|
|
<DT><A href='#synopsis'>Example</A></DT>
|
|
</DL>
|
|
|
|
<A NAME='description'>
|
|
<H2>Description</H2>
|
|
|
|
<P>
|
|
The function template <CODE>reverse</CODE> takes a Filter and returns a new Filter which performs the same filtering operation as the original Filter but which is an <A HREF="../concepts/output_filter.html">OutputFilter</A> if the orginal Filter was an <A HREF="../concepts/input_filter.html">InputFilter</A> and and <A HREF="../concepts/input_filter.html">InputFilter</A> if the orginal Filter was an <A HREF="../concepts/output_filter.html">OutputFilter</A>. Roughly speaking, it <I>reverses</I> the direction of a given Filter.
|
|
</P>
|
|
|
|
<P>
|
|
The implementation of <CODE>reverse</CODE> makes use of the class template <A HREF="../classes/one_step_filter.html"><CODE>one_step_filter</CODE></A>, which filters an entire sequence of data at once. Therefore, a Filter returned by <CODE>reverse</CODE> may have higher memory use than the original Filter and is unsuitable for use with streams of data which have no definite endpoint.
|
|
</P>
|
|
|
|
<A NAME='headers'>
|
|
<H2>Headers</H2>
|
|
|
|
<DL>
|
|
<DT><A CLASS='header' HREF='../../../../boost/iostreams/reverse.hpp'><CODE><boost/iostreams/reverse.hpp></CODE></A></DT>
|
|
</DL>
|
|
|
|
<A NAME='synopsis'>
|
|
<H2>Synopsis</H2>
|
|
|
|
<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> Filter>
|
|
<SPAN CLASS='omitted'>implementation-defined</SPAN> <SPAN CLASS="defined">reverse</SPAN>(<SPAN CLASS="keyword">const</SPAN> Filter& filter);
|
|
|
|
} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
|
|
|
|
<A NAME='example'>
|
|
<H2>Example</H2>
|
|
|
|
The following example defines an <A HREF="../concepts/output_filter.html">OutputFilter</A> and uses it to filter standard input.
|
|
|
|
<PRE CLASS='broken_ie'><SPAN CLASS='preprocessor'>#include</SPAN> <SPAN CLASS='literal'><cctype></SPAN> <SPAN CLASS='comment'>// toupper</SPAN>
|
|
<SPAN CLASS='preprocessor'>#include</SPAN> <SPAN CLASS='literal'><iostream></SPAN>
|
|
<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'>// output_filter</SPAN>
|
|
<SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF="../../../../boost/iostreams/filtering_stream.hpp"><SPAN CLASS='literal'><boost/iostreams/filtering_stream.hpp></SPAN></A>
|
|
<SPAN CLASS='preprocessor'>#include</SPAN> <A CLASS='header' HREF="../../../../boost/iostreams/reverse.hpp"><SPAN CLASS='literal'><boost/iostreams/reverse.hpp></SPAN></A>
|
|
|
|
<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='comment'>// Converts characters to uppercase</SPAN>
|
|
<SPAN CLASS="keyword">struct</SPAN> toupper_filter : output_filter {
|
|
<SPAN CLASS="keyword">void</SPAN> put(<SPAN CLASS="keyword">char</SPAN> c, std::streambuf& dest)
|
|
{
|
|
dest.sputc(toupper(c));
|
|
}
|
|
};
|
|
|
|
<SPAN CLASS="keyword">int</SPAN> main()
|
|
{
|
|
filtering_stream<input> in;
|
|
in.push(reverse(toupper_filter()));
|
|
in.push(cin);
|
|
<SPAN CLASS='omitted'>...</SPAN>
|
|
}</PRE>
|
|
|
|
<!-- 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> |