PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfAnnotationCollection.h
1
7#ifndef PDF_ANNOTATION_COLLECTION_H
8#define PDF_ANNOTATION_COLLECTION_H
9
10#include "PdfAnnotation.h"
11#include "PdfArray.h"
12
13namespace PoDoFo
14{
15 class PdfPage;
16
17 class PODOFO_API PdfAnnotationCollection final
18 {
19 friend class PdfPage;
20 friend class PdfAnnotation;
21
22 private:
23 PdfAnnotationCollection(PdfPage& page);
24
25 public:
26 template <typename TAnnotation>
27 TAnnotation& CreateAnnot(const Rect& rect);
28
29 PdfAnnotation& CreateAnnot(PdfAnnotationType annotType, const Rect& rect);
30
31 PdfAnnotation& GetAnnotAt(unsigned index);
32
33 const PdfAnnotation& GetAnnotAt(unsigned index) const;
34
35 PdfAnnotation& GetAnnot(const PdfReference& ref);
36
37 const PdfAnnotation& GetAnnot(const PdfReference& ref) const;
38
39 void RemoveAnnotAt(unsigned index);
40
41 void RemoveAnnot(const PdfReference& ref);
42
43 unsigned GetCount() const;
44
45 public:
46 using AnnotationList = std::vector<std::unique_ptr<PdfAnnotation>>;
47
48 template <typename TObject, typename TListIterator>
49 class Iterator final
50 {
51 friend class PdfAnnotationCollection;
52 public:
53 using difference_type = void;
54 using value_type = TObject*;
55 using pointer = void;
56 using reference = void;
57 using iterator_category = std::forward_iterator_tag;
58 public:
59 Iterator() { }
60 private:
61 Iterator(const TListIterator& iterator) : m_iterator(iterator) { }
62 public:
63 Iterator(const Iterator&) = default;
64 Iterator& operator=(const Iterator&) = default;
65 bool operator==(const Iterator& rhs) const
66 {
67 return m_iterator == rhs.m_iterator;
68 }
69 bool operator!=(const Iterator& rhs) const
70 {
71 return m_iterator != rhs.m_iterator;
72 }
73 Iterator& operator++()
74 {
75 m_iterator++;
76 return *this;
77 }
78 Iterator operator++(int)
79 {
80 auto copy = *this;
81 m_iterator++;
82 return copy;
83 }
84 value_type operator*()
85 {
86 return m_iterator->get();
87 }
88 value_type operator->()
89 {
90 return m_iterator->get();
91 }
92 private:
93 TListIterator m_iterator;
94 };
95
96 using iterator = Iterator<PdfAnnotation, AnnotationList::iterator>;
97 using const_iterator = Iterator<const PdfAnnotation, AnnotationList::const_iterator>;
98
99 public:
100 iterator begin();
101 iterator end();
102 const_iterator begin() const;
103 const_iterator end() const;
104
105 private:
106 PdfAnnotation& addAnnotation(std::unique_ptr<PdfAnnotation>&& annot);
107 PdfArray* getAnnotationsArray() const;
108 void initAnnotations();
109 PdfAnnotation& getAnnotAt(unsigned index) const;
110 PdfAnnotation& getAnnot(const PdfReference& ref) const;
111 void fixIndices(unsigned index);
112
113 private:
114 using AnnotationMap = std::map<PdfReference, unsigned>;
115
116 private:
117 AnnotationList m_Annots;
118 std::unique_ptr<AnnotationMap> m_annotMap;
119 PdfPage* m_Page;
120 PdfArray* m_annotArray;
121 };
122
123 template<typename TAnnotation>
124 TAnnotation& PdfAnnotationCollection::CreateAnnot(const Rect& rect)
125 {
126 return static_cast<TAnnotation&>(CreateAnnot(PdfAnnotation::GetAnnotationType<TAnnotation>(), rect));
127 }
128}
129
130#endif // PDF_ANNOTATION_COLLECTION_H
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16