SaveAndRestore: fix coding style and Doxygenify comments

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205959 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dmitri Gribenko 2014-04-10 09:44:32 +00:00
parent 878657074a
commit 7aca6639c2

View File

@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details. // License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// ///
// This file provides utility classes that uses RAII to save and restore /// \file
// values. /// This file provides utility classes that use RAII to save and restore
// /// values.
///
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_SAVEANDRESTORE_H #ifndef LLVM_SUPPORT_SAVEANDRESTORE_H
@ -17,31 +18,32 @@
namespace llvm { namespace llvm {
// SaveAndRestore - A utility class that uses RAII to save and restore /// A utility class that uses RAII to save and restore the value of a variable.
// the value of a variable. template <typename T> struct SaveAndRestore {
template<typename T> SaveAndRestore(T &X) : X(X), OldValue(X) {}
struct SaveAndRestore { SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) {
SaveAndRestore(T& x) : X(x), old_value(x) {} X = NewValue;
SaveAndRestore(T& x, const T &new_value) : X(x), old_value(x) {
X = new_value;
} }
~SaveAndRestore() { X = old_value; } ~SaveAndRestore() { X = OldValue; }
T get() { return old_value; } T get() { return OldValue; }
private: private:
T& X; T &X;
T old_value; T OldValue;
}; };
// SaveOr - Similar to SaveAndRestore. Operates only on bools; the old /// Similar to \c SaveAndRestore. Operates only on bools; the old value of a
// value of a variable is saved, and during the dstor the old value is /// variable is saved, and during the dstor the old value is or'ed with the new
// or'ed with the new value. /// value.
struct SaveOr { struct SaveOr {
SaveOr(bool& x) : X(x), old_value(x) { x = false; } SaveOr(bool &X) : X(X), OldValue(X) { X = false; }
~SaveOr() { X |= old_value; } ~SaveOr() { X |= OldValue; }
private: private:
bool& X; bool &X;
const bool old_value; const bool OldValue;
}; };
} } // namespace llvm
#endif #endif