source: NonGTP/Boost/boost/iostreams/detail/codecvt_holder.hpp @ 857

Revision 857, 1.9 KB checked in by igarcia, 18 years ago (diff)
Line 
1// (C) Copyright Jonathan Turkanis 2003.
2// Distributed under the Boost Software License, Version 1.0. (See accompanying
3// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
4
5// See http://www.boost.org/libs/iostreams for documentation.
6
7// Contains machinery for performing code conversion.
8
9#ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED
10#define BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED
11
12#if defined(_MSC_VER) && (_MSC_VER >= 1020)
13# pragma once
14#endif
15
16#include <cwchar>            // mbstate_t.
17#include <locale>            // codecvt, locale.
18#include <boost/config.hpp>  // HAS_MACRO_USE_FACET.
19#include <boost/iostreams/detail/config/codecvt.hpp>
20
21namespace boost { namespace iostreams { namespace detail {
22
23struct default_codecvt {
24    typedef wchar_t         intern_type, from_type;
25    typedef char            extern_type, to_type;
26    typedef std::mbstate_t  state_type;
27};
28
29template<typename Codecvt>
30struct codecvt_holder {
31    typedef Codecvt codecvt_type;
32    const codecvt_type& get() const { return codecvt_; }
33    void imbue(const std::locale& loc) { }
34    Codecvt codecvt_;
35};
36
37template<>
38struct codecvt_holder<default_codecvt> {
39    typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
40    codecvt_holder() { reset_codecvt(); }
41    const codecvt_type& get() const { return *codecvt_; }
42    void imbue(const std::locale& loc)
43    {
44        loc_ = loc;
45        reset_codecvt();
46    }
47    void reset_codecvt()
48    {
49        using namespace std;
50        #ifndef BOOST_HAS_MACRO_USE_FACET
51            codecvt_ = & use_facet< codecvt_type >(loc_);
52        #else
53            codecvt_ = & _USE(loc_, codecvt_type);
54        #endif
55    }
56    std::locale loc_; // Prevent codecvt_ from being freed.
57    const codecvt_type* codecvt_;
58};
59
60} } } // End namespaces detail, iostreams, boost.
61
62#endif // #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.