diff options
author | m-holger <m-holger@kubitscheck.org> | 2022-02-05 15:46:25 +0100 |
---|---|---|
committer | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2022-02-05 17:24:35 +0100 |
commit | e58b1174c7f8b617a1253e70df9b95a1cac10fab (patch) | |
tree | 3ed228458d61ae38704ef93cd546a789ad0118ce /libqpdf/QPDFObjectHandle.cc | |
parent | cfaa2de804f91b8130486848ced44d0aa283acef (diff) | |
download | qpdf-e58b1174c7f8b617a1253e70df9b95a1cac10fab.tar.zst |
Add new QPDFObjectHandle::getValueAs... accessors
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 0bcd816b..d754448f 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -392,6 +392,17 @@ QPDFObjectHandle::getNumericValue() } bool +QPDFObjectHandle::getValueAsNumber(double& value) +{ + if (! isNumber()) + { + return false; + } + value = getNumericValue(); + return true; +} + +bool QPDFObjectHandle::isName() { if (! this->initialized) @@ -536,6 +547,17 @@ QPDFObjectHandle::getBoolValue() } } +bool +QPDFObjectHandle::getValueAsBool(bool& value) +{ + if (! isBool()) + { + return false; + } + value = dynamic_cast<QPDF_Bool*>(obj.get())->getVal(); + return true; +} + // Integer accessors long long @@ -553,6 +575,17 @@ QPDFObjectHandle::getIntValue() } } +bool +QPDFObjectHandle::getValueAsInt(long long& value) +{ + if (! isInteger()) + { + return false; + } + value = dynamic_cast<QPDF_Integer*>(obj.get())->getVal(); + return true; +} + int QPDFObjectHandle::getIntValueAsInt() { @@ -581,6 +614,17 @@ QPDFObjectHandle::getIntValueAsInt() return result; } +bool +QPDFObjectHandle::getValueAsInt(int& value) +{ + if (! isInteger()) + { + return false; + } + value = getIntValueAsInt(); + return true; +} + unsigned long long QPDFObjectHandle::getUIntValue() { @@ -600,6 +644,17 @@ QPDFObjectHandle::getUIntValue() return result; } +bool +QPDFObjectHandle::getValueAsUInt(unsigned long long& value) +{ + if (! isInteger()) + { + return false; + } + value = getUIntValue(); + return true; +} + unsigned int QPDFObjectHandle::getUIntValueAsUInt() { @@ -629,6 +684,17 @@ QPDFObjectHandle::getUIntValueAsUInt() return result; } +bool +QPDFObjectHandle::getValueAsUInt(unsigned int& value) +{ + if (! isInteger()) + { + return false; + } + value = getUIntValueAsUInt(); + return true; +} + // Real accessors std::string @@ -646,6 +712,17 @@ QPDFObjectHandle::getRealValue() } } +bool +QPDFObjectHandle::getValueAsReal(std::string& value) +{ + if (! isReal()) + { + return false; + } + value = dynamic_cast<QPDF_Real*>(obj.get())->getVal(); + return true; +} + // Name accessors std::string @@ -663,6 +740,17 @@ QPDFObjectHandle::getName() } } +bool +QPDFObjectHandle::getValueAsName(std::string& value) +{ + if (! isName()) + { + return false; + } + value = dynamic_cast<QPDF_Name*>(obj.get())->getName(); + return true; +} + // String accessors std::string @@ -680,6 +768,17 @@ QPDFObjectHandle::getStringValue() } } +bool +QPDFObjectHandle::getValueAsString(std::string& value) +{ + if (! isString()) + { + return false; + } + value = dynamic_cast<QPDF_String*>(obj.get())->getVal(); + return true; +} + std::string QPDFObjectHandle::getUTF8Value() { @@ -695,6 +794,17 @@ QPDFObjectHandle::getUTF8Value() } } +bool +QPDFObjectHandle::getValueAsUTF8(std::string& value) +{ + if (! isString()) + { + return false; + } + value = dynamic_cast<QPDF_String*>(obj.get())->getUTF8Val(); + return true; +} + // Operator and Inline Image accessors std::string @@ -712,6 +822,17 @@ QPDFObjectHandle::getOperatorValue() } } +bool +QPDFObjectHandle::getValueAsOperator(std::string& value) +{ + if (! isOperator()) + { + return false; + } + value = dynamic_cast<QPDF_Operator*>(obj.get())->getVal(); + return true; +} + std::string QPDFObjectHandle::getInlineImageValue() { @@ -727,6 +848,17 @@ QPDFObjectHandle::getInlineImageValue() } } +bool +QPDFObjectHandle::getValueAsInlineImage(std::string& value) +{ + if (! isInlineImage()) + { + return false; + } + value = dynamic_cast<QPDF_InlineImage*>(obj.get())->getVal(); + return true; +} + // Array accessors QPDFObjectHandle::QPDFArrayItems |