3 /// RAII class to save and restore iostream state
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__
33 /// This class saves the following stream settings:
39 /// and restores them in the destructor.
41 class ios_format_state
44 typedef std::ios stream_type
;
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
;
54 explicit ios_format_state(stream_type
&stream
)
56 , m_flags(stream
.flags())
57 , m_precision(stream
.precision())
58 , m_width(stream
.width())
59 , m_fill(stream
.fill())
70 m_stream
.flags(m_flags
);
71 m_stream
.precision(m_precision
);
72 m_stream
.width(m_width
);
73 m_stream
.fill(m_fill
);