-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathFmtSaver.h
37 lines (25 loc) · 973 Bytes
/
FmtSaver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//-----------------------------------------------------------------------------
/** @file libboardgame_base/FmtSaver.h
@author Markus Enzenberger
@copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------
#ifndef LIBBOARDGAME_BASE_FMT_SAVER_H
#define LIBBOARDGAME_BASE_FMT_SAVER_H
#include <iostream>
namespace libboardgame_base {
using namespace std;
//-----------------------------------------------------------------------------
/** Saves the formatting state of a stream and restores it in its
destructor. */
class FmtSaver
{
public:
explicit FmtSaver(ostream& out) : m_out(out) { m_dummy.copyfmt(out); }
~FmtSaver() { m_out.copyfmt(m_dummy); }
private:
ostream& m_out;
ios m_dummy{nullptr};
};
//-----------------------------------------------------------------------------
} // namespace libboardgame_base
#endif // LIBBOARDGAME_BASE_FMT_SAVER_H