]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/doc/classes/code_converter.html
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / iostreams / doc / classes / code_converter.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Class Template code_converter</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">Class Template <CODE>code_converter</CODE></H1>
13 <HR CLASS="banner">
14
15 <!-- End Banner -->
16
17 <DL class="page-index">
18 <DT><A href="#description">Description</A></DT>
19 <DT><A href="#headers">Headers</A></DT>
20 <DT><A href="#reference">Reference</A></DT>
21 </DL>
22
23 <HR>
24
25 <A NAME="description"></A>
26 <H2>Description</H2>
27
28 <P>
29 The class templates <CODE>code_converter</CODE> is a <SPAN CLASS="term">Device adapter</SPAN> which takes a Device with a narrow <A HREF="../guide/traits.html#char_type">character type</A> \97 typically <CODE>char</CODE> \97 and produces a Device with wide character type \97 typically <CODE>wchar_t</CODE> \97 by introducing a layer of <A HREF="../guide/code_conversion.html">code conversion</A>. The code conversion is performed using a <CODE>std::codecvt</CODE> facet which can either be specified as a template parameter or be fetched from a <CODE>std::locale</CODE> provided at runtime.
30 </P>
31 <P>
32 For example, we can define a wide-character Device for reading from a memory-mapped file as follows:
33 <PRE CLASS="broken_ie"> <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/iostreams/device/mapped_file.hpp"><SPAN CLASS="literal">&lt;boost/iostreams/maped_file.hpp&gt;</SPAN></A>
34
35 <SPAN CLASS="keyword">typedef</SPAN> code_converter&lt;mapped_file_source&gt; my_source;</PRE>
36
37 Similarly, we can define a wide-character Device which writes multibyte characters to an in-memory character sequence as follows:
38
39 <PRE CLASS="broken_ie"> <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/iostreams/device/array.hpp"><SPAN CLASS="literal">&lt;boost/iostreams/device/array.hpp&gt;</SPAN></A>
40
41 <SPAN CLASS="keyword">typedef</SPAN> code_converter&lt;array_sink&gt; my_sink;</PRE>
42 </P>
43 <P>
44 The <A HREF="../guide/modes.html">mode</A> of a specialization of <CODE>code_converter</CODE> is determined as follows. If a narrow character Device is read-only, the resulting specialization of <CODE>code_converter</CODE> has mode <A HREF="../guide/modes.html#input">input</A>. If a narrow character Device is write-only, the resulting specialization of <CODE>code_converter</CODE> has mode <A HREF="../guide/modes.html#output">output</A>. If a narrow character Device performs input and output using two distinct sequences (<I>see</I> <A HREF="../guide/modes.html">Modes</A>), the resulting specialization of <CODE>code_converter</CODE> has mode <A HREF="../guide/modes.html#bidirectional">bidirectional</A>. Otherwise, attempting to spcialize <CODE>code_converter</CODE> results in a compile-time error.
45 </P>
46
47 <A NAME="headers"></A>
48 <H2>Headers</H2>
49
50 <DL class="page-index">
51 <DT><A CLASS="header" HREF="../../../../boost/iostreams/code_converter.hpp"><CODE>&lt;boost/iostreams/code_converter.hpp&gt;</CODE></A></DT>
52 </DL>
53
54 <A NAME="reference"></A>
55 <H2>Reference</H2>
56
57 <H4>Synopsis</H4>
58
59 <PRE CLASS="broken_ie"><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
60
61 <SPAN CLASS="keyword">template</SPAN>&lt; <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Device</A>,
62 <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Codecvt</A> = <SPAN CLASS='omitted'>default_value</SPAN>
63 <SPAN CLASS="keyword">typename</SPAN> <A CLASS="documented" HREF="#template_params">Alloc</A> = std::allocator&lt;<CODE>char</CODE>&gt; &gt;
64 <SPAN CLASS="keyword">class</SPAN> <A CLASS="documented" HREF="#template_params">code_converter</A> {
65 <SPAN CLASS="keyword">public</SPAN>:
66 <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="keyword">typename</SPAN> Codecvt::intern_type char_type;
67 <SPAN CLASS="keyword">typedef</SPAN> <SPAN CLASS="omitted">implementation-defined</SPAN> category;
68 <A CLASS="documented" HREF="#constructors">code_converter</A>();
69 <A CLASS="documented" HREF="#constructors">code_converter</A>( <SPAN CLASS="keyword">const</SPAN> Device&amp; dev,
70 int buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );
71 <A CLASS="documented" HREF="code_converter.html#constructors">code_converter</A>( <SPAN CLASS="omitted">device-constructor-args...</SPAN>,
72 int buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );
73 <SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="code_converter.html#open">open</A>( <SPAN CLASS="keyword">const</SPAN> Device&amp; dev,
74 int buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );
75 <SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="code_converter.html#open">open</A>( <SPAN CLASS="omitted">device-constructor-args...</SPAN>,
76 int buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );
77 <SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
78 <SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#close">close</A>();
79 std::locale <A CLASS="documented" HREF="#imbue">imbue</A>(<SPAN CLASS="keyword">const</SPAN> std::locale&amp; loc);
80 Device&amp; <A CLASS="documented" HREF="#operator_star">operator*</A>();
81 Device* <A CLASS="documented" HREF="#operator_arrow">operator-&gt;</A>();
82 };
83
84 } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE>
85
86 <A NAME="template_params"></A>
87 <H4>Template parameters</H4>
88
89 <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2>
90 <TR>
91 <TR>
92 <TD VALIGN="top"><I>Device</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
93 <TD>A model of one of the <A HREF="../guide/concepts.html#device_concepts">Device</A> concepts; typically has <A HREF="../guide/traits.html#char_type">character type</A> <CODE>char</CODE>.</TD>
94 </TR>
95 <TR>
96 <TD VALIGN="top"><I>Codecvt</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
97 <TD>
98 A standard library codecvt facet, which must be default constructible. If this parameter is not specified,
99 an instance of <CODE>std::codecvt&lt;wchar_t, char, std::mbstate_t&gt;</CODE> will be fetched from the global
100 local when a <CODE>code_converter</CODE> is constructed or opened.
101 </TD>
102 </TR>
103 <TR>
104 <TD VALIGN="top"><I>Alloc</I></TD><TD WIDTH="2em" VALIGN="top">-</TD>
105 <TD>A standard library allocator type (<A CLASS="bib_ref" HREF="../bibliography.html#iso">[ISO]</A>, 20.1.5), used to allocate character buffers</TD>
106 </TR>
107 </TABLE>
108
109 <A NAME="constructors"></A>
110 <H4><CODE>code_converter::code_converter</CODE></H4>
111
112 <PRE CLASS="broken_ie"> code_converter();
113 code_converter( <SPAN CLASS="keyword">const</SPAN> Device&amp; dev,
114 int buffer_size );
115 code_converter( <SPAN CLASS="omitted">device-constructor-args...</SPAN>,
116 int buffer_size );</PRE>
117
118 <P>
119 The first member constructs a <CODE>code_converter</CODE> with no associated instance of the Device type <CODE>Device</CODE>. Before the instance can be used for i/o, the member function <CODE>open()</CODE> must be invoked.
120 </P>
121
122 <P>
123 The second member constructs a <CODE>code_converter</CODE> based on the given instance of <CODE>Device</CODE>. The second parameter determines the size of the buffers or buffers used for code conversion. If a <CODE>std::codecvt</CODE> was specified as a template parameter, an instance of it will be default constructed. Otherwise, a copy of the global <CODE>locale</CODE> will be made, and an instance of <CODE>std::codecvt&lt;wchar_t, char, std::mbstate_t&gt;</CODE> will be fetched from it.
124 </P>
125
126 <P>
127 The third member constructs a <CODE>code_converter</CODE> based on the given instance of <CODE>Device</CODE> constructed with the forwarded arguments. Take care as the <CODE>buffer_size</CODE> can be confused for a constructor argument if it isn't an <CODE>int</CODE>.<br>
128 </P>
129
130 <A NAME="imbue"></A>
131 <H4><CODE>code_converter::imbue</CODE></H4>
132
133 <PRE CLASS="broken_ie"> std::locale imbue(<SPAN CLASS="keyword">const</SPAN> std::locale&amp; loc);</PRE>
134
135 <P>
136 Used to specify a locale from which a <CODE>std::codecvt</CODE> facet will be fetched to perform code conversion. The effect of invoking imbue while code conversion is in progress is undefined.
137 </P>
138
139 <P>
140 This function is a no-op if a <CODE>std::codecvt</CODE> facet was specified as a template parameter.
141 </P>
142
143 <A NAME="open"></A>
144 <H4><CODE>code_converter::open</CODE></H4>
145
146 <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Device&amp; dev,
147 std::streamsize buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );
148 <SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="omitted">device-constructor-args</SPAN>,
149 std::streamsize buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );<br></PRE>
150
151 <P>
152 Associates the given instance of <CODE>Device</CODE> with <CODE>this</CODE> instance of <CODE>code_converter</CODE>, if there is no such instance currently associated; otherwise, throws <CODE>std::ios_base::failure</CODE>. The second parameter determines the size of the buffer or buffers used for code conversion. If a <CODE>std::codecvt</CODE> was specified as a template parameter, an instance of it will be default constructed. Otherwise, a copy of the global <CODE>locale</CODE> will be made, and an instance of <CODE>std::codecvt&lt;wchar_t, char, std::mbstate_t&gt;</CODE> will be fetched from it.
153 </P>
154 <P>
155 The second member constructs a <CODE>Device</CODE> with the forwarded arguments. Take care as the <CODE>buffer_size</CODE> can be confused for a constructor argument if it isn't an <CODE>int</CODE>.
156 </P>
157
158 <A NAME="is_open"></A>
159 <H4><CODE>code_converter::is_open</CODE></H4>
160
161 <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
162
163 <P>Returns true if there is an instance of the Device type <CODE>Device</CODE> associated with <CODE>this</CODE> instance of <CODE>code_converter</CODE>.</P>
164
165 <A NAME="close"></A>
166 <H4><CODE>code_converter::close</CODE></H4>
167
168 <PRE CLASS="broken_ie"> <SPAN CLASS="keyword">void</SPAN> close();</PRE>
169
170 <P>
171 Disassociates from <CODE>this</CODE> instance of <CODE>code_converter</CODE> any instance of the Device type <CODE>Device</CODE> currently associated with it, calling cleanup functions as appropriate and destroying the associated instance of <CODE>Device</CODE>.
172 </P>
173
174 <A NAME="operator_star"></A>
175 <H4><CODE>code_converter::operator*</CODE></H4>
176
177 <PRE CLASS="broken_ie"> Device&amp; operator*();</PRE>
178
179 <P>
180 Returns a reference to the instance of Device associated with this instance of <CODE>code_converter</CODE>, which must be <A HREF="#is_open">open</A>.
181 </P>
182
183 <A NAME="operator_arrow"></A>
184 <H4><CODE>code_converter::operator-></CODE></H4>
185
186 <PRE CLASS="broken_ie"> Device* operator->();</PRE>
187
188 <P>
189 Returns a pointer to the instance of Device associated with this instance of <CODE>code_converter</CODE>, which must be <A HREF="#is_open">open</A>.
190 </P>
191
192 <!-- Begin Footer -->
193
194 <HR>
195
196 <P CLASS="copyright">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>&copy; Copyright 2004-2007 <a href="http://www.coderage.com/turkanis/" target="_top">Jonathan Turkanis</a></P>
197 <P CLASS="copyright">
198 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>)
199 </P>
200
201 <!-- End Footer -->
202
203 </BODY>