mirror of
https://github.com/boostorg/iostreams.git
synced 2026-02-22 15:32:20 +00:00
154 lines
6.2 KiB
HTML
Executable File
154 lines
6.2 KiB
HTML
Executable File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>Sink</TITLE>
|
|
<LINK REL='stylesheet' HREF='../../../../boost.css'>
|
|
<LINK REL='stylesheet' HREF='../theme/iostreams.css'>
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<!-- Begin Banner -->
|
|
|
|
<H1 CLASS='title'>Sink</H1>
|
|
<HR CLASS='banner'>
|
|
|
|
<!-- End Banner -->
|
|
|
|
<H2>Definition</H2>
|
|
|
|
<P>
|
|
A Sink is a <A HREF='device.html'>Device</A> whose <A HREF='../modes.html'>i/o mode</A> refines <A HREF='../modes.html#output'>output</A>.
|
|
</P>
|
|
|
|
<H2>Description</H2>
|
|
|
|
<P>
|
|
A Sink provides write-access to a sequence of characters of a given type. A Sink may expose this sequence in three ways:
|
|
<OL>
|
|
<LI STYLE='list-style-type:lower-roman'>
|
|
by defining a member function <CODE>write</CODE>, invoked indirectly by the Iostreams Library through the function <A HREF='../functions/write.html'><CODE>boost::iostreams::write</CODE></A>;
|
|
</LI>
|
|
<LI STYLE='list-style-type:lower-roman'>
|
|
by overloading or specializing <A HREF='../functions/write.html'><CODE>boost::iostreams::write</CODE></A>; or
|
|
</LI>
|
|
<LI STYLE='list-style-type:lower-roman'>
|
|
by defining a member function <CODE>output_sequence</CODE> returning a pair of pointers delimiting the sequence in its entirety.
|
|
</LI>
|
|
</OL>
|
|
</P>
|
|
|
|
<P>The i/o mode of a Sink is <A HREF='../modes.html#output'>output</A> or one of its refinements.</P>
|
|
|
|
<H2>Example</H2>
|
|
|
|
<P>A model of Sink can be defined as follows:</P>
|
|
|
|
<PRE CLASS='broken_ie'><SPAN CLASS="keyword">struct</SPAN> Sink {
|
|
<SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="keyword">char</SPAN> char_type;
|
|
<SPAN CLASS="keyword">typedef</SPAN> sink_tag io_category;
|
|
<SPAN CLASS="keyword">void</SPAN> write(<SPAN CLASS="keyword">const</SPAN> <SPAN CLASS="keyword">char</SPAN>* s, std::streamsize n)
|
|
{
|
|
<SPAN CLASS='comment'>// Writes n characters from the buffer s to the
|
|
// controlled sequence.</SPAN>
|
|
}
|
|
};</PRE>
|
|
|
|
<P>
|
|
Here <CODE>sink_tag</CODE> is a <A HREF='../traits.html#category_tags'>category tag</A> identifying the type as a model of Sink. Typically a Sink can be defined by deriving from the helper classes <A HREF='../classes/device.html#sink'><CODE>sink</CODE></A> or <A HREF='../classes/device.html#wsink'><CODE>wsink</CODE></A> and defining a member function <CODE>write</CODE>.
|
|
|
|
<H2>Refinement of</H2>
|
|
|
|
<P><A HREF='device.html'>Device</A>.</P>
|
|
|
|
<A NAME='types'></A>
|
|
<H2>Associated Types</H2>
|
|
|
|
<P>Same as <A HREF='device.html#types'>Device</A>, with the following additional requirements:</P>
|
|
|
|
<TABLE CELLPADDING='5' BORDER='1'>
|
|
<TR><TD>Category</TD><TD>A type convertible to <A HREF="../traits.html#category_tags"><CODE>device_tag</CODE></A> and to <A HREF="../modes.html#mode_tags"><CODE>output</CODE></A></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME='notation'></A>
|
|
<H2>Notation</H2>
|
|
|
|
<TABLE CELLPADDING='2'>
|
|
<TR><TD><CODE>S</CODE></TD><TD>- A type which is a model of Sink</TD></TR>
|
|
<TR><TD><CODE>Ch</CODE></TD><TD>- The character type</TD></TR>
|
|
<TR><TD><CODE>snk</CODE></TD><TD>- Object of type <CODE>S</CODE></TD></TR>
|
|
<TR><TD><CODE>s</CODE></TD><TD>- Object of type <CODE>const Ch*</CODE></SPAN></TD></TR>
|
|
<TR><TD><CODE>n</CODE></TD><TD>- Object of type <CODE>std::streamsize</CODE></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME='expressions'></A>
|
|
<H2>Valid Expressions / Semantics</H2>
|
|
|
|
<P>Same as <A HREF='device.html#types'>Device</A>, with the following additional requirements:</P>
|
|
|
|
<TABLE CELLPADDING='5' BORDER='1'>
|
|
<TR><TH>Expression</TH><TH>Expression Type</TH><TH>Category Precondition</TH><TH>Semantics</TH></TR>
|
|
<TR>
|
|
<TD>
|
|
<PRE CLASS='plain_code'><CODE>typename <A HREF='../traits.html'>io_char</A><S>::type</CODE></PRE>
|
|
</TD>
|
|
<TD><CODE>typename</CODE> of the character type</TD>
|
|
<TD ALIGN='center'>-</TD><TD ALIGN='center'>-</TD>
|
|
</TR>
|
|
<TR>
|
|
<TD>
|
|
<PRE CLASS='plain_code'><CODE>typename <A HREF='../traits.html'>io_category</A><S>::type</CODE></PRE>
|
|
</TD>
|
|
<TD><CODE>typename</CODE> of the io_category</TD>
|
|
<TD ALIGN='center'>-</TD><TD ALIGN='center'>-</TD>
|
|
</TR>
|
|
<TR>
|
|
<TD><PRE CLASS='plain_code'><CODE><A HREF='../functions/read.html'>boost::iostreams::write</A>(snk, s, n)</CODE></PRE></TD>
|
|
<TD><CODE>void</CODE></TD>
|
|
<TD>Not convertible to <A HREF="direct.html"><CODE>direct_tag</CODE></A></TD>
|
|
<TD>
|
|
Writes <CODE>n</CODE> characters from the sequence beginning at <CODE>s</CODE> to the sequence controlled by <CODE>snk</CODE>
|
|
</TD>
|
|
</TR>
|
|
<TR>
|
|
<TD><PRE CLASS='plain_code'><CODE>snk.output_sequence()</CODE></PRE></TD>
|
|
<TD><PRE CLASS='plain_code'><CODE>std::pair<Ch*,Ch*></CODE></PRE></TD>
|
|
<TD>Convertible to <A HREF="direct.html"><CODE>direct_tag</CODE></A></TD>
|
|
<TD>Returns a pair of pointers delimiting the sequence controlled by <CODE>snk</CODE></TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<H2>Exceptions</H2>
|
|
|
|
<P>
|
|
Errors which occur during the execution of member functions <CODE>write</CODE> or <CODE>output_sequence</CODE>
|
|
are indicated by throwing exceptions. Attempting to write past the end of the sequence is always an error.
|
|
</P>
|
|
|
|
<P>
|
|
After an exception is thrown, a Sink must be in a consistent state; further i/o operations may throw exceptions but must have well-defined behaviour.
|
|
</P>
|
|
|
|
<H2>Models</H2>
|
|
|
|
<UL>
|
|
<LI>Standard output streams and stream buffers.
|
|
<LI><A HREF='../classes/array.html#array_sink'>array_sink</A>, <A HREF='../classes/file.html#file_sink'>basic_file_sink</A>, <A HREF='../classes/file_descriptor.html#file_descriptor_sink'>file_descriptor_sink</A>, <A HREF='../classes/mapped_file.html#mapped_file_sink'>mapped_file_sink</A>.
|
|
</UL>
|
|
|
|
<!-- 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> |