diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-08-14 23:35:52 +0300 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-14 22:30:41 +0000 |
commit | f57cad4f5dd0436d5b207d362afb34fc5f3f9acb (patch) | |
tree | 6beef6ce505b2baf0d976e545a5ac8a625e5ff95 /core/fpdfapi/parser/cpdf_object_walker.h | |
parent | 93c886b7ce59f6e65fe885330558c52f51cfcab9 (diff) | |
download | pdfium-f57cad4f5dd0436d5b207d362afb34fc5f3f9acb.tar.xz |
Add CPDF_ObjectWalker.
It is allow us to walk on all non-null sub-objects
in an object in depth, include itself,
Change-Id: Ia23051073984411668112422b47cf7a4460aa078
Reviewed-on: https://pdfium-review.googlesource.com/8910
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_object_walker.h')
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_walker.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_object_walker.h b/core/fpdfapi/parser/cpdf_object_walker.h new file mode 100644 index 0000000000..5590440f8f --- /dev/null +++ b/core/fpdfapi/parser/cpdf_object_walker.h @@ -0,0 +1,69 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CORE_FPDFAPI_PARSER_CPDF_OBJECT_WALKER_H_ +#define CORE_FPDFAPI_PARSER_CPDF_OBJECT_WALKER_H_ + +#include <memory> +#include <stack> + +#include "core/fpdfapi/parser/cpdf_dictionary.h" + +// Walk on all non-null sub-objects in an object in depth, include itself, +// like in flat list. +class CPDF_ObjectWalker { + public: + class SubobjectIterator { + public: + virtual ~SubobjectIterator(); + bool IsStarted() const { return is_started_; } + bool virtual IsFinished() const = 0; + const CPDF_Object* Increment(); + const CPDF_Object* object() const { return object_; } + + protected: + explicit SubobjectIterator(const CPDF_Object* object); + + virtual const CPDF_Object* IncrementImpl() = 0; + virtual void Start() = 0; + + private: + const CPDF_Object* object_; + bool is_started_ = false; + }; + + explicit CPDF_ObjectWalker(const CPDF_Object* root); + ~CPDF_ObjectWalker(); + + const CPDF_Object* GetNext(); + void SkipWalkIntoCurrentObject(); + + size_t current_depth() const { return current_depth_; } + const CPDF_Object* GetParent() const { return parent_object_; } + const CFX_ByteString& dictionary_key() const { return dict_key_; } + + private: + static std::unique_ptr<SubobjectIterator> MakeIterator( + const CPDF_Object* object); + + const CPDF_Object* next_object_; + const CPDF_Object* parent_object_; + + CFX_ByteString dict_key_; + size_t current_depth_; + + std::stack<std::unique_ptr<SubobjectIterator>> stack_; +}; + +class CPDF_NonConstObjectWalker : public CPDF_ObjectWalker { + public: + explicit CPDF_NonConstObjectWalker(CPDF_Object* root) + : CPDF_ObjectWalker(root) {} + + CPDF_Object* GetNext() { + return const_cast<CPDF_Object*>(CPDF_ObjectWalker::GetNext()); + } +}; + +#endif // CORE_FPDFAPI_PARSER_CPDF_OBJECT_WALKER_H_ |