PoDoFo  1.0.0-dev
PdfNameTrees.h
1 
7 #ifndef PDF_NAME_TREES_H
8 #define PDF_NAME_TREES_H
9 
10 #include "PdfNameTree.h"
11 #include "PdfNameTreeOperations.h"
12 
13 namespace PoDoFo {
14 
21 class PODOFO_API PdfNameTrees final : public PdfDictionaryElement, public PdfNameTreeOperations
22 {
23  friend class PdfDocument;
24 
25 private:
30 
35  PdfNameTrees(PdfObject& obj);
36 
37 public:
38  template <typename TNameTree>
39  TNameTree* GetTree()
40  {
41  return static_cast<TNameTree*>(getNameTree(getType<TNameTree>()));
42  }
43 
44  template <typename TNameTree>
45  const TNameTree* GetTree() const
46  {
47  return static_cast<const TNameTree*>(getNameTree(getType<TNameTree>()));
48  }
49 
50  template <typename TNameTree>
51  TNameTree& MustGetTree()
52  {
53  return static_cast<TNameTree&>(mustGetNameTree(getType<TNameTree>()));
54  }
55 
56  template <typename TNameTree>
57  const TNameTree& MustGetTree() const
58  {
59  return static_cast<const TNameTree&>(mustGetNameTree(getType<TNameTree>()));
60  }
61 
62  template <typename TNameTree>
63  TNameTree& GetOrCreateTree()
64  {
65  return static_cast<TNameTree&>(getOrCreateNameTree(getType<TNameTree>()));
66  }
67 
68 public:
69  const PdfObject* GetValue(PdfKnownNameTree tree, const std::string_view& key) const override;
70  PdfObject* GetValue(PdfKnownNameTree tree, const std::string_view& key) override;
71  bool HasKey(PdfKnownNameTree tree, const std::string_view& key) const override;
72  void ToDictionary(PdfKnownNameTree tree, PdfStringMap<PdfObject>& dict, bool skipClear = false) const override;
73 
74 private:
75  void AddValue(PdfKnownNameTree tree, const PdfString& key, const PdfObject& value) override;
76  void AddValue(const PdfName& treeName, const PdfString& key, const PdfObject& value) override;
77  const PdfObject* GetValue(const std::string_view& treeName, const std::string_view& key) const override;
78  PdfObject* GetValue(const std::string_view& treeName, const std::string_view& key) override;
79  bool HasKey(const std::string_view& treeName, const std::string_view& key) const override;
80  void ToDictionary(const std::string_view& treeName, PdfStringMap<PdfObject>& dict, bool skipClear = false) const override;
81 
82 private:
100  PdfObject* getRootNode(const std::string_view& treeName) const;
101  PdfObject& getOrCreateRootNode(const PdfName& treeName);
102 
103  PdfObject* getValue(const std::string_view& name, const std::string_view& key) const;
104 
105  PdfNameTreeBase* getNameTree(PdfKnownNameTree tree) const;
106 
107  PdfNameTreeBase& mustGetNameTree(PdfKnownNameTree tree) const;
108 
109  PdfNameTreeBase& getOrCreateNameTree(PdfKnownNameTree tree);
110 
111  template <typename TNameTree>
112  static constexpr PdfKnownNameTree getType()
113  {
114  if (std::is_same_v<TNameTree, PdfEmbeddedFiles>)
115  return PdfKnownNameTree::EmbeddedFiles;
116  else if (std::is_same_v<TNameTree, PdfDestinations>)
117  return PdfKnownNameTree::Dests;
118  else
119  return PdfKnownNameTree::Unknown;
120  }
121 
122 private:
123  nullable<std::unique_ptr<PdfNameTreeBase>> m_Trees[(unsigned)PdfKnownNameTree::Renditions];
124 };
125 
126 };
127 
128 #endif // PDF_NAME_TREES_H
PdfDocument is the core interface for working with PDF documents.
Definition: PdfDocument.h:108
A low level interface with operations to handle document name trees stored in the /Names element.
Definition: PdfNameTreeOperations.h:18
Interface to access names trees in the document.
Definition: PdfNameTrees.h:22
bool HasKey(PdfKnownNameTree tree, const std::string_view &key) const override
Tests whether a certain nametree has a value.
const PdfObject * GetValue(PdfKnownNameTree tree, const std::string_view &key) const override
Get the object referenced by a string key in one of the dictionaries of the name tree.
This class represents a PdfName.
Definition: PdfName.h:24
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
A string that can be written to a PDF document.
Definition: PdfString.h:24
Alternative to std::optional that supports reference (but not pointer) types.
Definition: nullable.h:29
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16