Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:29

0001 #ifndef BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP
0002 #define BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // basic_streambuf_locale_saver.hpp
0011 
0012 // (C) Copyright 2005 Robert Ramey - http://www.rrsd.com
0013 
0014 // Use, modification and distribution is subject to the Boost Software
0015 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0016 // http://www.boost.org/LICENSE_1_0.txt)
0017 
0018 //  See http://www.boost.org for updates, documentation, and revision history.
0019 
0020 // note derived from boost/io/ios_state.hpp
0021 // Copyright 2002, 2005 Daryle Walker.  Use, modification, and distribution
0022 // are subject to the Boost Software License, Version 1.0.  (See accompanying
0023 // file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
0024 
0025 //  See <http://www.boost.org/libs/io/> for the library's home page.
0026 
0027 #ifndef BOOST_NO_STD_LOCALE
0028 
0029 #include <locale>     // for std::locale
0030 #include <ios>
0031 #include <streambuf>  // for std::basic_streambuf
0032 
0033 #include <boost/config.hpp>
0034 #include <boost/noncopyable.hpp>
0035 
0036 #ifdef BOOST_MSVC
0037 #  pragma warning(push)
0038 #  pragma warning(disable : 4511 4512)
0039 #endif
0040 
0041 namespace boost{
0042 namespace archive{
0043 
0044 template < typename Ch, class Tr >
0045 class basic_streambuf_locale_saver :
0046     private boost::noncopyable
0047 {
0048 public:
0049     explicit basic_streambuf_locale_saver(std::basic_streambuf<Ch, Tr> &s) :
0050         m_streambuf(s),
0051         m_locale(s.getloc())
0052     {}
0053     ~basic_streambuf_locale_saver(){
0054         m_streambuf.pubsync();
0055         m_streambuf.pubimbue(m_locale);
0056     }
0057 private:
0058     std::basic_streambuf<Ch, Tr> &       m_streambuf;
0059     std::locale const  m_locale;
0060 };
0061 
0062 template < typename Ch, class Tr >
0063 class basic_istream_locale_saver :
0064     private boost::noncopyable
0065 {
0066 public:
0067     explicit basic_istream_locale_saver(std::basic_istream<Ch, Tr> &s) :
0068         m_istream(s),
0069         m_locale(s.getloc())
0070     {}
0071     ~basic_istream_locale_saver(){
0072         // libstdc++ crashes without this
0073         m_istream.sync();
0074         m_istream.imbue(m_locale);
0075     }
0076 private:
0077     std::basic_istream<Ch, Tr> & m_istream;
0078     std::locale const  m_locale;
0079 };
0080 
0081 template < typename Ch, class Tr >
0082 class basic_ostream_locale_saver :
0083     private boost::noncopyable
0084 {
0085 public:
0086     explicit basic_ostream_locale_saver(std::basic_ostream<Ch, Tr> &s) :
0087         m_ostream(s),
0088         m_locale(s.getloc())
0089     {}
0090     ~basic_ostream_locale_saver(){
0091         m_ostream.flush();
0092         m_ostream.imbue(m_locale);
0093     }
0094 private:
0095     std::basic_ostream<Ch, Tr> & m_ostream;
0096     std::locale const  m_locale;
0097 };
0098 
0099 
0100 } // archive
0101 } // boost
0102 
0103 #ifdef BOOST_MSVC
0104 #pragma warning(pop)
0105 #endif
0106 
0107 #endif // BOOST_NO_STD_LOCALE
0108 #endif // BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP