1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 // Contains machinery for performing code conversion.
10 #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED
11 #define BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED
17 #include <cwchar> // mbstate_t.
18 #include <locale> // codecvt, locale.
19 #include <boost/config.hpp> // HAS_MACRO_USE_FACET.
20 #include <boost/iostreams/detail/config/codecvt.hpp>
22 namespace boost { namespace iostreams { namespace detail {
24 struct default_codecvt {
25 typedef wchar_t intern_type, from_type;
26 typedef char extern_type, to_type;
27 typedef std::mbstate_t state_type;
30 template<typename Codecvt>
31 struct codecvt_holder {
32 typedef Codecvt codecvt_type;
33 const codecvt_type& get() const { return codecvt_; }
34 void imbue(const std::locale&) { }
39 struct codecvt_holder<default_codecvt> {
40 typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
41 codecvt_holder() { reset_codecvt(); }
42 const codecvt_type& get() const { return *codecvt_; }
43 void imbue(const std::locale& loc)
51 #ifndef BOOST_HAS_MACRO_USE_FACET
52 codecvt_ = & use_facet< codecvt_type >(loc_);
54 codecvt_ = & _USE(loc_, codecvt_type);
57 std::locale loc_; // Prevent codecvt_ from being freed.
58 const codecvt_type* codecvt_;
61 } } } // End namespaces detail, iostreams, boost.
63 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED