llvm.org GIT mirror llvm / 7aca663
SaveAndRestore: fix coding style and Doxygenify comments git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205959 91177308-0d34-0410-b5e6-96231b3b80d8 Dmitri Gribenko 6 years ago
1 changed file(s) with 25 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
55 // License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
8 //
9 // This file provides utility classes that uses RAII to save and restore
10 // values.
11 //
8 ///
9 /// \file
10 /// This file provides utility classes that use RAII to save and restore
11 /// values.
12 ///
1213 //===----------------------------------------------------------------------===//
1314
1415 #ifndef LLVM_SUPPORT_SAVEANDRESTORE_H
1617
1718 namespace llvm {
1819
19 // SaveAndRestore - A utility class that uses RAII to save and restore
20 // the value of a variable.
21 template
22 struct SaveAndRestore {
23 SaveAndRestore(T& x) : X(x), old_value(x) {}
24 SaveAndRestore(T& x, const T &new_value) : X(x), old_value(x) {
25 X = new_value;
20 /// A utility class that uses RAII to save and restore the value of a variable.
21 template struct SaveAndRestore {
22 SaveAndRestore(T &X) : X(X), OldValue(X) {}
23 SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) {
24 X = NewValue;
2625 }
27 ~SaveAndRestore() { X = old_value; }
28 T get() { return old_value; }
26 ~SaveAndRestore() { X = OldValue; }
27 T get() { return OldValue; }
28
2929 private:
30 T& X;
31 T old_value;
30 T &X;
31 T OldValue;
3232 };
3333
34 // SaveOr - Similar to SaveAndRestore. Operates only on bools; the old
35 // value of a variable is saved, and during the dstor the old value is
36 // or'ed with the new value.
34 /// Similar to \c SaveAndRestore. Operates only on bools; the old value of a
35 /// variable is saved, and during the dstor the old value is or'ed with the new
36 /// value.
3737 struct SaveOr {
38 SaveOr(bool& x) : X(x), old_value(x) { x = false; }
39 ~SaveOr() { X |= old_value; }
38 SaveOr(bool &X) : X(X), OldValue(X) { X = false; }
39 ~SaveOr() { X |= OldValue; }
40
4041 private:
41 bool& X;
42 const bool old_value;
42 bool &X;
43 const bool OldValue;
4344 };
4445
45 }
46 } // namespace llvm
47
4648 #endif