[rtems-tools commit] rtems-utils.h: Create ostream_guard

Joel Sherrill joel at rtems.org
Tue Jul 27 18:42:01 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    68348ad39f44255087d9aa3edcd9d91f935e9db6
Changeset: http://git.rtems.org/rtems-tools/commit/?id=68348ad39f44255087d9aa3edcd9d91f935e9db6

Author:    Ryan Long <ryan.long at oarcorp.com>
Date:      Tue Jul 20 09:51:34 2021 -0400

rtems-utils.h: Create ostream_guard

---

 rtemstoolkit/rtems-utils.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/rtemstoolkit/rtems-utils.h b/rtemstoolkit/rtems-utils.h
index 4ce9c68..81bf913 100644
--- a/rtemstoolkit/rtems-utils.h
+++ b/rtemstoolkit/rtems-utils.h
@@ -47,6 +47,26 @@ namespace rtems
                bool        real = false,
                size_t      line_length = 16,
                uint32_t    offset = 0);
+
+    /*
+     * Save and restore the output stream's settings.
+     */
+    struct ostream_guard {
+      std::ostream&           o;
+      std::ios_base::fmtflags flags;
+
+      ostream_guard (std::ostream& o_)
+        : o (o_),
+          flags (o_.flags ())
+      {
+      }
+
+      ~ostream_guard ()
+      {
+        o.flags(flags);
+      }
+    };
+
   }
 }
 



More information about the vc mailing list