summaryrefslogtreecommitdiff
path: root/core/fxcrt/autorestorer.h
blob: 745a56fff2de44c7f60a010b5c12dbd1c7e31b57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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_AUTORESTORER_H_
#define CORE_FXCRT_AUTORESTORER_H_

namespace fxcrt {

template <typename T>
class AutoRestorer {
 public:
  explicit AutoRestorer(T* location)
      : m_Location(location), m_OldValue(*location) {}
  ~AutoRestorer() { *m_Location = m_OldValue; }

 private:
  T* const m_Location;
  const T m_OldValue;
};

}  // namespace fxcrt

using fxcrt::AutoRestorer;

#endif  // CORE_FXCRT_AUTORESTORER_H_