Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkScoped_DEFINED | |
| 9 #define SkScoped_DEFINED | |
| 10 | |
| 11 /** | |
| 12 * sk_at_scope_end(stmt) evaluates stmt when the current scope ends. | |
| 13 * | |
| 14 * E.g. | |
| 15 * | |
| 16 * int x = 5; | |
| 17 * { | |
| 18 * sk_at_scope_end(x--); | |
| 19 * SkASSERT(x == 5); | |
| 20 * } | |
| 21 * SkASSERT(x == 4); | |
| 22 */ | |
| 23 template <typename Fn> | |
| 24 class SkScoped { | |
|
bungeman-skia
2016/08/26 18:24:42
SkScopeExit
hal.canary
2016/08/26 19:22:37
Done.
| |
| 25 public: | |
| 26 SkScoped(Fn f) : fFn(std::move(f)) {} | |
| 27 ~SkScoped() { fFn(); } | |
| 28 | |
| 29 private: | |
| 30 Fn fFn; | |
| 31 | |
| 32 SkScoped( const SkScoped& ) = delete; | |
| 33 SkScoped& operator=(const SkScoped& ) = delete; | |
| 34 SkScoped( SkScoped&&) = delete; | |
| 35 SkScoped& operator=( SkScoped&&) = delete; | |
| 36 }; | |
| 37 | |
| 38 template <typename Fn> | |
| 39 inline SkScoped<Fn> SkMakeScoped(Fn&& fn) { | |
|
bungeman-skia
2016/08/26 18:24:42
SkMakeScopeExit
hal.canary
2016/08/26 19:22:37
Done.
| |
| 40 return {std::move(fn)}; | |
| 41 } | |
| 42 | |
| 43 #define sk_at_scope_end(stmt) \ | |
|
bungeman-skia
2016/08/26 18:24:42
SK_AT_SCOPE_EXIT
| |
| 44 SK_UNUSED auto&& SK_MACRO_APPEND_LINE(at_scope_exit_) = \ | |
|
bungeman-skia
2016/08/26 18:24:42
You'll also need
https://codereview.chromium.org/
| |
| 45 SkMakeScoped([&]() { stmt; }); | |
| 46 | |
| 47 #endif // SkScoped_DEFINED | |
| OLD | NEW |