7 #ifndef PDF_DICTIONARY_H
8 #define PDF_DICTIONARY_H
11 #include "PdfDataContainer.h"
20 template <
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*();
57 TMapIterator m_iterator;
63 Iterator begin()
const;
85 friend class PdfSignature;
87 friend class PdfObjectOutputStream;
207 PdfObject* FindKey(
const std::string_view& key);
208 const PdfObject& MustFindKey(
const std::string_view& key)
const;
209 PdfObject& MustFindKey(
const std::string_view& key);
222 PdfObject* FindKeyParent(
const std::string_view& key);
223 const PdfObject& MustFindKeyParent(
const std::string_view& key)
const;
224 PdfObject& MustFindKeyParent(
const std::string_view& key);
240 PdfObject& MustGetKey(
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);
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;
331 T 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);
341 T 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);
351 T 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);
362 T 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))
373 T 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))
383 template <
typename T>
384 bool PdfDictionary::TryFindKeyAs(
const std::string_view& key, T& value)
const
386 auto obj = findKey(key);
387 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
398 template <
typename T>
399 bool PdfDictionary::TryFindKeyParentAs(
const std::string_view& key, T& value)
const
401 auto obj = findKeyParent(key);
402 if (obj !=
nullptr && Object<T>::TryGet(*obj, value))
413 template <
typename TObject,
typename TMapIterator>
414 PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase()
415 : m_dict(nullptr) { }
417 template <
typename TObject,
typename TMapIterator>
418 PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase(PdfDictionary& dict)
419 : PdfIndirectIterableBase(dict), m_dict(&dict) { }
421 template <
typename TObject,
typename TMapIterator>
422 typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::begin()
const
424 if (m_dict ==
nullptr)
427 return Iterator(m_dict->begin(), GetObjects());
430 template <
typename TObject,
typename TMapIterator>
431 typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::end()
const
433 if (m_dict ==
nullptr)
436 return Iterator(m_dict->end(), GetObjects());
439 template<
typename TObject,
typename TMapIterator>
440 PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator() : m_objects(nullptr) { }
442 template<
typename TObject,
typename TMapIterator>
443 PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator(TMapIterator&& iterator, PdfIndirectObjectList* objects)
444 : m_iterator(std::move(iterator)), m_objects(objects) { }
446 template<
typename TObject,
typename TMapIterator>
447 bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator==(
const Iterator& rhs)
const
449 return m_iterator == rhs.m_iterator;
452 template<
typename TObject,
typename TMapIterator>
453 bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator!=(
const Iterator& rhs)
const
455 return m_iterator != rhs.m_iterator;
458 template<
typename TObject,
typename TMapIterator>
459 typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator& PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++()
465 template<
typename TObject,
typename TMapIterator>
466 typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++(
int)
473 template<
typename TObject,
typename TMapIterator>
474 typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::reference PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator*()
480 template<
typename TObject,
typename TMapIterator>
481 typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::pointer PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator->()
487 template<
typename TObject,
typename TMapIterator>
488 void 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 & MustGetKey(const std::string_view &key) const
Get the key's 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 * FindKeyParent(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 * FindKey(const std::string_view &key) const
Get the keys 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:53
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