Commit 4eb9f113876223516c0985a81a1c56380cff5a67

Authored by m-holger
1 parent 7d7a7d08

Refactor `NNTreeIterator` and `PathElement`: replace `QPDFObjectHandle` with `qp…

…df::Dictionary`, update constructors, and streamline logic with `Dictionary` API.
libqpdf/NNTree.cc
@@ -64,7 +64,7 @@ NNTreeIterator::updateIValue(bool allow_invalid) @@ -64,7 +64,7 @@ NNTreeIterator::updateIValue(bool allow_invalid)
64 return; 64 return;
65 } 65 }
66 66
67 - if (item_number < 0 || !node.isDictionary()) { 67 + if (item_number < 0 || !node) {
68 if (!allow_invalid) { 68 if (!allow_invalid) {
69 throw std::logic_error( 69 throw std::logic_error(
70 "attempt made to dereference an invalid name/number tree iterator"); 70 "attempt made to dereference an invalid name/number tree iterator");
@@ -74,12 +74,6 @@ NNTreeIterator::updateIValue(bool allow_invalid) @@ -74,12 +74,6 @@ NNTreeIterator::updateIValue(bool allow_invalid)
74 impl.error(node, "update ivalue: items array is too short"); 74 impl.error(node, "update ivalue: items array is too short");
75 } 75 }
76 76
77 -NNTreeIterator::PathElement::PathElement(QPDFObjectHandle const& node, int kid_number) :  
78 - node(node),  
79 - kid_number(kid_number)  
80 -{  
81 -}  
82 -  
83 Dictionary 77 Dictionary
84 NNTreeIterator::getNextKid(PathElement& pe, bool backward) 78 NNTreeIterator::getNextKid(PathElement& pe, bool backward)
85 { 79 {
@@ -349,7 +343,7 @@ NNTreeIterator::insertAfter(QPDFObjectHandle const&amp; key, QPDFObjectHandle const&amp; @@ -349,7 +343,7 @@ NNTreeIterator::insertAfter(QPDFObjectHandle const&amp; key, QPDFObjectHandle const&amp;
349 return; 343 return;
350 } 344 }
351 345
352 - Array items = node.getKey(impl.itemsKey()); 346 + Array items = node[impl.itemsKey()];
353 if (!items) { 347 if (!items) {
354 impl.error(node, "node contains no items array"); 348 impl.error(node, "node contains no items array");
355 } 349 }
@@ -451,7 +445,7 @@ NNTreeIterator::remove() @@ -451,7 +445,7 @@ NNTreeIterator::remove()
451 445
452 if (parent == path.end()) { 446 if (parent == path.end()) {
453 // We erased the very last item. Convert the root to an empty items array. 447 // We erased the very last item. Convert the root to an empty items array.
454 - element->node.removeKey("/Kids"); 448 + element->node.erase("/Kids");
455 element->node.replaceKey(impl.itemsKey(), Array::empty()); 449 element->node.replaceKey(impl.itemsKey(), Array::empty());
456 path.clear(); 450 path.clear();
457 setItemNumber(impl.tree_root, -1); 451 setItemNumber(impl.tree_root, -1);
libqpdf/qpdf/NNTree.hh
@@ -81,9 +81,13 @@ class NNTreeIterator final @@ -81,9 +81,13 @@ class NNTreeIterator final
81 class PathElement 81 class PathElement
82 { 82 {
83 public: 83 public:
84 - PathElement(QPDFObjectHandle const& node, int kid_number); 84 + PathElement(qpdf::Dictionary const& node, int kid_number) :
  85 + node(node),
  86 + kid_number(kid_number)
  87 + {
  88 + }
85 89
86 - QPDFObjectHandle node; 90 + qpdf::Dictionary node;
87 int kid_number; 91 int kid_number;
88 }; 92 };
89 93
@@ -114,7 +118,7 @@ class NNTreeIterator final @@ -114,7 +118,7 @@ class NNTreeIterator final
114 118
115 NNTreeImpl& impl; 119 NNTreeImpl& impl;
116 std::list<PathElement> path; 120 std::list<PathElement> path;
117 - QPDFObjectHandle node; 121 + qpdf::Dictionary node;
118 int item_number{-1}; 122 int item_number{-1};
119 value_type ivalue; 123 value_type ivalue;
120 }; 124 };