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

Ryan Long ryan.long at oarcorp.com
Tue Jul 20 15:06:53 UTC 2021


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

diff --git a/rtemstoolkit/rtems-utils.h b/rtemstoolkit/rtems-utils.h
index 4ce9c68..c4a262e 100644
--- a/rtemstoolkit/rtems-utils.h
+++ b/rtemstoolkit/rtems-utils.h
@@ -47,6 +47,24 @@ 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