Home | History | Annotate | Download | only in fxcrt
      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:
     13   explicit AutoRestorer(T* location)
     14       : m_Location(location), m_OldValue(*location) {}
     15   ~AutoRestorer() { *m_Location = m_OldValue; }
     16 
     17  private:
     18   T* const m_Location;
     19   const T m_OldValue;
     20 };
     21 
     22 }  // namespace fxcrt
     23 
     24 using fxcrt::AutoRestorer;
     25 
     26 #endif  // CORE_FXCRT_AUTORESTORER_H_
     27