• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4    <TITLE>Null Devices</TITLE>
5    <LINK REL="stylesheet" HREF="../../../../boost.css">
6    <LINK REL="stylesheet" HREF="../theme/iostreams.css">
7</HEAD>
8<BODY>
9
10<!-- Begin Banner -->
11
12    <H1 CLASS="title">Null Devices</H1>
13    <HR CLASS="banner">
14
15<!-- End Banner -->
16
17<DL class="page-index">
18  <DT><A href="#overview">Overview</A></DT>
19  <DT><A href="#acknowledgments">Acknowledgments</A></DT>
20  <DT><A href="#headers">Headers</A></DT>
21  <DT><A href="#reference">Reference</A>
22    <DL>
23      <DT><A href="#null_source">Class template <CODE>basic_null_source</CODE></A></DT>
24      <DT><A href="#null_sink">Class template <CODE>basic_null_sink</CODE></A></DT>
25      <DT><A href="#null_device">Class template <CODE>basic_null_device</CODE></A></DT>
26    </DL>
27  </DT>
28</DL>
29
30<HR>
31
32<A NAME="overview"></A>
33<H2>Overview</H2>
34
35<P>
36    The class templates <CODE>basic_null_source</CODE>, <CODE>basic_null_sink</CODE> and <CODE>basic_null_device</CODE> are models of Device whose member functions all have trivial implementations. A <CODE>basic_null_source</CODE> is a <A HREF="../concepts/source.html">Source</A> whose member function <CODE>read</CODE> returns <CODE>-1</CODE>, indicating end-of-sequence. A <CODE>basic_null_sink</CODE> is a <A HREF="../concepts/sink.html">Sink</A> whose member function <CODE>write</CODE> consumes and ignores the characters passed to it. A <CODE>basic_null_device</CODE> combines &#8212; depending on its template parameter <A HREF="#null_device_params"><CODE>Mode</CODE></A> &#8212; the trivial <CODE>read</CODE> and <CODE>write</CODE> functions just described with a member <CODE>seek</CODE> that always returns an invalid stream position.
37</P>
38
39<P>
40    In addition, each of the above templates is <A HREF='../concepts/closable.html'>Closable</A>, with a no-op implementation of <CODE>close</CODE>.
41</P>
42
43<A NAME="acknowledgments"></A>
44<H2>Acknowledgments</H2>
45
46<P>
47    The templates described here were inspired by <A HREF="http://www.boost.org/people/daryle_walker.html" TARGET="_top">Daryle Walker's</A> <CODE>basic_nullbuf</CODE> template. <I>See</I> <A HREF="http://boost-sandbox.cvs.sourceforge.net/viewvc/boost-sandbox/boost-sandbox/libs/io/doc/null_stream.html" TARGET="_top">Disconnected Streams</A>.
48</P>
49
50<A NAME="headers"></A>
51<H2>Headers</H2>
52
53<DL class="page-index">
54  <DT><A CLASS="header" HREF="../../../../boost/iostreams/device/null.hpp"><CODE>&lt;boost/iostreams/device/null.hpp&gt;</CODE></A></DT>
55</DL>
56
57<A NAME="reference"></A>
58<H2>Reference</H2>
59
60<A NAME="null_source"></A>
61<H3>Class template <CODE>basic_null_source</CODE></H3>
62
63<H4>Description</H4>
64
65<P>Model of <A HREF="../concepts/source.html">Source</A> whose member function <CODE>read</CODE> returns <CODE>-1</CODE>, indicating end-of-sequence.</P>
66
67<H4>Synopsis</H4>
68
69<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
70
71<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#null_source_params">Ch</A>&gt;
72<SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#null_source_params">basic_null_source</A> {
73<SPAN CLASS="keyword">public</SPAN>:
74    <SPAN CLASS="keyword">typedef</SPAN> Ch                        char_type;
75    <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN>  category;
76
77    <A CLASS="documented" HREF="#null_source_ctor">basic_null_source</A>();
78    std::streamsize <A CLASS="documented" HREF="#null_source_read">read</A>(char_type* s, std::streamsize n);
79    <SPAN CLASS='keyword'>void</SPAN> <A CLASS='documented' HREF='#null_source_close'>close</A>();
80};
81
82<SPAN CLASS='keyword'>typedef</SPAN> basic_null_source&lt;<SPAN CLASS='keyword'>char</SPAN>&gt;     <SPAN CLASS='defined'>null_source</SPAN>;
83<SPAN CLASS='keyword'>typedef</SPAN> basic_null_source&lt;<SPAN CLASS='keyword'>wchar_t</SPAN>&gt;  <SPAN CLASS='defined'>wnull_source</SPAN>;
84
85} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
86
87<A NAME="null_source_params"></A>
88<H4>Template parameters</H4>
89
90<TABLE STYLE="margin-left:2em">
91<TR>
92    <TD><P><I>Ch</I></TD><TD VALIGN="top">-</TD>
93    <TD><P>The <A HREF='../guide/traits.html#char_type'>character type</A> type.</TD>
94</TR>
95</TABLE>
96
97<A NAME="null_source_ctor"></A>
98
99<H4><CODE>basic_null_source::basic_null_source</CODE></H4>
100
101<PRE CLASS="broken_ie">    basic_null_source();</PRE>
102
103<P>Constructs a <CODE>basic_null_source</CODE>.</P>
104
105<A NAME="null_source_read"></A>
106<H4><CODE>basic_null_source::read</CODE></H4>
107
108<PRE CLASS="broken_ie">    std::streamsize read(char_type* s, std::streamsize n);</PRE>
109
110<P>Returns <CODE>-1</CODE>.</P>
111
112<A NAME="null_source_close"></A>
113<H4><CODE>basic_null_source::close</CODE></H4>
114
115<PRE CLASS="broken_ie">    <SPAN CLASS='keyword'>void</SPAN> close();</PRE>
116
117<P>No-op.</P>
118
119<A NAME="null_sink"></A>
120<H3>Class template <CODE>basic_null_sink</CODE></H3>
121
122<H4>Description</H4>
123
124<P>Model of <A HREF="../concepts/sink.html">Sink</A> whose member function <CODE>write</CODE> consumes and ignores the contents of the character buffer passed to it.
125
126<H4>Synopsis</H4>
127
128<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
129
130<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#null_sink_params">Ch</A>&gt;
131<SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#null_sink_params">basic_null_sink</A> {
132<SPAN CLASS="keyword">public</SPAN>:
133    <SPAN CLASS="keyword">typedef</SPAN> Ch                        char_type;
134    <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN>  category;
135
136    <A CLASS="documented" HREF="#null_sink_ctor">basic_null_sink</A>();
137    std::streamsize <A CLASS="documented" HREF="#null_sink_write">write</A>(<SPAN CLASS='keyword'>const</SPAN> char_type* s, std::streamsize n);
138    <SPAN CLASS='keyword'>void</SPAN> <A CLASS='documented' HREF='#null_sink_close'>close</A>();
139};
140
141<SPAN CLASS='keyword'>typedef</SPAN> basic_null_sink&lt;<SPAN CLASS='keyword'>char</SPAN>&gt;     <SPAN CLASS='defined'>null_sink</SPAN>;
142<SPAN CLASS='keyword'>typedef</SPAN> basic_null_sink&lt;<SPAN CLASS='keyword'>wchar_t</SPAN>&gt;  <SPAN CLASS='defined'>wnull_sink</SPAN>;
143
144} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
145
146<A NAME="null_sink_params"></A>
147<H4>Template parameters</H4>
148
149<TABLE STYLE="margin-left:2em">
150<TR>
151    <TD><P><I>Ch</I></TD><TD VALIGN="top">-</TD>
152    <TD><P>The <A HREF='../guide/traits.html#char_type'>character type</A> type.</TD>
153</TR>
154</TABLE>
155
156<A NAME="null_sink_ctor"></A>
157
158<H4><CODE>basic_null_sink::basic_null_sink</CODE></H4>
159
160<PRE CLASS="broken_ie">    basic_null_sink();</PRE>
161
162<P>Constructs a <CODE>basic_null_sink</CODE>.</P>
163
164<A NAME="null_sink_write"></A>
165<H4><CODE>basic_null_sink::write</CODE></H4>
166
167<PRE CLASS="broken_ie">    std::streamsize write(<SPAN CLASS='keyword'>const</SPAN> char_type* s, std::streamsize n);</PRE>
168
169<P>Returns <CODE>n</CODE>.</P>
170
171<A NAME="null_sink_close"></A>
172<H4><CODE>basic_null_sink::close</CODE></H4>
173
174<PRE CLASS="broken_ie">    <SPAN CLASS='keyword'>void</SPAN> close();</PRE>
175
176<P>No-op.</P>
177
178<A NAME="null_device"></A>
179<H3>Class template <CODE>basic_null_device</CODE></H3>
180
181<H4>Description</H4>
182
183<P>Model of <A HREF="../concepts/seekable_device.html">Device</A> whose mode is specified as a template parameter, and whose member functions have trivial implementations, as follows:</P>
184<UL>
185<LI><CODE>read</CODE> returns <CODE>-1</CODE>, indicating end-of-sequence
186<LI><CODE>write</CODE> consumes but ignores the entire contents of the character buffer passed to it
187<LI><CODE>seek</CODE> returns an invalid stream position
188</UL>
189
190<H4>Synopsis</H4>
191
192<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
193
194<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#null_device_params">Ch</A>, <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#null_device_params">Mode</A>&gt;
195<SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#null_device_params">basic_null_device</A> {
196<SPAN CLASS="keyword">public</SPAN>:
197    <SPAN CLASS="keyword">typedef</SPAN> Ch                        char_type;
198    <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN>  category;
199
200    <A CLASS="documented" HREF="#null_device_ctor">basic_null_device</A>();
201    std::streamsize <A CLASS="documented" HREF="#null_device_read">read</A>(char_type* s, std::streamsize n);
202    std::streamsize <A CLASS="documented" HREF="#null_device_write">write</A>(<SPAN CLASS='keyword'>const</SPAN> char_type* s, std::streamsize n);
203    <A CLASS='documented' HREF='../functions/positioning.html#synopsis'>stream_offset</A> <A CLASS='documented' HREF='#null_device_seek'>seek</A>( <A CLASS='documented' HREF='../functions/positioning.html#synopsis'>stream_offset</A> off, std::ios_base::seekdir way,
204                        std::ios_base::openmode which =
205                            std::ios_base::in | std::ios_base::out );
206    <SPAN CLASS='keyword'>void</SPAN> <A CLASS='documented' HREF='#null_device_close'>close</A>();
207};
208
209} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
210
211<A NAME="null_device_params"></A>
212<H4>Template parameters</H4>
213
214<TABLE STYLE="margin-left:2em">
215<TR>
216    <TD><P><I>Ch</I></TD><TD VALIGN="top">-</TD>
217    <TD><P>The <A HREF='../guide/traits.html#char_type'>character type</A>.</TD>
218</TR>
219<TR>
220    <TD><P><I>Mode</I></TD><TD VALIGN="top">-</TD>
221    <TD><P>The <A HREF='../guide/modes.html'>mode</A>.</TD>
222</TR>
223</TABLE>
224
225<A NAME="null_device_ctor"></A>
226<H4><CODE>basic_null_device::basic_null_device</CODE></H4>
227
228<PRE CLASS="broken_ie">    basic_null_device();</PRE>
229
230<P>Constructs a <CODE>basic_null_device</CODE>.</P>
231
232<A NAME="null_device_read"></A>
233<H4><CODE>basic_null_device::read</CODE></H4>
234
235<PRE CLASS="broken_ie">    std::streamsize read(char_type* s, std::streamsize n);</PRE>
236
237<P>Returns <CODE>-1</CODE>. Enabled if <CODE>Mode</CODE> refines <A HREF='../guide/modes.html#mode_tags'><CODE>input</CODE></A>.</P>
238
239<A NAME="null_device_write"></A>
240<H4><CODE>basic_null_device::write</CODE></H4>
241
242<PRE CLASS="broken_ie">    std::streamsize write(<SPAN CLASS='keyword'>const</SPAN> char_type* s, std::streamsize n);</PRE>
243
244<P>Returns <CODE>n</CODE>. Enabled if <CODE>Mode</CODE> refines <A HREF='../guide/modes.html#mode_tags'><CODE>output</CODE></A>.</P>
245
246<A NAME="null_device_seek"></A>
247<H4><CODE>basic_null_device::seek</CODE></H4>
248
249<PRE CLASS="broken_ie">     <A CLASS='documented' HREF='../functions/positioning.html#synopsis'>stream_offset</A> seek( <A CLASS='documented' HREF='../functions/positioning.html#synopsis'>stream_offset</A> off, std::ios_base::seekdir way,
250                         std::ios_base::openmode which =
251                             std::ios_base::in | std::ios_base::out );</PRE>
252
253<P>Returns an invalid stream position. Enabled if <CODE>Mode</CODE> permits random access.</P>
254
255<A NAME="null_device_close"></A>
256<H4><CODE>basic_null_device::close</CODE></H4>
257
258<PRE CLASS="broken_ie">    <SPAN CLASS='keyword'>void</SPAN> close();</PRE>
259
260<P>No-op.</P>
261
262<!-- Begin Footer -->
263
264<HR>
265
266<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>
267<P CLASS="copyright">
268    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>)
269</P>
270
271<!-- End Footer -->
272
273</BODY>