summaryrefslogtreecommitdiff
path: root/public/cpp/fpdf_scopers.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-25 18:49:32 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-25 18:49:32 +0000
commite08d2b1fee0db40bac9538ca8b7be0a951675bd6 (patch)
tree81ded468a54adb247f46d7824632f6c4a537619c /public/cpp/fpdf_scopers.h
parenteb3ec8f29846a5df67269a53ca94d1d740c84513 (diff)
downloadpdfium-e08d2b1fee0db40bac9538ca8b7be0a951675bd6.tar.xz
Introduce ScopedFPDF types in public/cpp/fpdf_scopers.h
Applies std::remove_ptr to the public API types so that we can deduce a correct unique ptr type no matter how that API might change away from void* usage. Creates shorter names for std::unique_ptr<std::remove_pointer<>, ...> Change-Id: I04a0ff43cb7d5a4d3867939a53a54c9cef00db86 Reviewed-on: https://pdfium-review.googlesource.com/31292 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'public/cpp/fpdf_scopers.h')
-rw-r--r--public/cpp/fpdf_scopers.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/public/cpp/fpdf_scopers.h b/public/cpp/fpdf_scopers.h
new file mode 100644
index 0000000000..1898ac887d
--- /dev/null
+++ b/public/cpp/fpdf_scopers.h
@@ -0,0 +1,54 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PUBLIC_CPP_FPDF_SCOPERS_H_
+#define PUBLIC_CPP_FPDF_SCOPERS_H_
+
+#include <memory>
+#include <type_traits>
+
+#include "public/cpp/fpdf_deleters.h"
+#include "public/fpdf_annot.h"
+#include "public/fpdf_dataavail.h"
+#include "public/fpdf_edit.h"
+#include "public/fpdf_formfill.h"
+#include "public/fpdf_structtree.h"
+#include "public/fpdf_text.h"
+#include "public/fpdfview.h"
+
+// Versions of FPDF types that clean up the object at scope exit.
+
+using ScopedFPDFAnnotation =
+ std::unique_ptr<std::remove_pointer<FPDF_ANNOTATION>::type,
+ FPDFAnnotationDeleter>;
+
+using ScopedFPDFAvail =
+ std::unique_ptr<std::remove_pointer<FPDF_AVAIL>::type, FPDFAvailDeleter>;
+
+using ScopedFPDFBitmap =
+ std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter>;
+
+using ScopedFPDFDocument =
+ std::unique_ptr<std::remove_pointer<FPDF_DOCUMENT>::type,
+ FPDFDocumentDeleter>;
+
+using ScopedFPDFFormHandle =
+ std::unique_ptr<std::remove_pointer<FPDF_FORMHANDLE>::type,
+ FPDFFormHandleDeleter>;
+
+using ScopedFPDFTextPage =
+ std::unique_ptr<std::remove_pointer<FPDF_TEXTPAGE>::type,
+ FPDFTextPageDeleter>;
+
+using ScopedFPDFPage =
+ std::unique_ptr<std::remove_pointer<FPDF_PAGE>::type, FPDFPageDeleter>;
+
+using ScopedFPDFStructTree =
+ std::unique_ptr<std::remove_pointer<FPDF_STRUCTTREE>::type,
+ FPDFStructTreeDeleter>;
+
+using ScopedFPDFFont =
+ std::unique_ptr<std::remove_pointer<FPDF_FONT>::type, FPDFFontDeleter>;
+
+#endif // PUBLIC_CPP_FPDF_SCOPERS_H_