Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: // Contains machinery for performing code conversion. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include // mbstate_t. Chris@16: #include // codecvt, locale. Chris@16: #include // HAS_MACRO_USE_FACET. Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: struct default_codecvt { Chris@16: typedef wchar_t intern_type, from_type; Chris@16: typedef char extern_type, to_type; Chris@16: typedef std::mbstate_t state_type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct codecvt_holder { Chris@16: typedef Codecvt codecvt_type; Chris@16: const codecvt_type& get() const { return codecvt_; } Chris@16: void imbue(const std::locale&) { } Chris@16: Codecvt codecvt_; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct codecvt_holder { Chris@16: typedef std::codecvt codecvt_type; Chris@16: codecvt_holder() { reset_codecvt(); } Chris@16: const codecvt_type& get() const { return *codecvt_; } Chris@16: void imbue(const std::locale& loc) Chris@16: { Chris@16: loc_ = loc; Chris@16: reset_codecvt(); Chris@16: } Chris@16: void reset_codecvt() Chris@16: { Chris@16: using namespace std; Chris@16: #ifndef BOOST_HAS_MACRO_USE_FACET Chris@16: codecvt_ = & use_facet< codecvt_type >(loc_); Chris@16: #else Chris@16: codecvt_ = & _USE(loc_, codecvt_type); Chris@16: #endif Chris@16: } Chris@16: std::locale loc_; // Prevent codecvt_ from being freed. Chris@16: const codecvt_type* codecvt_; Chris@16: }; Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HOLDER_HPP_INCLUDED