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 <streambuf> // for std::basic_streambuf 31 32 #include <boost/config.hpp> 33 #include <boost/noncopyable.hpp> 34 35 #ifdef BOOST_MSVC 36 # pragma warning(push) 37 # pragma warning(disable : 4511 4512) 38 #endif 39 40 namespace boost{ 41 namespace archive{ 42 43 template < typename Ch, class Tr > 44 class basic_streambuf_locale_saver : 45 private boost::noncopyable 46 { 47 public: 48 typedef ::std::basic_streambuf<Ch, Tr> state_type; 49 typedef ::std::locale aspect_type; basic_streambuf_locale_saver(state_type & s)50 explicit basic_streambuf_locale_saver( state_type &s ) 51 : s_save_( s ), a_save_( s.getloc() ) 52 {} basic_streambuf_locale_saver(state_type & s,aspect_type const & a)53 explicit basic_streambuf_locale_saver( state_type &s, aspect_type const &a ) 54 : s_save_( s ), a_save_( s.pubimbue(a) ) 55 {} ~basic_streambuf_locale_saver()56 ~basic_streambuf_locale_saver() 57 { this->restore(); } restore()58 void restore(){ 59 s_save_.pubsync(); 60 s_save_.pubimbue( a_save_ ); 61 } 62 private: 63 state_type & s_save_; 64 aspect_type const a_save_; 65 }; 66 67 } // archive 68 } // boost 69 70 #ifdef BOOST_MSVC 71 #pragma warning(pop) 72 #endif 73 74 #endif // BOOST_NO_STD_LOCALE 75 #endif // BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP 76