| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_AUTO_RESET_H_ | 5 #ifndef BASE_AUTO_RESET_H_ |
| 6 #define BASE_AUTO_RESET_H_ | 6 #define BASE_AUTO_RESET_H_ |
| 7 #pragma once | |
| 8 | 7 |
| 9 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 10 | 9 |
| 11 // AutoReset<> is useful for setting a variable to a new value only within a | 10 // AutoReset<> is useful for setting a variable to a new value only within a |
| 12 // particular scope. An AutoReset<> object resets a variable to its original | 11 // particular scope. An AutoReset<> object resets a variable to its original |
| 13 // value upon destruction, making it an alternative to writing "var = false;" | 12 // value upon destruction, making it an alternative to writing "var = false;" |
| 14 // or "var = old_val;" at all of a block's exit points. | 13 // or "var = old_val;" at all of a block's exit points. |
| 15 // | 14 // |
| 16 // This should be obvious, but note that an AutoReset<> instance should have a | 15 // This should be obvious, but note that an AutoReset<> instance should have a |
| 17 // shorter lifetime than its scoped_variable, to prevent invalid memory writes | 16 // shorter lifetime than its scoped_variable, to prevent invalid memory writes |
| (...skipping 11 matching lines...) Expand all Loading... |
| 29 ~AutoReset() { *scoped_variable_ = original_value_; } | 28 ~AutoReset() { *scoped_variable_ = original_value_; } |
| 30 | 29 |
| 31 private: | 30 private: |
| 32 T* scoped_variable_; | 31 T* scoped_variable_; |
| 33 T original_value_; | 32 T original_value_; |
| 34 | 33 |
| 35 DISALLOW_COPY_AND_ASSIGN(AutoReset); | 34 DISALLOW_COPY_AND_ASSIGN(AutoReset); |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 #endif // BASE_AUTO_RESET_H_ | 37 #endif // BASE_AUTO_RESET_H_ |
| OLD | NEW |