Block-Structured AMR Software Framework
AMReX_IOFormat.H
Go to the documentation of this file.
1 #ifndef AMREX_IO_FORMAT_H_
2 #define AMREX_IO_FORMAT_H_
3 
4 #include <ios>
5 
6 namespace amrex {
7 
8 /*
9  * \brief I/O stream format saver
10  *
11  * This class can be used to save and restore I/O stream format in a RAII
12  * way. It handles fill, fmtflag, precision, and width.
13  */
14 template <class CharT, class Traits>
16 {
17 public:
18  using BasicIos = std::basic_ios<CharT, Traits>;
19 
20  explicit IOFormatSaver (BasicIos& ios)
21  : m_ios(&ios),
22  m_fill(ios.fill()),
23  m_flags(ios.flags()),
24  m_precision(ios.precision()),
25  m_width(ios.width())
26  {}
27 
29  {
30  m_ios->fill(m_fill);
31  m_ios->flags(m_flags);
32  m_ios->precision(m_precision);
33  m_ios->width(m_width);
34  }
35 
36  IOFormatSaver (IOFormatSaver const&) = delete;
37  IOFormatSaver (IOFormatSaver &&) noexcept = delete;
38  IOFormatSaver& operator= (IOFormatSaver const&) = delete;
39  IOFormatSaver& operator= (IOFormatSaver &&) noexcept = delete;
40 
41 private:
43  CharT m_fill;
44  typename BasicIos::fmtflags m_flags;
45  std::streamsize m_precision;
46  std::streamsize m_width;
47 };
48 
49 }
50 
51 #endif
Definition: AMReX_IOFormat.H:16
std::streamsize m_precision
Definition: AMReX_IOFormat.H:45
BasicIos * m_ios
Definition: AMReX_IOFormat.H:42
~IOFormatSaver()
Definition: AMReX_IOFormat.H:28
BasicIos::fmtflags m_flags
Definition: AMReX_IOFormat.H:44
IOFormatSaver(BasicIos &ios)
Definition: AMReX_IOFormat.H:20
std::streamsize m_width
Definition: AMReX_IOFormat.H:46
IOFormatSaver(IOFormatSaver const &)=delete
std::basic_ios< CharT, Traits > BasicIos
Definition: AMReX_IOFormat.H:18
IOFormatSaver(IOFormatSaver &&) noexcept=delete
CharT m_fill
Definition: AMReX_IOFormat.H:43
Definition: AMReX_Amr.cpp:49
void fill(BaseFab< STRUCT > &aos_fab, F const &f)
Definition: AMReX_BaseFabUtility.H:29