Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: third_party/WebKit/Source/wtf/TemporaryChange.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 21 matching lines...) Expand all
32 32
33 // TemporaryChange<> is useful for setting a variable to a new value only within a 33 // TemporaryChange<> is useful for setting a variable to a new value only within a
34 // particular scope. An TemporaryChange<> object changes a variable to its origi nal 34 // particular scope. An TemporaryChange<> object changes a variable to its origi nal
35 // value upon destruction, making it an alternative to writing "var = false;" 35 // value upon destruction, making it an alternative to writing "var = false;"
36 // or "var = oldVal;" at all of a block's exit points. 36 // or "var = oldVal;" at all of a block's exit points.
37 // 37 //
38 // This should be obvious, but note that an TemporaryChange<> instance should ha ve a 38 // This should be obvious, but note that an TemporaryChange<> instance should ha ve a
39 // shorter lifetime than its scopedVariable, to prevent invalid memory writes 39 // shorter lifetime than its scopedVariable, to prevent invalid memory writes
40 // when the TemporaryChange<> object is destroyed. 40 // when the TemporaryChange<> object is destroyed.
41 41
42 template<typename T> 42 template <typename T>
43 class TemporaryChange { 43 class TemporaryChange {
44 WTF_MAKE_NONCOPYABLE(TemporaryChange); 44 WTF_MAKE_NONCOPYABLE(TemporaryChange);
45 public:
46 TemporaryChange(T& scopedVariable, T newValue)
47 : m_scopedVariable(scopedVariable)
48 , m_originalValue(scopedVariable)
49 {
50 m_scopedVariable = newValue;
51 }
52 45
53 ~TemporaryChange() 46 public:
54 { 47 TemporaryChange(T& scopedVariable, T newValue)
55 m_scopedVariable = m_originalValue; 48 : m_scopedVariable(scopedVariable), m_originalValue(scopedVariable) {
56 } 49 m_scopedVariable = newValue;
50 }
57 51
52 ~TemporaryChange() { m_scopedVariable = m_originalValue; }
58 53
59 private: 54 private:
60 T& m_scopedVariable; 55 T& m_scopedVariable;
61 T m_originalValue; 56 T m_originalValue;
62 }; 57 };
63
64 } 58 }
65 59
66 using WTF::TemporaryChange; 60 using WTF::TemporaryChange;
67 61
68 #endif 62 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/StringHasherTest.cpp ('k') | third_party/WebKit/Source/wtf/TemporaryChangeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698