Commit 5a33c75b981253dad559f2b1a4448087ac7fa780

Authored by m-holger
Committed by m-holger
1 parent bcf56e53

Add QPDFObjectHandle::operator bool

include/qpdf/QPDFObjectHandle.hh
... ... @@ -295,6 +295,11 @@ class QPDFObjectHandle
295 295 QPDF_DLL
296 296 QPDFObjectHandle& operator=(QPDFObjectHandle const&) = default;
297 297  
  298 + // Return true if the QPDFObjectHandle is initialized. This allows object handles to be used in
  299 + // if statements with initializer.
  300 + QPDF_DLL
  301 + explicit inline operator bool() const noexcept;
  302 +
298 303 QPDF_DLL
299 304 inline bool isInitialized() const;
300 305  
... ... @@ -1634,5 +1639,10 @@ QPDFObjectHandle::isInitialized() const
1634 1639 return obj != nullptr;
1635 1640 }
1636 1641  
  1642 +inline QPDFObjectHandle::operator bool() const noexcept
  1643 +{
  1644 + return static_cast<bool>(obj);
  1645 +}
  1646 +
1637 1647 #endif // QPDF_FUTURE
1638 1648 #endif // QPDFOBJECTHANDLE_HH
... ...
include/qpdf/QPDFObjectHandle_future.hh
... ... @@ -295,6 +295,11 @@ class QPDFObjectHandle
295 295 QPDF_DLL
296 296 QPDFObjectHandle& operator=(QPDFObjectHandle&&) = default;
297 297  
  298 + // Return true if the QPDFObjectHandle is initialized. This allows object handles to be used in
  299 + // if statements with initializer.
  300 + QPDF_DLL
  301 + explicit inline operator bool() const noexcept;
  302 +
298 303 QPDF_DLL
299 304 inline bool isInitialized() const noexcept;
300 305  
... ... @@ -1634,4 +1639,9 @@ QPDFObjectHandle::isInitialized() const noexcept
1634 1639 return obj != nullptr;
1635 1640 }
1636 1641  
  1642 +inline QPDFObjectHandle::operator bool() const noexcept
  1643 +{
  1644 + return static_cast<bool>(obj);
  1645 +}
  1646 +
1637 1647 #endif // QPDFOBJECTHANDLE_FUTURE_HH
... ...