1 #ifndef BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP 2 #define BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP 3 4 // MS compatible compilers support #pragma once 5 #if defined(_MSC_VER) 6 # pragma once 7 #endif 8 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 10 // basic_streambuf_locale_saver.hpp 11 12 // (C) Copyright 2005 Robert Ramey - http://www.rrsd.com 13 14 // Use, modification and distribution is subject to the Boost Software 15 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 16 // http://www.boost.org/LICENSE_1_0.txt) 17 18 // See http://www.boost.org for updates, documentation, and revision history. 19 20 // note derived from boost/io/ios_state.hpp 21 // Copyright 2002, 2005 Daryle Walker. Use, modification, and distribution 22 // are subject to the Boost Software License, Version 1.0. (See accompanying 23 // file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) 24 25 // See <http://www.boost.org/libs/io/> for the library's home page. 26 27 #ifndef BOOST_NO_STD_LOCALE 28 29 #include <locale> // for std::locale 30 #include <ios> 31 #include <streambuf> // for std::basic_streambuf 32 33 #include <boost/config.hpp> 34 #include <boost/noncopyable.hpp> 35 36 #ifdef BOOST_MSVC 37 # pragma warning(push) 38 # pragma warning(disable : 4511 4512) 39 #endif 40 41 namespace boost{ 42 namespace archive{ 43 44 template < typename Ch, class Tr > 45 class basic_streambuf_locale_saver : 46 private boost::noncopyable 47 { 48 public: basic_streambuf_locale_saver(std::basic_streambuf<Ch,Tr> & s)49 explicit basic_streambuf_locale_saver(std::basic_streambuf<Ch, Tr> &s) : 50 m_streambuf(s), 51 m_locale(s.getloc()) 52 {} ~basic_streambuf_locale_saver()53 ~basic_streambuf_locale_saver(){ 54 m_streambuf.pubsync(); 55 m_streambuf.pubimbue(m_locale); 56 } 57 private: 58 std::basic_streambuf<Ch, Tr> & m_streambuf; 59 std::locale const m_locale; 60 }; 61 62 template < typename Ch, class Tr > 63 class basic_istream_locale_saver : 64 private boost::noncopyable 65 { 66 public: basic_istream_locale_saver(std::basic_istream<Ch,Tr> & s)67 explicit basic_istream_locale_saver(std::basic_istream<Ch, Tr> &s) : 68 m_istream(s), 69 m_locale(s.getloc()) 70 {} ~basic_istream_locale_saver()71 ~basic_istream_locale_saver(){ 72 // libstdc++ crashes without this 73 m_istream.sync(); 74 m_istream.imbue(m_locale); 75 } 76 private: 77 std::basic_istream<Ch, Tr> & m_istream; 78 std::locale const m_locale; 79 }; 80 81 template < typename Ch, class Tr > 82 class basic_ostream_locale_saver : 83 private boost::noncopyable 84 { 85 public: basic_ostream_locale_saver(std::basic_ostream<Ch,Tr> & s)86 explicit basic_ostream_locale_saver(std::basic_ostream<Ch, Tr> &s) : 87 m_ostream(s), 88 m_locale(s.getloc()) 89 {} ~basic_ostream_locale_saver()90 ~basic_ostream_locale_saver(){ 91 m_ostream.flush(); 92 m_ostream.imbue(m_locale); 93 } 94 private: 95 std::basic_ostream<Ch, Tr> & m_ostream; 96 std::locale const m_locale; 97 }; 98 99 100 } // archive 101 } // boost 102 103 #ifdef BOOST_MSVC 104 #pragma warning(pop) 105 #endif 106 107 #endif // BOOST_NO_STD_LOCALE 108 #endif // BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP 109