7#ifndef PDF_DICTIONARY_H
8#define PDF_DICTIONARY_H
11#include "PdfDataContainer.h"
20template <
typename TObject,
typename TMapIterator>
36 using difference_type =
void;
37 using value_type = std::pair<PdfName, TObject*>;
38 using pointer =
const value_type*;
39 using reference =
const value_type&;
40 using iterator_category = std::forward_iterator_tag;
46 Iterator(
const Iterator&) =
default;
47 Iterator& operator=(
const Iterator&) =
default;
48 bool operator==(
const Iterator&
rhs)
const;
49 bool operator!=(
const Iterator&
rhs)
const;
50 Iterator& operator++();
51 Iterator operator++(
int);
52 reference operator*();
63 Iterator begin()
const;
85 friend class PdfSignature;
87 friend class PdfObjectOutputStream;
208 const PdfObject& MustFindKey(
const std::string_view&
key)
const;
223 const PdfObject& MustFindKeyParent(
const std::string_view&
key)
const;
224 PdfObject& MustFindKeyParent(
const std::string_view&
key);
242 template <
typename T>
243 T GetKeyAs(
const std::string_view&
key,
const std::common_type_t<T>&
defvalue = { })
const;
245 template <
typename T>
246 T FindKeyAs(
const std::string_view&
key,
const std::common_type_t<T>&
defvalue = { })
const;
248 template <
typename T>
249 T FindKeyParentAs(
const std::string_view& key,
const std::common_type_t<T>& defvalue = { })
const;
251 template <
typename T>
252 T FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& defvalue = { })
const;
254 template <
typename T>
255 T FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& defvalue = { })
const;
257 template <
typename T>
258 bool TryFindKeyAs(
const std::string_view& key, T& value)
const;
260 template <
typename T>
261 bool TryFindKeyParentAs(
const std::string_view& key, T& value)
const;
268 bool HasKey(
const std::string_view& key)
const;
281 bool RemoveKey(
const std::string_view& key);
283 void Write(OutputStream& stream, PdfWriteFlags writeMode,
284 const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const override;
289 unsigned GetSize()
const;
291 PdfDictionaryIndirectIterable GetIndirectIterator();
293 PdfDictionaryConstIndirectIterable GetIndirectIterator()
const;
296 using iterator = PdfNameMap<PdfObject>::iterator;
297 using const_iterator = PdfNameMap<PdfObject>::const_iterator;
302 const_iterator begin()
const;
303 const_iterator end()
const;
307 void resetDirty()
override;
308 void setChildrenParent()
override;
312 void AddKeyNoDirtySet(
const PdfName& key, PdfObject&& obj);
313 void AddKeyNoDirtySet(
const PdfName& key, PdfVariant&& var);
314 void RemoveKeyNoDirtySet(
const std::string_view& key);
316 PdfObject& EmplaceNoDirtySet(
const PdfName& key);
319 PdfObject& addKey(
const PdfName& key, PdfObject&& obj);
320 PdfObject* getKey(
const std::string_view& key)
const;
321 PdfObject* findKey(
const std::string_view& key)
const;
322 PdfObject* findKeyParent(
const std::string_view& key)
const;
323 void write(OutputStream& stream, PdfWriteFlags writeMode,
bool addDelimiters,
324 const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const;
327 PdfNameMap<PdfObject> m_Map;
331T PdfDictionary::GetKeyAs(
const std::string_view& key,
const std::common_type_t<T>& defvalue)
const
333 auto obj = getKey(key);
337 return Object<T>::Get(*obj);
341T PdfDictionary::FindKeyAs(
const std::string_view& key,
const std::common_type_t<T>& defvalue)
const
343 auto obj = findKey(key);
347 return Object<T>::Get(*obj);
351T PdfDictionary::FindKeyParentAs(
const std::string_view& key,
const std::common_type_t<T>& defvalue)
const
353 auto obj = findKeyParent(key);
358 return Object<T>::Get(*obj);
362T PdfDictionary::FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& defvalue)
const
365 auto obj = findKey(key);
366 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
373T PdfDictionary::FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& defvalue)
const
376 auto obj = findKeyParent(key);
377 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
384bool PdfDictionary::TryFindKeyAs(
const std::string_view& key, T& value)
const
386 auto obj = findKey(key);
387 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
399bool PdfDictionary::TryFindKeyParentAs(
const std::string_view& key, T& value)
const
401 auto obj = findKeyParent(key);
402 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
413template <
typename TObject,
typename TMapIterator>
414PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase()
415 : m_dict(nullptr) { }
417template <
typename TObject,
typename TMapIterator>
418PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase(PdfDictionary& dict)
419 : PdfIndirectIterableBase(dict), m_dict(&dict) { }
421template <
typename TObject,
typename TMapIterator>
422typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::begin()
const
424 if (m_dict ==
nullptr)
427 return Iterator(m_dict->begin(), GetObjects());
430template <
typename TObject,
typename TMapIterator>
431typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::end()
const
433 if (m_dict ==
nullptr)
436 return Iterator(m_dict->end(), GetObjects());
439template<
typename TObject,
typename TMapIterator>
440PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator() : m_objects(nullptr) { }
442template<
typename TObject,
typename TMapIterator>
443PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator(TMapIterator&& iterator, PdfIndirectObjectList* objects)
444 : m_iterator(std::move(iterator)), m_objects(objects) { }
446template<
typename TObject,
typename TMapIterator>
447bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator==(
const Iterator& rhs)
const
449 return m_iterator == rhs.m_iterator;
452template<
typename TObject,
typename TMapIterator>
453bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator!=(
const Iterator& rhs)
const
455 return m_iterator != rhs.m_iterator;
458template<
typename TObject,
typename TMapIterator>
459typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator& PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++()
465template<
typename TObject,
typename TMapIterator>
466typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++(
int)
473template<
typename TObject,
typename TMapIterator>
474typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::reference PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator*()
480template<
typename TObject,
typename TMapIterator>
481typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::pointer PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator->()
487template<
typename TObject,
typename TMapIterator>
488void PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::resolve()
490 TObject& robj = m_iterator->second;
491 TObject* indirectobj;
493 if (m_objects !=
nullptr
494 && robj.TryGetReference(ref)
496 && (indirectobj = GetObject(*m_objects, ref)) !=
nullptr)
498 m_pair = value_type(m_iterator->first, indirectobj);
502 m_pair = value_type(m_iterator->first, &robj);
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
A PdfDataProvider object with a PdfObject owner, specialized in holding objects.
Definition PdfDataContainer.h:22
Helper class to iterate through indirect objects.
Definition PdfDictionary.h:22
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition PdfDictionary.h:82
const PdfObject * FindKeyParent(const std::string_view &key) const
Get the keys value out of the dictionary.
const PdfObject * GetKey(const std::string_view &key) const
Get the key's value out of the dictionary.
const PdfObject * FindKey(const std::string_view &key) const
Get the keys value out of the dictionary.
PdfObject * GetKey(const std::string_view &key)
Get the key's value out of the dictionary.
const PdfObject & MustGetKey(const std::string_view &key) const
Get the key's value out of the dictionary.
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 PdfName.
Definition PdfName.h:24
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition PdfObjectStream.h:87
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:36
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