[PATCH v3 1/5] rtems-utils.h: Create ostream_guard

Ryan Long ryan.long at oarcorp.com
Wed Jul 21 14:41:51 UTC 2021


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

diff --git a/rtemstoolkit/rtems-utils.h b/rtemstoolkit/rtems-utils.h
index 4ce9c68..c4d227c 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 );
+      }
+    };
+
   }
 }
 
-- 
1.8.3.1



More information about the devel mailing list