summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_autorestorer.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/cfx_autorestorer.h')
-rw-r--r--core/fxcrt/cfx_autorestorer.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_autorestorer.h b/core/fxcrt/cfx_autorestorer.h
new file mode 100644
index 0000000000..a8c5125c4e
--- /dev/null
+++ b/core/fxcrt/cfx_autorestorer.h
@@ -0,0 +1,20 @@
+// Copyright 2017 PDFium 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 CORE_FXCRT_CFX_AUTORESTORER_H_
+#define CORE_FXCRT_CFX_AUTORESTORER_H_
+
+template <typename T>
+class CFX_AutoRestorer {
+ public:
+ explicit CFX_AutoRestorer(T* location)
+ : m_Location(location), m_OldValue(*location) {}
+ ~CFX_AutoRestorer() { *m_Location = m_OldValue; }
+
+ private:
+ T* const m_Location;
+ const T m_OldValue;
+};
+
+#endif // CORE_FXCRT_CFX_AUTORESTORER_H_