From 5a33c75b981253dad559f2b1a4448087ac7fa780 Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 17 Jun 2024 16:29:34 +0100 Subject: [PATCH] Add QPDFObjectHandle::operator bool --- include/qpdf/QPDFObjectHandle.hh | 10 ++++++++++ include/qpdf/QPDFObjectHandle_future.hh | 10 ++++++++++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 9df0dd5..4d4d7f7 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -295,6 +295,11 @@ class QPDFObjectHandle QPDF_DLL QPDFObjectHandle& operator=(QPDFObjectHandle const&) = default; + // Return true if the QPDFObjectHandle is initialized. This allows object handles to be used in + // if statements with initializer. + QPDF_DLL + explicit inline operator bool() const noexcept; + QPDF_DLL inline bool isInitialized() const; @@ -1634,5 +1639,10 @@ QPDFObjectHandle::isInitialized() const return obj != nullptr; } +inline QPDFObjectHandle::operator bool() const noexcept +{ + return static_cast(obj); +} + #endif // QPDF_FUTURE #endif // QPDFOBJECTHANDLE_HH diff --git a/include/qpdf/QPDFObjectHandle_future.hh b/include/qpdf/QPDFObjectHandle_future.hh index 2a8a0ba..e6a79f6 100644 --- a/include/qpdf/QPDFObjectHandle_future.hh +++ b/include/qpdf/QPDFObjectHandle_future.hh @@ -295,6 +295,11 @@ class QPDFObjectHandle QPDF_DLL QPDFObjectHandle& operator=(QPDFObjectHandle&&) = default; + // Return true if the QPDFObjectHandle is initialized. This allows object handles to be used in + // if statements with initializer. + QPDF_DLL + explicit inline operator bool() const noexcept; + QPDF_DLL inline bool isInitialized() const noexcept; @@ -1634,4 +1639,9 @@ QPDFObjectHandle::isInitialized() const noexcept return obj != nullptr; } +inline QPDFObjectHandle::operator bool() const noexcept +{ + return static_cast(obj); +} + #endif // QPDFOBJECTHANDLE_FUTURE_HH -- libgit2 0.21.4