• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4    <TITLE>File Wrappers</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">File Wrappers</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="#headers">Headers</A></DT>
20  <DT><A href="#reference">Reference</A>
21    <UL>
22      <LI CLASS="square"><A href="#file_source">Class template <CODE>basic_file_source</CODE></A></LI>
23      <LI CLASS="square"><A href="#file_sink">Class template <CODE>basic_file_sink</CODE></A></LI>
24      <LI CLASS="square"><A href="#file">Class template <CODE>basic_file</CODE></A></LI>
25    </UL>
26  </DT>
27</DL>
28
29<HR>
30
31<A NAME="overview"></A>
32<H2>Overview</H2>
33
34<P>
35    The class templates <CODE>basic_file_source</CODE>, <CODE>basic_file_sink</CODE> and <CODE>basic_file</CODE> are wrappers for <CODE>std::basic_filebuf</CODE> which are <A HREF="http://www.boost.org/libs/utility/CopyConstructible.html"  TARGET="_top">CopyConstructible</A> and <A HREF="http://www.boost.org/libs/utility/Assignable.html">Assignable</A>. They are useful whenever one wants to access a file without managing the lifetime of a standard file stream or stream buffer. This is because when a stream or stream buffer is added to a <A HREF="filtering_streambuf.html"><CODE>filtering_streambuf</CODE></A> or <A HREF="filtering_stream.html"><CODE>filtering_stream</CODE></A> it is stored as a reference which must remain valid until that stream or stream buffer is removed from the chain.
36</P>
37<P>
38    The most common specializations are accessible via the typedefs <CODE>file_source</CODE>, <CODE>file_sink</CODE>, <CODE>file</CODE>, <CODE>wfile_source</CODE>, <CODE>wfile_sink</CODE> and <CODE>wfile</CODE>.
39</P>
40
41<A NAME="headers"></A>
42<H2>Headers</H2>
43
44<DL class="page-index">
45  <DT><A CLASS="header" HREF="../../../../boost/iostreams/device/file.hpp"><CODE>&lt;boost/iostreams/device/file.hpp&gt;</CODE></A></DT>
46</DL>
47
48<A NAME="reference"></A>
49<H2>Reference</H2>
50
51<A NAME="file_source"></A>
52<H3>Class template <CODE>basic_file_source</CODE></H3>
53
54<H4>Description</H4>
55
56<P>
57    <A HREF="http://www.boost.org/libs/utility/CopyConstructible.html" TARGET="_top">CopyConstructible</A> and <A HREF="http://www.boost.org/libs/utility/Assignable.html">Assignable</A> wrapper for a <CODE>std::basic_filebuf</CODE> opened in read-only mode.
58<P>
59
60<A NAME="file_source_synopsis"></A>
61<H4>Synopsis</H4>
62
63<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
64
65<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#basic_file_source_params">Ch</A>&gt;
66<SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#basic_file_source_params">basic_file_source</A> {
67<SPAN CLASS="keyword">public</SPAN>:
68    <SPAN CLASS="keyword">typedef</SPAN> Ch                      char_type;
69    <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">implementation-defined</SPAN>  category;
70    <A CLASS="documented" HREF="#basic_file_source_constructor">basic_file_source</A>( <SPAN CLASS="keyword">const</SPAN> std::string&amp; path,
71                       std::ios_base::openmode mode =
72                           std::ios_base::in );
73    <SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#basic_file_source_is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
74    <SPAN CLASS="omitted">...</SPAN>
75};
76
77<SPAN CLASS="keyword">typedef</SPAN> basic_file_source&lt;<SPAN CLASS="keyword">char</SPAN>&gt;     <SPAN CLASS="defined">file_source</SPAN>;
78<SPAN CLASS="keyword">typedef</SPAN> basic_file_source&lt;<SPAN CLASS="keyword">wchar_t</SPAN>&gt;  <SPAN CLASS="defined">wfile_source</SPAN>;
79
80} } <SPAN CLASS='comment'>// End namespace boost::iostreams</SPAN></PRE>
81
82<A NAME="basic_file_source_params"></A>
83<H4>Template parameters</H4>
84
85<TABLE STYLE="margin-left:2em">
86<TR>
87    <TD><I>Ch</I></TD><TD VALIGN="top">-</TD>
88    <TD>The character type.</TD></TR>
89<TR>
90</TABLE>
91
92<A NAME="basic_file_source_constructor"></A>
93<H4><CODE>basic_file_source::basic_file_source</CODE></H4>
94
95<PRE CLASS="broken_ie">    basic_file_source( <SPAN CLASS="keyword">const</SPAN> std::string&amp; path,
96                       std::ios_base::openmode mode );</PRE>
97
98<P>
99    Constructs a <CODE>basic_file_source</CODE> which wraps a <CODE>std::basic_filebuf</CODE> <CODE>buf</CODE> opened as follows:
100    <PRE CLASS="broken_ie">    mode |= std::ios_base::in;
101    mode &amp;= ~std::ios_base::out;
102    buf.open(path.c_str(), mode);</PRE>
103</P>
104
105<A NAME="basic_file_source_is_open"></A>
106<H4><CODE>basic_file_source::is_open</CODE></H4>
107
108<PRE CLASS="broken_ie">    <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
109
110<P>Returns <CODE>true</CODE> if the underlying instance of <CODE>basic_filebuf</CODE> was opened successfully.</P>
111
112<A NAME="file_sink"></A>
113<H3>Class template <CODE>basic_file_sink</CODE></H3>
114
115<H4>Description</H4>
116
117<P>
118    <A HREF="http://www.boost.org/libs/utility/CopyConstructible.html" TARGET="_top">CopyConstructible</A> and <A HREF="http://www.boost.org/libs/utility/Assignable.html">Assignable</A> wrapper for a <CODE>std::basic_filebuf</CODE> opened in write-only mode.
119<P>
120
121<A NAME="file_sink_synopsis"></A>
122<H4>Synopsis</H4>
123
124<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
125
126<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#basic_file_sink_params">Ch</A>&gt;
127<SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#basic_file_sink_params">basic_file_sink</A> {
128<SPAN CLASS="keyword">public</SPAN>:
129    <SPAN CLASS="keyword">typedef</SPAN> Ch                      char_type;
130    <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">implementation-defined</SPAN>  category;
131    <A CLASS="documented" HREF="#basic_file_sink_constructor">basic_file_sink</A>( <SPAN CLASS="keyword">const</SPAN> std::string&amp; path,
132                     std::ios_base::openmode mode =
133                         std::ios_base::out );
134    <SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#basic_file_sink_is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
135    <SPAN CLASS="omitted">...</SPAN>
136};
137
138<SPAN CLASS="keyword">typedef</SPAN> basic_file_sink&lt;<SPAN CLASS="keyword">char</SPAN>&gt;     <SPAN CLASS="defined">file_sink</SPAN>;
139<SPAN CLASS="keyword">typedef</SPAN> basic_file_sink&lt;<SPAN CLASS="keyword">wchar_t</SPAN>&gt;  <SPAN CLASS="defined">wfile_sink</SPAN>;
140
141} } <SPAN CLASS='comment'>// End namespace boost::iostreams</SPAN></PRE>
142
143<A NAME="basic_file_sink_params"></A>
144<H4>Template parameters</H4>
145
146<TABLE STYLE="margin-left:2em">
147<TR>
148    <TD><I>Ch</I></TD><TD VALIGN="top">-</TD>
149    <TD>The character type.</TD></TR>
150<TR>
151</TABLE>
152
153<A NAME="basic_file_sink_constructor"></A>
154<H4><CODE>basic_file_sink::basic_file_sink</CODE></H4>
155
156<PRE CLASS="broken_ie">    basic_file_sink( <SPAN CLASS="keyword">const</SPAN> std::string&amp; path,
157                     std::ios_base::openmode mode );</PRE>
158
159<P>
160    Constructs a <CODE>basic_file_sink</CODE> which wraps a <CODE>std::basic_filebuf</CODE> <CODE>buf</CODE> opened as follows:
161    <PRE CLASS="broken_ie">    mode |= std::ios_base::out;
162    mode &amp;= ~std::ios_base::in;
163    buf.open(path.c_str(), mode);</PRE>
164</P>
165
166<A NAME="basic_file_sink_is_open"></A>
167<H4><CODE>basic_file_sink::is_open</CODE></H4>
168
169<PRE CLASS="broken_ie">    <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
170
171<P>Returns <CODE>true</CODE> if the underlying instance of <CODE>basic_filebuf</CODE> was opened successfully.</P>
172
173<A NAME="file"></A>
174<H3>Class template <CODE>basic_file</CODE></H3>
175
176<H4>Description</H4>
177
178<P><A HREF="http://www.boost.org/libs/utility/CopyConstructible.html"  TARGET="_top">CopyConstructible</A> and <A HREF="http://www.boost.org/libs/utility/Assignable.html">Assignable</A> wrapper for a <CODE>std::basic_filebuf</CODE> opened in read-write mode by default.
179
180<A NAME="file_synopsis"></A>
181<H4>Synopsis</H4>
182
183<PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
184
185<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#basic_file_params">Ch</A>&gt;
186<SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#basic_file_params">basic_file</A> {
187<SPAN CLASS="keyword">public</SPAN>:
188    <SPAN CLASS="keyword">typedef</SPAN> Ch                      char_type;
189    <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">implementation-defined</SPAN>  category;
190    <A CLASS="documented" HREF="#basic_file_constructor">basic_file</A>( <SPAN CLASS="keyword">const</SPAN> std::string&amp; path,
191                std::ios_base::openmode mode =
192                    std::ios_base::in | std::ios_base::out );
193    <SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#basic_file_is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
194    <SPAN CLASS="omitted">...</SPAN>
195};
196
197<SPAN CLASS="keyword">typedef</SPAN> basic_file&lt;<SPAN CLASS="keyword">char</SPAN>&gt;     <SPAN CLASS="defined">file</SPAN>;
198<SPAN CLASS="keyword">typedef</SPAN> basic_file&lt;<SPAN CLASS="keyword">wchar_t</SPAN>&gt;  <SPAN CLASS="defined">wfile</SPAN>;
199
200} } <SPAN CLASS='comment'>// End namespace boost::iostreams</SPAN></PRE>
201
202<A NAME="basic_file_params"></A>
203<H4>Template parameters</H4>
204
205<TABLE STYLE="margin-left:2em">
206<TR>
207    <TD><I>Ch</I></TD><TD VALIGN="top">-</TD>
208    <TD>The character type.</TD></TR>
209<TR>
210</TABLE>
211
212<A NAME="basic_file_constructor"></A>
213<H4><CODE>basic_file_::basic_file</CODE></H4>
214
215<PRE CLASS="broken_ie">    basic_file( <SPAN CLASS="keyword">const</SPAN> std::string&amp; path,
216                std::ios_base::openmode mode );</PRE>
217
218<P>
219    Constructs a <CODE>basic_file</CODE> which wraps a <CODE>std::basic_filebuf</CODE> <CODE>buf</CODE> opened as follows:
220    <PRE CLASS="broken_ie">    mode |= std::ios_base::in | std::ios_base::out;
221    buf.open(path.c_str(), mode);</PRE>
222</P>
223
224<A NAME="basic_file_is_open"></A>
225<H4><CODE>basic_file::is_open</CODE></H4>
226
227<PRE CLASS="broken_ie">    <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
228
229<P>Returns <CODE>true</CODE> if the underlying instance of <CODE>basic_filebuf</CODE> was opened successfully.</P>
230
231<!-- Begin Footer -->
232
233<HR>
234
235<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>
236<P CLASS="copyright">
237    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>)
238</P>
239
240<!-- End Footer -->
241
242</BODY>