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

Side by Side Diff: src/pdf/SkScopeExit.h

Issue 2278703002: SkPDF: Glyph validation change (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unit test for SK_AT_SCOPE_EXIT Created 4 years, 3 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
« no previous file with comments | « src/pdf/SkPDFFont.cpp ('k') | tests/CPlusPlusEleven.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 SkScopeExit_DEFINED
9 #define SkScopeExit_DEFINED
10
11 #include "SkTypes.h"
12
13 /**
14 * sk_at_scope_end(stmt) evaluates stmt when the current scope ends.
bungeman-skia 2016/08/26 19:47:05 SK_AT_SCOPE_EXIT
hal.canary 2016/08/26 19:49:01 Done.
15 *
16 * E.g.
17 *
18 * int x = 5;
19 * {
20 * SK_AT_SCOPE_EXIT(x--);
21 * SkASSERT(x == 5);
22 * }
23 * SkASSERT(x == 4);
24 */
25 template <typename Fn>
26 class SkScopeExit {
27 public:
28 SkScopeExit(Fn f) : fFn(std::move(f)) {}
29 ~SkScopeExit() { fFn(); }
30
31 private:
32 Fn fFn;
33
34 SkScopeExit( const SkScopeExit& ) = delete;
35 SkScopeExit& operator=(const SkScopeExit& ) = delete;
36 SkScopeExit( SkScopeExit&&) = delete;
37 SkScopeExit& operator=( SkScopeExit&&) = delete;
38 };
39
40 template <typename Fn>
41 inline SkScopeExit<Fn> SkMakeScopeExit(Fn&& fn) {
42 return {std::move(fn)};
43 }
44
45 #define SK_AT_SCOPE_EXIT(stmt) \
46 SK_UNUSED auto&& SK_MACRO_APPEND_LINE(at_scope_exit_) = \
47 SkMakeScopeExit([&]() { stmt; });
48
49 #endif // SkScopeExit_DEFINED
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFont.cpp ('k') | tests/CPlusPlusEleven.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698