From e58b1174c7f8b617a1253e70df9b95a1cac10fab Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 5 Feb 2022 14:46:25 +0000 Subject: Add new QPDFObjectHandle::getValueAs... accessors --- libqpdf/QPDFObjectHandle.cc | 132 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'libqpdf/QPDFObjectHandle.cc') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 0bcd816b..d754448f 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -391,6 +391,17 @@ QPDFObjectHandle::getNumericValue() return result; } +bool +QPDFObjectHandle::getValueAsNumber(double& value) +{ + if (! isNumber()) + { + return false; + } + value = getNumericValue(); + return true; +} + bool QPDFObjectHandle::isName() { @@ -536,6 +547,17 @@ QPDFObjectHandle::getBoolValue() } } +bool +QPDFObjectHandle::getValueAsBool(bool& value) +{ + if (! isBool()) + { + return false; + } + value = dynamic_cast(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(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(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(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(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(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(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(obj.get())->getVal(); + return true; +} + // Array accessors QPDFObjectHandle::QPDFArrayItems -- cgit v1.2.3-54-g00ecf