pstore2
ios_state.hpp
Go to the documentation of this file.
1 //===- include/pstore/support/ios_state.hpp ---------------*- mode: C++ -*-===//
2 //* _ _ _ *
3 //* (_) ___ ___ ___| |_ __ _| |_ ___ *
4 //* | |/ _ \/ __| / __| __/ _` | __/ _ \ *
5 //* | | (_) \__ \ \__ \ || (_| | || __/ *
6 //* |_|\___/|___/ |___/\__\__,_|\__\___| *
7 //* *
8 //===----------------------------------------------------------------------===//
9 //
10 // Part of the pstore project, under the Apache License v2.0 with LLVM Exceptions.
11 // See https://github.com/SNSystems/pstore/blob/master/LICENSE.txt for license
12 // information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //===----------------------------------------------------------------------===//
18 
19 #ifndef PSTORE_SUPPORT_IOS_STATE_HPP
20 #define PSTORE_SUPPORT_IOS_STATE_HPP
21 
22 #include <iosfwd>
23 
24 #include "pstore/support/portab.hpp"
25 
26 namespace pstore {
27 
33  public:
34  explicit ios_flags_saver (std::ios_base & stream)
35  : ios_flags_saver (stream, stream.flags ()) {}
36 
37  ios_flags_saver (std::ios_base & stream, std::ios_base::fmtflags const & flags) noexcept
38  : stream_{stream}
39  , flags_{flags} {}
40  // No copying, moving, or assignment.
41  ios_flags_saver (ios_flags_saver const &) = delete;
42  ios_flags_saver (ios_flags_saver && rhs) noexcept = delete;
43 
44  ~ios_flags_saver () noexcept {
45  no_ex_escape ([this] () { stream_.flags (flags_); });
46  }
47 
48  // No copying, moving, or assignment.
49  ios_flags_saver & operator= (ios_flags_saver const &) = delete;
50  ios_flags_saver & operator= (ios_flags_saver && rhs) = delete;
51 
52  private:
53  std::ios_base & stream_;
54  std::ios_base::fmtflags flags_;
55  };
56 
57 } // namespace pstore
58 
59 #endif // PSTORE_SUPPORT_IOS_STATE_HPP
Definition: nonpod2.cpp:40
A class used to save an iostream&#39;s formatting flags on construction and restore them on destruction...
Definition: ios_state.hpp:32