summaryrefslogtreecommitdiff
path: root/absl/flags/reflection.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/flags/reflection.h')
-rw-r--r--absl/flags/reflection.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/absl/flags/reflection.h b/absl/flags/reflection.h
index e8e24f68..045f9784 100644
--- a/absl/flags/reflection.h
+++ b/absl/flags/reflection.h
@@ -31,6 +31,9 @@
namespace absl {
ABSL_NAMESPACE_BEGIN
+namespace flags_internal {
+class FlagSaverImpl;
+} // namespace flags_internal
// FindCommandLineFlag()
//
@@ -39,6 +42,41 @@ ABSL_NAMESPACE_BEGIN
// 'retired' flag is specified.
CommandLineFlag* FindCommandLineFlag(absl::string_view name);
+//------------------------------------------------------------------------------
+// FlagSaver
+//------------------------------------------------------------------------------
+//
+// A FlagSaver object stores the state of flags in the scope where the FlagSaver
+// is defined, allowing modification of those flags within that scope and
+// automatic restoration of the flags to their previous state upon leaving the
+// scope.
+//
+// A FlagSaver can be used within tests to temporarily change the test
+// environment and restore the test case to its previous state.
+//
+// Example:
+//
+// void MyFunc() {
+// absl::FlagSaver fs;
+// ...
+// absl::SetFlag(FLAGS_myFlag, otherValue);
+// ...
+// } // scope of FlagSaver left, flags return to previous state
+//
+// This class is thread-safe.
+
+class FlagSaver {
+ public:
+ FlagSaver();
+ ~FlagSaver();
+
+ FlagSaver(const FlagSaver&) = delete;
+ void operator=(const FlagSaver&) = delete;
+
+ private:
+ flags_internal::FlagSaverImpl* impl_;
+};
+
//-----------------------------------------------------------------------------
ABSL_NAMESPACE_END