PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfFieldChildrenCollection.h
1// SPDX-FileCopyrightText: 2022 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_FIELD_CHILDREN_COLLECTION_H
5#define PDF_FIELD_CHILDREN_COLLECTION_H
6
7#include "PdfObject.h"
8#include <podofo/auxiliary/Rect.h>
9
10namespace PoDoFo
11{
12 class PdfField;
13 class PdfPage;
14
15 class PODOFO_API PdfFieldChildrenCollectionBase
16 {
17 friend class PdfField;
18
19 private:
20 PdfFieldChildrenCollectionBase(PdfField& field);
21
22 public:
23 PdfField& CreateChild();
24 PdfField& CreateChild(PdfPage& page, const Rect& rect);
25
26 PdfField& GetFieldAt(unsigned index);
27
28 const PdfField& GetFieldAt(unsigned index) const;
29
30 PdfField& GetField(const PdfReference& ref);
31
32 const PdfField& GetField(const PdfReference& ref) const;
33
34 void RemoveFieldAt(unsigned index);
35
36 void RemoveField(const PdfReference& ref);
37
38 unsigned GetCount() const;
39
40 bool HasKidsArray() const;
41
42 public:
43 using FieldList = std::vector<std::shared_ptr<PdfField>>;
44
45 template <typename TField, typename TListIterator>
46 class Iterator final
47 {
48 friend class PdfFieldChildrenCollectionBase;
49 public:
50 using difference_type = void;
51 using value_type = TField*;
52 using pointer = void;
53 using reference = void;
54 using iterator_category = std::forward_iterator_tag;
55 public:
56 Iterator() { }
57 private:
58 Iterator(const TListIterator& iterator) : m_iterator(iterator) { }
59 public:
60 Iterator(const Iterator&) = default;
61 Iterator& operator=(const Iterator&) = default;
62 bool operator==(const Iterator& rhs) const
63 {
64 return m_iterator == rhs.m_iterator;
65 }
66 bool operator!=(const Iterator& rhs) const
67 {
68 return m_iterator != rhs.m_iterator;
69 }
70 Iterator& operator++()
71 {
72 m_iterator++;
73 return *this;
74 }
75 Iterator operator++(int)
76 {
77 auto copy = *this;
78 m_iterator++;
79 return copy;
80 }
81 value_type operator*()
82 {
83 return m_iterator.get();
84 }
85 value_type operator->()
86 {
87 return m_iterator.get();
88 }
89 private:
90 TListIterator m_iterator;
91 };
92
93 using iterator = Iterator<PdfField, FieldList::iterator>;
94 using const_iterator = Iterator<const PdfField, FieldList::const_iterator>;
95
96 public:
97 iterator begin();
98 iterator end();
99 const_iterator begin() const;
100 const_iterator end() const;
101
102 private:
103 // To be called by PdfField
104 PdfField& AddChild(std::shared_ptr<PdfField> field);
105 private:
106 PdfArray* getKidsArray() const;
107 void initFields();
108 PdfField& getFieldAt(unsigned index) const;
109 PdfField& getField(const PdfReference& ref) const;
110 void fixIndices(unsigned index);
111
112 private:
113 using FieldMap = std::map<PdfReference, unsigned>;
114
115 private:
116 FieldList m_Fields;
117 FieldMap m_fieldMap;
118 PdfField* m_field;
119 PdfArray* m_kidsArray;
120 };
121
122 // TODO
123 template <typename TField>
124 class PdfFieldChildrenCollection final : PdfFieldChildrenCollectionBase
125 {
126
127 };
128}
129
130#endif // PDF_FIELD_CHILDREN_COLLECTION_H
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13