11 #include "PdfDataContainer.h"
16 using PdfArrayList = std::vector<PdfObject>;
21 template <
typename TObject,
typename TListIterator>
37 using difference_type = void;
38 using value_type = TObject*;
40 using reference = void;
41 using iterator_category = std::forward_iterator_tag;
47 Iterator(
const Iterator&) =
default;
48 Iterator& operator=(
const Iterator&) =
default;
49 bool operator==(
const Iterator& rhs)
const;
50 bool operator!=(
const Iterator& rhs)
const;
51 Iterator& operator++();
52 Iterator operator++(
int);
53 value_type operator*();
54 value_type operator->();
58 TListIterator m_iterator;
63 Iterator begin()
const;
86 using size_type = size_t;
90 using iterator = PdfArrayList::iterator;
91 using const_iterator = PdfArrayList::const_iterator;
92 using reverse_iterator = PdfArrayList::reverse_iterator;
93 using const_reverse_iterator = PdfArrayList::const_reverse_iterator;
116 unsigned GetSize()
const;
121 bool IsEmpty()
const;
128 const PdfStatefulEncrypt* encrypt,
charbuff& buffer)
const override;
130 template <
typename T>
131 T GetAtAs(
unsigned idx)
const;
133 template <
typename T>
134 T GetAtAsSafe(
unsigned idx,
const std::common_type_t<T>& defvalue = { })
const;
136 template <
typename T>
137 bool TryGetAtAs(
unsigned idx, T& value)
const;
148 const PdfObject* FindAt(
unsigned idx)
const;
151 const PdfObject& MustFindAt(
unsigned idx)
const;
154 template <
typename T>
155 T FindAtAs(
unsigned idx,
const std::common_type_t<T>& defvalue = { })
const;
157 template <
typename T>
158 T FindAtAsSafe(
unsigned idx,
const std::common_type_t<T>& defvalue = { })
const;
160 template <
typename T>
161 bool TryFindAtAs(
unsigned idx, T& value)
const;
163 void RemoveAt(
unsigned idx);
177 void SetAtIndirect(
unsigned idx,
const PdfObject* obj);
192 void Reserve(
unsigned n);
194 void SwapAt(
unsigned atIndex,
unsigned toIndex);
196 void MoveTo(
unsigned atIndex,
unsigned toIndex);
205 const PdfObject& operator[](size_type idx)
const;
219 const_iterator begin()
const;
233 const_iterator end()
const;
240 reverse_iterator rbegin();
247 const_reverse_iterator rbegin()
const;
254 reverse_iterator rend();
261 const_reverse_iterator rend()
const;
263 void resize(
size_t size);
265 void reserve(
size_t size);
267 iterator insert(
const iterator& pos,
const PdfObject& obj);
268 iterator insert(
const iterator& pos,
PdfObject&& obj);
270 template<
typename InputIterator>
271 inline void insert(
const iterator& pos,
const InputIterator& first,
const InputIterator& last);
273 void erase(
const iterator& pos);
274 void erase(
const iterator& first,
const iterator& last);
301 bool operator==(
const PdfArray& rhs)
const;
302 bool operator!=(
const PdfArray& rhs)
const;
305 void resetDirty()
override;
306 void setChildrenParent()
override;
314 iterator insertAt(
const iterator& pos,
PdfObject&& obj);
318 const PdfStatefulEncrypt* encrypt,
charbuff& buffer)
const;
321 PdfArrayList m_Objects;
325 T PdfArray::GetAtAs(
unsigned idx)
const
331 T PdfArray::GetAtAsSafe(
unsigned idx,
const std::common_type_t<T>& defvalue)
const
334 if (Object<T>::TryGet(getAt(idx), value))
341 bool PdfArray::TryGetAtAs(
unsigned idx, T& value)
const
343 if (Object<T>::TryGet(getAt(idx), value))
355 T PdfArray::FindAtAs(
unsigned idx,
const std::common_type_t<T>& defvalue)
const
357 auto obj = findAt(idx);
361 return Object<T>::Get(*obj);
365 T PdfArray::FindAtAsSafe(
unsigned idx,
const std::common_type_t<T>& defvalue)
const
368 auto obj = findAt(idx);
369 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
376 bool PdfArray::TryFindAtAs(
unsigned idx, T& value)
const
378 auto obj = findAt(idx);
379 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
390 template<
typename InputIterator>
391 void PdfArray::insert(
const PdfArray::iterator& pos,
392 const InputIterator& first,
393 const InputIterator& last)
396 auto document = GetObjectDocument();
397 InputIterator it1 = first;
399 for (; it1 != last; it1++, it2++)
401 it2 = m_Objects.insert(it2, *it1);
402 it2->SetDocument(document);
408 template<
typename TObject,
typename TListIterator>
409 PdfArrayIndirectIterableBase<TObject, TListIterator>::PdfArrayIndirectIterableBase()
412 template<
typename TObject,
typename TListIterator>
413 PdfArrayIndirectIterableBase<TObject, TListIterator>::PdfArrayIndirectIterableBase(PdfArray& arr)
414 : PdfIndirectIterableBase(arr), m_arr(&arr) { }
416 template<
typename TObject,
typename TListIterator>
417 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator PdfArrayIndirectIterableBase<TObject, TListIterator>::begin()
const
419 if (m_arr ==
nullptr)
422 return Iterator(m_arr->begin(), GetObjects());
425 template<
typename TObject,
typename TListIterator>
426 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator PdfArrayIndirectIterableBase<TObject, TListIterator>::end()
const
428 if (m_arr ==
nullptr)
431 return Iterator(m_arr->end(), GetObjects());
434 template<
typename TObject,
typename TListIterator>
435 PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::Iterator() : m_objects(nullptr) { }
437 template<
typename TObject,
typename TListIterator>
438 PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::Iterator(TListIterator&& iterator, PdfIndirectObjectList* objects)
439 : m_iterator(std::move(iterator)), m_objects(objects) { }
441 template<
typename TObject,
typename TListIterator>
442 bool PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::operator==(
const Iterator& rhs)
const
444 return m_iterator == rhs.m_iterator;
447 template<
typename TObject,
typename TListIterator>
448 bool PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::operator!=(
const Iterator& rhs)
const
450 return m_iterator != rhs.m_iterator;
453 template<
typename TObject,
typename TListIterator>
454 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator& PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::operator++()
460 template<
typename TObject,
typename TListIterator>
461 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::operator++(
int)
468 template<
typename TObject,
typename TListIterator>
469 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::value_type PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::operator*()
474 template<
typename TObject,
typename TListIterator>
475 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::value_type PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::operator->()
480 template<
typename TObject,
typename TListIterator>
481 typename PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::value_type PdfArrayIndirectIterableBase<TObject, TListIterator>::Iterator::resolve()
483 TObject& robj = *m_iterator;
484 TObject* indirectobj;
486 if (m_objects !=
nullptr
487 && robj.TryGetReference(ref)
489 && (indirectobj = GetObject(*m_objects, ref)) !=
nullptr)
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
An interface for writing blocks of data to a data source.
Definition: OutputStream.h:18
Helper class to iterate through array indirect objects.
Definition: PdfArray.h:23
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition: PdfArray.h:81
A PdfDataProvider object with a PdfObject owner, specialized in holding objects.
Definition: PdfDataContainer.h:22
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition: PdfIndirectObjectList.h:30
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
A simple tokenizer for PDF files and PDF content streams.
Definition: PdfTokenizer.h:53
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition: basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
PdfWriteFlags
Specify additional options for writing the PDF.
Definition: PdfDeclarations.h:137
Templatized object type getter helper.
Definition: PdfObject.h:607