Lumiera  0.pre.03
»edit your freedom«
ios-savepoint.hpp
Go to the documentation of this file.
1 /*
2  IOS-SAVEPOINT.hpp - capture and restore std::ostream format settings
3 
4  Copyright (C) Lumiera.org
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
43 #ifndef LIB_IOS_SAVEPOINT_H
44 #define LIB_IOS_SAVEPOINT_H
45 
46 #include "lib/nocopy.hpp"
47 
48 #include <ostream>
49 
50 
51 
52 namespace util {
53 
59  : MoveOnly
60  {
61  std::ostream& theStream_;
62  std::ios_base::fmtflags prevFlags_;
63  char fillChar_;
64 
65  public:
66  explicit
67  IosSavepoint(std::ostream& stream_to_capture)
68  : theStream_{stream_to_capture}
69  , prevFlags_{theStream_.flags()}
70  , fillChar_{theStream_.fill()}
71  { }
72 
73  ~IosSavepoint()
74  {
75  theStream_.flags(prevFlags_);
76  theStream_.fill(fillChar_);
77  }
78  };
79 
80 
81 } // namespace util
82 #endif /*LIB_IOS_SAVEPOINT_H*/
Types marked with this mix-in may be moved but not copied.
Definition: nocopy.hpp:58
Mix-Ins to allow or prohibit various degrees of copying and cloning.
RAII helper to capture and restore output stream format settings.