mirror of
https://github.com/boostorg/iostreams.git
synced 2026-02-22 15:32:20 +00:00
199 lines
9.5 KiB
HTML
Executable File
199 lines
9.5 KiB
HTML
Executable File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>Function Template read</TITLE>
|
|
<LINK REL="stylesheet" HREF="../../../../boost.css">
|
|
<LINK REL="stylesheet" HREF="../theme/iostreams.css">
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<!-- Begin Banner -->
|
|
|
|
<H1 CLASS="title">Function Template <CODE>read</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 two overloads of the function template <CODE>read</CODE> provide a uniform interface for reading a sequence of characters from a <A HREF="../concepts/source.html">Source</A> or <A HREF="../concepts/input_filter.html">InputFilter</A>.
|
|
<UL>
|
|
<LI>The first overload can be used directly in the definitions of new Filter types (<I>see</I> <A HREF="#example">Example</A>), and figures in the specification of the <A HREF="../concepts.html#device_concepts">Device</A> concepts.
|
|
<LI>The second overload is primarily for internal use by the library.
|
|
</UL>
|
|
</P>
|
|
<P>
|
|
Although <CODE>read</CODE> is designed to be overloaded or specialized for new Filter and Device types, the default implementation should be suitable for most purposes.</P>
|
|
</P>
|
|
|
|
<A NAME="example">
|
|
<H2>Example</H2>
|
|
|
|
<P>
|
|
The following code illustrates the use of the function <CODE>read</CODE> in the definition of a <A HREF="../concepts/multi-character.html">Multi-Character</A> <A HREF="../concepts/input_filter.html">InputFilter</A>.
|
|
</P>
|
|
|
|
<PRE CLASS="broken_ie"> <SPAN CLASS="preprocessor">#include</SPAN> <SPAN CLASS="literal"><ctype.h></SPAN> <SPAN CLASS="comment">// tolower</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">// multichar_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">// read</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> tolower_filter : <SPAN CLASS="keyword">public</SPAN> multichar_input_filter {
|
|
<SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> Source>
|
|
streamsize read(Source& src, <SPAN CLASS="keyword">char</SPAN>* s, streamsize n)
|
|
{
|
|
streamsize result = boost::iostreams::read(src, s, n);
|
|
<SPAN CLASS="keyword">for</SPAN> (streamsize z = <SPAN CLASS="numeric_literal">0</SPAN>; z < result; ++z)
|
|
s[z] = tolower(s[z]);
|
|
<SPAN CLASS="keyword">return</SPAN> result;
|
|
}
|
|
};</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>
|
|
|
|
Reads a sequence of characters from a given instance of the template parameter <CODE>T</CODE>, returning the number of characters read.
|
|
|
|
<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">T</A>>
|
|
std::streamsize <A CLASS="documented" HREF="#read_device">read</A>( T& <A CLASS="documented" HREF="#function_params">t</A>,
|
|
<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="../traits.html#char_type_ref">char_type_of</A><T>::type* <A CLASS="documented" HREF="#function_params">s</A>,
|
|
std::streamsize <A CLASS="documented" HREF="#function_params">n</A> );
|
|
|
|
<SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">T</A>, <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Source</A>>
|
|
std::streamsize <A CLASS="documented" HREF="#read_filter">read</A>( T& <A CLASS="documented" HREF="#function_params">t</A>,
|
|
Source& <A CLASS="documented" HREF="#function_params">src</A>,
|
|
<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="../traits.html#char_type_ref">char_type_of</A><T>::type* <A CLASS="documented" HREF="#function_params">s</A>,
|
|
std::streamsize <A CLASS="documented" HREF="#function_params">n</A> );
|
|
|
|
} } <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>T</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
|
|
<TD>For the first overload, a model of <A HREF="../concepts/source.html">Source</A> or a standard input stream or stream buffer type. For the second overload, a model of <A HREF="../concepts/input_filter.html">InputFilter</A>.
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top"><I>Source</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
|
|
<TD>A model of <A HREF="../concepts/source.html">Source</A> with the same <A HREF="../traits.html#char_type">character type</A> as <CODE>T</CODE> whose <A HREF="../modes.html">i/o mode</A> refines that of <CODE>T</CODE>. <CODE>Source</CODE> must also model <A HREF="../concepts/peekable.html">Peekable</A>.
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="function_params"></A>
|
|
<H4>Function Parameters</H4>
|
|
|
|
<TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
|
|
<TR>
|
|
<TR>
|
|
<TD VALIGN="top"><I>t</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
|
|
<TD>An instance of the Filter or Device type <CODE>T</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top"><I>s</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
|
|
<TD>The buffer into which characters should be read</TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top"><I>n</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
|
|
<TD>The maximum number of characters to read</TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top"><I>src</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
|
|
<TD>An instance of <CODE>Source</CODE>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="read_device"></A>
|
|
<H4>Semantics — Device Types</H4>
|
|
|
|
<PRE CLASS="broken_ie"><SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> T>
|
|
std::streamsize read( T& t, <SPAN CLASS="keyword">typename</SPAN> char_type_of<T>::type* s, std::streamsize n );</PRE>
|
|
|
|
<P>The semantics of <CODE>read</CODE> depends on the <A HREF="../traits.html#category">category</A> of <CODE>T</CODE> as follows:</P>
|
|
|
|
<TABLE STYLE="margin-left:2em" BORDER=1 CELLPADDING=4>
|
|
<TR><TH><CODE>category_of<T>::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>t.read(s, n)</CODE> and returns <CODE>t.gcount()</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>returns <CODE>t.sgetn(s, n)</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top"><I>not</I> convertible to <A HREF="../traits.html#category_tags"><CODE>direct_tag</CODE></A></TD>
|
|
<TD>returns <CODE>t.read(s, n)</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top">otherwise</TD>
|
|
<TD>compile-time error</CODE></TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="read_filter"></A>
|
|
<H4>Semantics — Filter Types</H4>
|
|
|
|
<PRE CLASS="broken_ie"><SPAN CLASS="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> T>
|
|
std::streamsize read( T& t, Source& src, <SPAN CLASS="keyword">typename</SPAN> char_type_of<T>::type* s,
|
|
std::streamsize n );</PRE>
|
|
|
|
<P>The semantics of <CODE>read</CODE> depends on the <A HREF="../traits.html#category">category</A> of <CODE>T</CODE> as follows:</P>
|
|
|
|
<TABLE STYLE="margin-bottom:2em;margin-left:2em" BORDER=1 CELLPADDING=4>
|
|
<TR><TH><CODE>category_of<T>::type</CODE></TH><TH>semantics</TH></TR>
|
|
<TR>
|
|
<TD VALIGN="top">convertible to <A HREF="../traits.html#category_tags"><CODE>multichar_tag</CODE></A></TD>
|
|
<TD>returns <CODE>t.read(src, s, n)</CODE></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top">otherwise</TD>
|
|
<TD>reads up to <CODE>n</CODE> characters into <CODE>s</CODE> by invoking <CODE>t.get(src)</CODE> repeatedly, halting if an end-of-stream indicator is returned; returns the number of characters successfully read</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> |