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

Unified Diff: src/pdf/SkScopeExit.h

Issue 2278703002: SkPDF: Glyph validation change (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix comment 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
« no previous file with comments | « src/pdf/SkPDFFont.cpp ('k') | tests/CPlusPlusEleven.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkScopeExit.h
diff --git a/src/pdf/SkScopeExit.h b/src/pdf/SkScopeExit.h
new file mode 100644
index 0000000000000000000000000000000000000000..5b7bcdc07686cb334417659cb0d312dcf36a9c53
--- /dev/null
+++ b/src/pdf/SkScopeExit.h
@@ -0,0 +1,50 @@
+/*
+ * 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 SkScopeExit_DEFINED
+#define SkScopeExit_DEFINED
+
+#include "SkTypes.h"
+
+/**
+ * SK_AT_SCOPE_EXIT(stmt) evaluates stmt when the current scope ends.
+ *
+ * E.g.
+ * {
+ * int x = 5;
+ * {
+ * SK_AT_SCOPE_EXIT(x--);
+ * SkASSERT(x == 5);
+ * }
+ * SkASSERT(x == 4);
+ * }
+ */
+template <typename Fn>
+class SkScopeExit {
+public:
+ SkScopeExit(Fn f) : fFn(std::move(f)) {}
+ ~SkScopeExit() { fFn(); }
+
+private:
+ Fn fFn;
+
+ SkScopeExit( const SkScopeExit& ) = delete;
+ SkScopeExit& operator=(const SkScopeExit& ) = delete;
+ SkScopeExit( SkScopeExit&&) = delete;
+ SkScopeExit& operator=( SkScopeExit&&) = delete;
+};
+
+template <typename Fn>
+inline SkScopeExit<Fn> SkMakeScopeExit(Fn&& fn) {
+ return {std::move(fn)};
+}
+
+#define SK_AT_SCOPE_EXIT(stmt) \
+ SK_UNUSED auto&& SK_MACRO_APPEND_LINE(at_scope_exit_) = \
+ SkMakeScopeExit([&]() { stmt; });
+
+#endif // SkScopeExit_DEFINED
« 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