Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: third_party/cld/base/varsetter.h

Issue 1956183002: CL for perf tryjob on linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/cld/base/varsetter.h
diff --git a/third_party/cld/base/varsetter.h b/third_party/cld/base/varsetter.h
new file mode 100644
index 0000000000000000000000000000000000000000..c51d5c0dc6815eba245c01795fcc7861b135fa1e
--- /dev/null
+++ b/third_party/cld/base/varsetter.h
@@ -0,0 +1,57 @@
+//
+// Copyright (C) 1999 and onwards Google, Inc.
+//
+// Author: Ray Sidney
+//
+#ifndef BASE_VARSETTER_H_
+#define BASE_VARSETTER_H_
+
+//#include "base/port.h"
+
+//
+// Use a VarSetter object to temporarily set an object of some sort to
+// a particular value. When the VarSetter object is destructed, the
+// underlying object will revert to its former value.
+//
+// Sample code:
+//
+#if 0
+{
+ bool b = true;
+ {
+ VarSetter<bool> bool_setter(&b, false);
+ // Now b == false.
+ }
+ // Now b == true again.
+}
+#endif
+
+template <class C>
+class VarSetter {
+public:
+
+ // Constructor that just sets the object to a fixed value
+ VarSetter(C* object, const C& value) : object_(object), old_value_(*object) {
+ *object = value;
+ }
+
+ ~VarSetter() { *object_ = old_value_; }
+
+private:
+
+ C*const object_;
+ C old_value_;
+
+ // Disallow
+ VarSetter(const VarSetter&);
+ VarSetter& operator=(const VarSetter&);
+
+ // VarSetters always live on the stack
+ static void* operator new (size_t);
+ static void* operator new[](size_t); // Redundant, no default ctor
+
+ static void operator delete (void*);
+ static void operator delete[](void*);
+};
+
+#endif // BASE_VARSETTER_H_
« no previous file with comments | « third_party/cld/base/commandlineflags.h ('k') | third_party/cld/encodings/compact_enc_det/compact_enc_det.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698