5#include "core/fpdfapi/parser/cpdf_object_walker.h"
9#include "core/fpdfapi/parser/cpdf_array.h"
10#include "core/fpdfapi/parser/cpdf_dictionary.h"
11#include "core/fpdfapi/parser/cpdf_stream.h"
12#include "third_party/base/check.h"
18 explicit StreamIterator(
RetainPtr<
const CPDF_Stream> stream)
21 ~StreamIterator()
override =
default;
23 bool IsFinished()
const override {
return IsStarted() && is_finished_; }
27 DCHECK(!IsFinished());
29 return object()->GetDict();
32 void Start()
override {}
35 bool is_finished_ =
false;
40 explicit DictionaryIterator(
RetainPtr<
const CPDF_Dictionary> dictionary)
43 ~DictionaryIterator()
override =
default;
45 bool IsFinished()
const override {
46 return IsStarted() && dict_iterator_ == locker_.end();
51 DCHECK(!IsFinished());
53 dict_key_ = dict_iterator_->first;
58 void Start()
override {
60 dict_iterator_ = locker_.begin();
63 ByteString dict_key()
const {
return dict_key_; }
66 CPDF_Dictionary::const_iterator dict_iterator_;
73 explicit ArrayIterator(
RetainPtr<
const CPDF_Array> array)
76 ~ArrayIterator()
override =
default;
78 bool IsFinished()
const override {
79 return IsStarted() && arr_iterator_ == locker_.end();
84 DCHECK(!IsFinished());
90 void Start()
override { arr_iterator_ = locker_.begin(); }
93 CPDF_Array::const_iterator arr_iterator_;
121std::unique_ptr<CPDF_ObjectWalker::SubobjectIterator>
123 if (object->IsStream())
124 return std::make_unique<StreamIterator>(ToStream(object));
125 if (object->IsDictionary())
126 return std::make_unique<DictionaryIterator>(ToDictionary(object));
127 if (object->IsArray())
128 return std::make_unique<ArrayIterator>(ToArray(object));
138 while (!stack_.empty() || next_object_) {
140 auto new_iterator = MakeIterator(next_object_);
143 stack_.push(std::move(new_iterator));
145 return std::move(next_object_);
152 next_object_ = it->Increment();
153 parent_object_.Reset(it->object());
154 dict_key_ = parent_object_->IsDictionary()
155 ?
static_cast<DictionaryIterator*>(it)->dict_key()
157 current_depth_ = stack_.size();
160 dict_key_ = ByteString();
166 if (stack_.empty() || stack_.top()->IsStarted())
176 return pdfium::WrapRetain(
177 const_cast<CPDF_Object*>(CPDF_ObjectWalker::GetNext().Get()));
RetainPtr< CPDF_Object > GetNext()
CPDF_NonConstObjectWalker(RetainPtr< CPDF_Object > root)
virtual bool IsFinished() const =0
const CPDF_Object * object() const
virtual ~SubobjectIterator()
SubobjectIterator(RetainPtr< const CPDF_Object > object)
RetainPtr< const CPDF_Object > Increment()
CPDF_ObjectWalker(RetainPtr< const CPDF_Object > root)
RetainPtr< const CPDF_Object > GetNext()
void SkipWalkIntoCurrentObject()