diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2023-05-20 20:09:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-20 20:09:49 +0200 |
commit | a85635b839755765713eb27d767f42b357056b2e (patch) | |
tree | 369b4e49b78e54e04a0409b774a659206017addd /libqpdf/QPDFObjGen.cc | |
parent | fd17c8e3fe38a56abf50ce0edec1cde48d4f74cb (diff) | |
parent | 50bc82b4e035853bd06a9935722d6b5aec902133 (diff) | |
download | qpdf-a85635b839755765713eb27d767f42b357056b2e.tar.zst |
Merge pull request #929 from m-holger/ogguard
Add new convenience class QPDFObjGen::Guard
Diffstat (limited to 'libqpdf/QPDFObjGen.cc')
-rw-r--r-- | libqpdf/QPDFObjGen.cc | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/libqpdf/QPDFObjGen.cc b/libqpdf/QPDFObjGen.cc index 7cce84d8..8e5bd178 100644 --- a/libqpdf/QPDFObjGen.cc +++ b/libqpdf/QPDFObjGen.cc @@ -1,7 +1,12 @@ #include <qpdf/QPDFObjGen.hh> -#include <qpdf/QUtil.hh> +#include <qpdf/QPDFObjectHandle.hh> +#include <qpdf/QPDFObjectHelper.hh> +#include <qpdf/QPDFObject_private.hh> +#include <stdexcept> + +// ABI: inline and pass og by value std::ostream& operator<<(std::ostream& os, const QPDFObjGen& og) { @@ -9,8 +14,55 @@ operator<<(std::ostream& os, const QPDFObjGen& og) return os; } +// ABI: inline std::string QPDFObjGen::unparse(char separator) const { - return std::to_string(this->obj) + separator + std::to_string(this->gen); + return std::to_string(obj) + separator + std::to_string(gen); +} + +bool +QPDFObjGen::set::add(QPDFObjectHandle const& oh) +{ + if (auto* ptr = oh.getObjectPtr()) { + return add(ptr->getObjGen()); + } else { + throw std::logic_error("attempt to retrieve QPDFObjGen from " + "uninitialized QPDFObjectHandle"); + return false; + } +} + +bool +QPDFObjGen::set::add(QPDFObjectHelper const& helper) +{ + if (auto* ptr = helper.getObjectHandle().getObjectPtr()) { + return add(ptr->getObjGen()); + } else { + throw std::logic_error("attempt to retrieve QPDFObjGen from " + "uninitialized QPDFObjectHandle"); + return false; + } +} + +void +QPDFObjGen::set::erase(QPDFObjectHandle const& oh) +{ + if (auto* ptr = oh.getObjectPtr()) { + erase(ptr->getObjGen()); + } else { + throw std::logic_error("attempt to retrieve QPDFObjGen from " + "uninitialized QPDFObjectHandle"); + } +} + +void +QPDFObjGen::set::erase(QPDFObjectHelper const& helper) +{ + if (auto* ptr = helper.getObjectHandle().getObjectPtr()) { + erase(ptr->getObjGen()); + } else { + throw std::logic_error("attempt to retrieve QPDFObjGen from " + "uninitialized QPDFObjectHandle"); + } } |