| 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>  typically <CODE>char</CODE>  and produces a Device with wide character type  typically <CODE>wchar_t</CODE>  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"><boost/iostreams/maped_file.hpp></SPAN></A> | 
|---|
| 34 |  | 
|---|
| 35 |     <SPAN CLASS="keyword">typedef</SPAN> code_converter<mapped_file_source> 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"><boost/iostreams/device/array.hpp></SPAN></A> | 
|---|
| 40 |  | 
|---|
| 41 |     <SPAN CLASS="keyword">typedef</SPAN> code_converter<array_sink> 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><boost/iostreams/code_converter.hpp></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>< <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<<CODE>char</CODE>> > | 
|---|
| 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& dev,  | 
|---|
| 70 |                     std::streamsize buffer_size = <SPAN CLASS="omitted">default_value</SPAN> ); | 
|---|
| 71 |     <SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#open">open</A>( <SPAN CLASS="keyword">const</SPAN> Device& dev,  | 
|---|
| 72 |                std::streamsize buffer_size = <SPAN CLASS="omitted">default_value</SPAN> ); | 
|---|
| 73 |     <SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>; | 
|---|
| 74 |     <SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#close">close</A>(); | 
|---|
| 75 |     std::locale <A CLASS="documented" HREF="#imbue">imbue</A>(<SPAN CLASS="keyword">const</SPAN> std::locale& loc);  | 
|---|
| 76 |     Device& <A CLASS="documented" HREF="#operator_star">operator*</A>(); | 
|---|
| 77 |     Device* <A CLASS="documented" HREF="#operator_arrow">operator-></A>(); | 
|---|
| 78 | }; | 
|---|
| 79 |  | 
|---|
| 80 | } } <SPAN CLASS="comment">// End namespace boost::io</SPAN></PRE> | 
|---|
| 81 |  | 
|---|
| 82 | <A NAME="template_params"></A> | 
|---|
| 83 | <H4>Template parameters</H4> | 
|---|
| 84 |  | 
|---|
| 85 | <TABLE STYLE="margin-left:2em" BORDER=0 CELLPADDING=2> | 
|---|
| 86 | <TR> | 
|---|
| 87 |     <TR> | 
|---|
| 88 |         <TD VALIGN="top"><I>Device</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> | 
|---|
| 89 |         <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> | 
|---|
| 90 |     </TR> | 
|---|
| 91 |     <TR> | 
|---|
| 92 |         <TD VALIGN="top"><I>Codecvt</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> | 
|---|
| 93 |         <TD> | 
|---|
| 94 |             A standard library codecvt facet, which must be default constructible. If this parameter is not specified, | 
|---|
| 95 |             an instance of <CODE>std::codecvt<wchar_t, char, std::mbstate_t></CODE> will be fetched from the global | 
|---|
| 96 |             local when a <CODE>code_converter</CODE> is constructed or opened. | 
|---|
| 97 |         </TD> | 
|---|
| 98 |     </TR> | 
|---|
| 99 |     <TR> | 
|---|
| 100 |         <TD VALIGN="top"><I>Alloc</I></TD><TD WIDTH="2em" VALIGN="top">-</TD> | 
|---|
| 101 |         <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> | 
|---|
| 102 |     </TR> | 
|---|
| 103 | </TABLE> | 
|---|
| 104 |  | 
|---|
| 105 | <A NAME="constructors"></A> | 
|---|
| 106 | <H4><CODE>code_converter::code_converter</CODE></H4> | 
|---|
| 107 |  | 
|---|
| 108 | <PRE CLASS="broken_ie">    code_converter(); | 
|---|
| 109 |     code_converter( <SPAN CLASS="keyword">const</SPAN> Device& dev,  | 
|---|
| 110 |                     std::streamsize buffer_size );</PRE> | 
|---|
| 111 |      | 
|---|
| 112 | <P> | 
|---|
| 113 |     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.  | 
|---|
| 114 | </P> | 
|---|
| 115 |      | 
|---|
| 116 | <P> | 
|---|
| 117 |     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<wchar_t, char, std::mbstate_t></CODE> will be fetched from it. | 
|---|
| 118 | </P> | 
|---|
| 119 |  | 
|---|
| 120 | <A NAME="imbue"></A> | 
|---|
| 121 | <H4><CODE>code_converter::imbue</CODE></H4> | 
|---|
| 122 |  | 
|---|
| 123 | <PRE CLASS="broken_ie">    std::locale imbue(<SPAN CLASS="keyword">const</SPAN> std::locale& loc);</PRE> | 
|---|
| 124 |  | 
|---|
| 125 | <P> | 
|---|
| 126 |     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. | 
|---|
| 127 | </P> | 
|---|
| 128 |  | 
|---|
| 129 | <P> | 
|---|
| 130 |     This function is a no-op if a <CODE>std::codecvt</CODE> facet was specified as a template parameter. | 
|---|
| 131 | </P> | 
|---|
| 132 |  | 
|---|
| 133 | <A NAME="open"></A> | 
|---|
| 134 | <H4><CODE>code_converter::open</CODE></H4> | 
|---|
| 135 |  | 
|---|
| 136 | <PRE CLASS="broken_ie">     <SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Device& dev,  | 
|---|
| 137 |                 std::streamsize buffer_size = <SPAN CLASS="omitted">default_value</SPAN> );</PRE> | 
|---|
| 138 |  | 
|---|
| 139 | <P> | 
|---|
| 140 |     Assocaites 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<wchar_t, char, std::mbstate_t></CODE> will be fetched from it. | 
|---|
| 141 | </P> | 
|---|
| 142 |  | 
|---|
| 143 | <A NAME="is_open"></A> | 
|---|
| 144 | <H4><CODE>code_converter::is_open</CODE></H4> | 
|---|
| 145 |  | 
|---|
| 146 | <PRE CLASS="broken_ie">    <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE> | 
|---|
| 147 |  | 
|---|
| 148 | <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> | 
|---|
| 149 |  | 
|---|
| 150 | <A NAME="close"></A> | 
|---|
| 151 | <H4><CODE>code_converter::close</CODE></H4> | 
|---|
| 152 |  | 
|---|
| 153 | <PRE CLASS="broken_ie">    <SPAN CLASS="keyword">void</SPAN> close();</PRE> | 
|---|
| 154 |  | 
|---|
| 155 | <P> | 
|---|
| 156 |     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>. | 
|---|
| 157 | </P> | 
|---|
| 158 |  | 
|---|
| 159 | <A NAME="operator_star"></A> | 
|---|
| 160 | <H4><CODE>code_converter::operator*</CODE></H4> | 
|---|
| 161 |  | 
|---|
| 162 | <PRE CLASS="broken_ie">    Device& operator*();</PRE> | 
|---|
| 163 |  | 
|---|
| 164 | <P> | 
|---|
| 165 |      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>. | 
|---|
| 166 | </P> | 
|---|
| 167 |  | 
|---|
| 168 | <A NAME="operator_arrow"></A> | 
|---|
| 169 | <H4><CODE>code_converter::operator-></CODE></H4> | 
|---|
| 170 |  | 
|---|
| 171 | <PRE CLASS="broken_ie">    Device* operator->();</PRE> | 
|---|
| 172 |  | 
|---|
| 173 | <P> | 
|---|
| 174 |     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>. | 
|---|
| 175 | </P> | 
|---|
| 176 |      | 
|---|
| 177 | <!-- Begin Footer --> | 
|---|
| 178 |  | 
|---|
| 179 | <HR> | 
|---|
| 180 | <P CLASS="copyright">Revised | 
|---|
| 181 | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> | 
|---|
| 182 | 20 May, 2004 | 
|---|
| 183 | <!--webbot bot="Timestamp" endspan i-checksum="38504" --> | 
|---|
| 184 | </P> | 
|---|
| 185 |  | 
|---|
| 186 | <P CLASS="copyright">© Copyright <A HREF="http://www.kangaroologic.com" TARGET="_top">Jonathan Turkanis</A>, 2004</P> | 
|---|
| 187 | <P CLASS="copyright">  | 
|---|
| 188 |     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>) | 
|---|
| 189 | </P> | 
|---|
| 190 |  | 
|---|
| 191 | <!-- End Footer --> | 
|---|
| 192 |  | 
|---|
| 193 | </BODY> | 
|---|