Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-10 07:48:43

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <ios>
0012 #include <ostream>
0013 
0014 namespace Acts::detail {
0015 
0016 /// @brief Restore an output stream's formatting state on scope exit.
0017 ///
0018 /// This keeps diagnostic output helpers from leaking persistent manipulators
0019 /// such as std::fixed, std::setprecision, std::setfill, or std::boolalpha into
0020 /// the stream provided by the caller.
0021 class OstreamStateGuard {
0022  public:
0023   explicit OstreamStateGuard(std::ostream& stream)
0024       : m_stream(&stream),
0025         m_flags(stream.flags()),
0026         m_precision(stream.precision()),
0027         m_width(stream.width()),
0028         m_fill(stream.fill()) {}
0029 
0030   ~OstreamStateGuard() noexcept {
0031     m_stream->flags(m_flags);
0032     m_stream->precision(m_precision);
0033     m_stream->width(m_width);
0034     m_stream->fill(m_fill);
0035   }
0036 
0037   OstreamStateGuard(const OstreamStateGuard&) = delete;
0038   OstreamStateGuard& operator=(const OstreamStateGuard&) = delete;
0039   OstreamStateGuard(OstreamStateGuard&&) = delete;
0040   OstreamStateGuard& operator=(OstreamStateGuard&&) = delete;
0041 
0042  private:
0043   std::ostream* m_stream{};
0044   std::ios_base::fmtflags m_flags{};
0045   std::streamsize m_precision{};
0046   std::streamsize m_width{};
0047   char m_fill{};
0048 };
0049 
0050 }  // namespace Acts::detail