basic_streambuf_locale_saver.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP
  2. #define BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // basic_streambuf_local_saver.hpp
  9. // (C) Copyright 2005 Robert Ramey - http://www.rrsd.com
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. // note derived from boost/io/ios_state.hpp
  15. // Copyright 2002, 2005 Daryle Walker. Use, modification, and distribution
  16. // are subject to the Boost Software License, Version 1.0. (See accompanying
  17. // file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
  18. // See <http://www.boost.org/libs/io/> for the library's home page.
  19. #ifndef BOOST_NO_STD_LOCALE
  20. #include <locale> // for std::locale
  21. #include <streambuf> // for std::basic_streambuf
  22. #include <boost/config.hpp>
  23. #include <boost/noncopyable.hpp>
  24. #ifdef BOOST_MSVC
  25. # pragma warning(push)
  26. # pragma warning(disable : 4511 4512)
  27. #endif
  28. namespace boost{
  29. namespace archive{
  30. template < typename Ch, class Tr >
  31. class basic_streambuf_locale_saver :
  32. private boost::noncopyable
  33. {
  34. public:
  35. typedef ::std::basic_streambuf<Ch, Tr> state_type;
  36. typedef ::std::locale aspect_type;
  37. explicit basic_streambuf_locale_saver( state_type &s )
  38. : s_save_( s ), a_save_( s.getloc() )
  39. {}
  40. basic_streambuf_locale_saver( state_type &s, aspect_type const &a )
  41. : s_save_( s ), a_save_( s.pubimbue(a) )
  42. {}
  43. ~basic_streambuf_locale_saver()
  44. { this->restore(); }
  45. void restore()
  46. { s_save_.pubimbue( a_save_ ); }
  47. private:
  48. state_type & s_save_;
  49. aspect_type const a_save_;
  50. };
  51. } // archive
  52. } // boost
  53. #ifdef BOOST_MSVC
  54. #pragma warning(pop)
  55. #endif
  56. #endif // BOOST_NO_STD_LOCALE
  57. #endif // BOOST_ARCHIVE_BASIC_STREAMBUF_LOCALE_SAVER_HPP