menu: added new Keywords tag to .desktop files
[barry.git] / src / ios_state.h
blob6a1f50e3b8104db82b8c62d2870bf0baceaa02d3
1 ///
2 /// \file ios_state.h
3 /// RAII class to save and restore iostream state
4 ///
6 /*
7 Copyright (C) 2011-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_IOS_STATE_H__
23 #define __BARRY_IOS_STATE_H__
25 #include <ios>
26 #include <ostream>
28 namespace Barry {
31 // ios_format_state
33 /// This class saves the following stream settings:
34 /// - flags
35 /// - precision
36 /// - width
37 /// - fill character
38 ///
39 /// and restores them in the destructor.
40 ///
41 class ios_format_state
43 public:
44 typedef std::ios stream_type;
46 private:
47 stream_type &m_stream;
48 std::ios_base::fmtflags m_flags;
49 std::streamsize m_precision;
50 std::streamsize m_width;
51 stream_type::char_type m_fill;
53 public:
54 explicit ios_format_state(stream_type &stream)
55 : m_stream(stream)
56 , m_flags(stream.flags())
57 , m_precision(stream.precision())
58 , m_width(stream.width())
59 , m_fill(stream.fill())
63 ~ios_format_state()
65 restore();
68 void restore()
70 m_stream.flags(m_flags);
71 m_stream.precision(m_precision);
72 m_stream.width(m_width);
73 m_stream.fill(m_fill);
79 #endif