From 655c55f84830190f9fa4777c615b8a622254648a Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 10 Aug 2011 13:33:58 -0400 Subject: implement methods to get dictionary and array contents as map and vector --- libqpdf/QPDFObjectHandle.cc | 14 ++++++++++++++ libqpdf/QPDF_Array.cc | 6 ++++++ libqpdf/QPDF_Dictionary.cc | 7 +++++++ libqpdf/qpdf/QPDF_Array.hh | 1 + libqpdf/qpdf/QPDF_Dictionary.hh | 1 + 5 files changed, 29 insertions(+) (limited to 'libqpdf') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index b877f3dd..8567eef9 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -246,6 +246,13 @@ QPDFObjectHandle::getArrayItem(int n) return dynamic_cast(obj.getPointer())->getItem(n); } +std::vector +QPDFObjectHandle::getArrayAsVector() +{ + assertType("Array", isArray()); + return dynamic_cast(obj.getPointer())->getAsVector(); +} + // Array mutators void @@ -278,6 +285,13 @@ QPDFObjectHandle::getKeys() return dynamic_cast(obj.getPointer())->getKeys(); } +std::map +QPDFObjectHandle::getDictAsMap() +{ + assertType("Dictionary", isDictionary()); + return dynamic_cast(obj.getPointer())->getAsMap(); +} + // Array and Name accessors bool QPDFObjectHandle::isOrHasName(std::string const& value) diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index ae70bd67..ab61f307 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -51,6 +51,12 @@ QPDF_Array::getItem(int n) const return this->items[n]; } +std::vector const& +QPDF_Array::getAsVector() const +{ + return this->items; +} + void QPDF_Array::setItem(int n, QPDFObjectHandle const& oh) { diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index 838a37e6..3be138a4 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -78,6 +78,13 @@ QPDF_Dictionary::getKeys() return result; } +std::map const& +QPDF_Dictionary::getAsMap() const +{ + + return this->items; +} + void QPDF_Dictionary::replaceKey(std::string const& key, QPDFObjectHandle const& value) diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index 490df723..a57834c8 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -14,6 +14,7 @@ class QPDF_Array: public QPDFObject virtual std::string unparse(); int getNItems() const; QPDFObjectHandle getItem(int n) const; + std::vector const& getAsVector() const; void setItem(int, QPDFObjectHandle const&); protected: diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh index e84b549e..af9f7f09 100644 --- a/libqpdf/qpdf/QPDF_Dictionary.hh +++ b/libqpdf/qpdf/QPDF_Dictionary.hh @@ -21,6 +21,7 @@ class QPDF_Dictionary: public QPDFObject bool hasKey(std::string const&); QPDFObjectHandle getKey(std::string const&); std::set getKeys(); + std::map const& getAsMap() const; // Replace value of key, adding it if it does not exist void replaceKey(std::string const& key, QPDFObjectHandle const&); -- cgit v1.2.3-54-g00ecf