]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/serialization/include/boost/archive/basic_streambuf_locale_saver.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / include / boost / archive / basic_streambuf_locale_saver.hpp
CommitLineData
7c673cae
FG
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
41namespace boost{
42namespace archive{
43
44template < typename Ch, class Tr >
45class basic_streambuf_locale_saver :
46 private boost::noncopyable
47{
48public:
49 explicit basic_streambuf_locale_saver(std::basic_streambuf<Ch, Tr> &s) :
50 m_streambuf(s),
51 m_locale(s.getloc())
52 {}
53 ~basic_streambuf_locale_saver(){
54 m_streambuf.pubsync();
55 m_streambuf.pubimbue(m_locale);
56 }
57private:
58 std::basic_streambuf<Ch, Tr> & m_streambuf;
59 std::locale const m_locale;
60};
61
62template < typename Ch, class Tr >
63class basic_istream_locale_saver :
64 private boost::noncopyable
65{
66public:
67 explicit basic_istream_locale_saver(std::basic_istream<Ch, Tr> &s) :
68 m_istream(s),
69 m_locale(s.getloc())
70 {}
71 ~basic_istream_locale_saver(){
72 // libstdc++ crashes without this
73 m_istream.sync();
74 m_istream.imbue(m_locale);
75 }
76private:
77 std::basic_istream<Ch, Tr> & m_istream;
78 std::locale const m_locale;
79};
80
81template < typename Ch, class Tr >
82class basic_ostream_locale_saver :
83 private boost::noncopyable
84{
85public:
86 explicit basic_ostream_locale_saver(std::basic_ostream<Ch, Tr> &s) :
87 m_ostream(s),
88 m_locale(s.getloc())
89 {}
90 ~basic_ostream_locale_saver(){
91 m_ostream.flush();
92 m_ostream.imbue(m_locale);
93 }
94private:
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