• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CORE_FXCRT_AUTORESTORER_H_
6 #define CORE_FXCRT_AUTORESTORER_H_
7 
8 namespace fxcrt {
9 
10 template <typename T>
11 class AutoRestorer {
12  public:
AutoRestorer(T * location)13   explicit AutoRestorer(T* location)
14       : m_Location(location), m_OldValue(*location) {}
~AutoRestorer()15   ~AutoRestorer() {
16     if (m_Location)
17       *m_Location = m_OldValue;
18   }
AbandonRestoration()19   void AbandonRestoration() { m_Location = nullptr; }
20 
21  private:
22   T* m_Location;
23   const T m_OldValue;
24 };
25 
26 }  // namespace fxcrt
27 
28 using fxcrt::AutoRestorer;
29 
30 #endif  // CORE_FXCRT_AUTORESTORER_H_
31