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

Unified Diff: src/pdf/SkScoped.h

Issue 2278703002: SkPDF: Glyph validation change (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 3 nits Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« src/pdf/SkPDFFont.cpp ('K') | « src/pdf/SkPDFFont.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkScoped.h
diff --git a/src/pdf/SkScoped.h b/src/pdf/SkScoped.h
new file mode 100644
index 0000000000000000000000000000000000000000..e76f63e3ce21c40f8221fef80b3584c10e386d06
--- /dev/null
+++ b/src/pdf/SkScoped.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkScoped_DEFINED
+#define SkScoped_DEFINED
+
+/**
+* sk_at_scope_end(stmt) evaluates stmt when the current scope ends.
+*
+* E.g.
+*
+* int x = 5;
+* {
+* sk_at_scope_end(x--);
+* SkASSERT(x == 5);
+* }
+* SkASSERT(x == 4);
+*/
+template <typename Fn>
+class SkScoped {
bungeman-skia 2016/08/26 18:24:42 SkScopeExit
hal.canary 2016/08/26 19:22:37 Done.
+public:
+ SkScoped(Fn f) : fFn(std::move(f)) {}
+ ~SkScoped() { fFn(); }
+
+private:
+ Fn fFn;
+
+ SkScoped( const SkScoped& ) = delete;
+ SkScoped& operator=(const SkScoped& ) = delete;
+ SkScoped( SkScoped&&) = delete;
+ SkScoped& operator=( SkScoped&&) = delete;
+};
+
+template <typename Fn>
+inline SkScoped<Fn> SkMakeScoped(Fn&& fn) {
bungeman-skia 2016/08/26 18:24:42 SkMakeScopeExit
hal.canary 2016/08/26 19:22:37 Done.
+ return {std::move(fn)};
+}
+
+#define sk_at_scope_end(stmt) \
bungeman-skia 2016/08/26 18:24:42 SK_AT_SCOPE_EXIT
+ 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/
+ SkMakeScoped([&]() { stmt; });
+
+#endif // SkScoped_DEFINED
« src/pdf/SkPDFFont.cpp ('K') | « src/pdf/SkPDFFont.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698