summaryrefslogtreecommitdiffstats
path: root/base/scoped_bool.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/scoped_bool.h')
-rw-r--r--base/scoped_bool.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/base/scoped_bool.h b/base/scoped_bool.h
new file mode 100644
index 0000000..0622f967
--- /dev/null
+++ b/base/scoped_bool.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_SCOPED_BOOL_H_
+#define BASE_SCOPED_BOOL_H_
+
+// ScopedBool is useful for setting a flag only during a particular scope. If
+// you have code that has to add "var = false;" at all the exit points of a
+// function, for example, you would benefit from using this instead.
+
+class ScopedBool {
+ public:
+ explicit ScopedBool(bool* scoped_bool) : scoped_bool_(scoped_bool) {
+ *scoped_bool_ = true;
+ }
+ ~ScopedBool() { *scoped_bool_ = false; }
+
+ private:
+ bool* scoped_bool_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedBool);
+};
+
+#endif // BASE_SCOPED_BOOL_H_