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 const typename ObjectAdapter<T>::TRet GetKeyAs(
const std::string_view&
key)
const;
245 template <
typename T>
246 typename ObjectAdapter<T>::TRet GetKeyAs(
const std::string_view&
key);
248 template <
typename T>
249 const typename ObjectAdapter<T>::TRet FindKeyAs(
const std::string_view&
key)
const;
251 template <
typename T>
252 typename ObjectAdapter<T>::TRet FindKeyAs(
const std::string_view&
key);
254 template <
typename T>
255 const typename ObjectAdapter<T>::TRet FindKeyParentAs(
const std::string_view&
key)
const;
257 template <
typename T>
258 typename ObjectAdapter<T>::TRet FindKeyParentAs(
const std::string_view&
key);
260 template <
typename T>
261 const typename ObjectAdapter<T>::TRet GetKeyAsSafe(
const std::string_view&
key,
const std::common_type_t<T>&
fallback = { })
const;
263 template <
typename T>
264 typename ObjectAdapter<T>::TRet GetKeyAsSafe(
const std::string_view&
key,
const std::common_type_t<T>&
fallback = { });
266 template <
typename T>
267 const typename ObjectAdapter<T>::TRet FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { })
const;
269 template <
typename T>
270 typename ObjectAdapter<T>::TRet FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { });
272 template <
typename T>
273 const typename ObjectAdapter<T>::TRet FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { })
const;
275 template <
typename T>
276 typename ObjectAdapter<T>::TRet FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { });
278 template <
typename T>
279 bool TryFindKeyAs(
const std::string_view& key, T& value)
const;
281 template <
typename T>
282 bool TryFindKeyAs(
const std::string_view& key, T& value);
284 template <
typename T>
285 bool TryFindKeyParentAs(
const std::string_view& key, T& value)
const;
287 template <
typename T>
288 bool TryFindKeyParentAs(
const std::string_view& key, T& value);
295 bool HasKey(
const std::string_view& key)
const;
308 bool RemoveKey(
const std::string_view& key);
310 void Write(OutputStream& stream, PdfWriteFlags writeMode,
311 const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const override;
316 unsigned GetSize()
const;
318 PdfDictionaryIndirectIterable GetIndirectIterator();
320 PdfDictionaryConstIndirectIterable GetIndirectIterator()
const;
323 using iterator = PdfNameMap<PdfObject>::iterator;
324 using const_iterator = PdfNameMap<PdfObject>::const_iterator;
329 const_iterator begin()
const;
330 const_iterator end()
const;
334 void resetDirty()
override;
335 void setChildrenParent()
override;
339 void AddKeyNoDirtySet(
const PdfName& key, PdfObject&& obj);
340 void AddKeyNoDirtySet(
const PdfName& key, PdfVariant&& var);
341 void RemoveKeyNoDirtySet(
const std::string_view& key);
343 PdfObject& EmplaceNoDirtySet(
const PdfName& key);
346 PdfObject& addKey(
const PdfName& key, PdfObject&& obj);
347 PdfObject* getKey(
const std::string_view& key)
const;
348 PdfObject* findKey(
const std::string_view& key)
const;
349 PdfObject* findKeyParent(
const std::string_view& key)
const;
350 void write(OutputStream& stream, PdfWriteFlags writeMode,
bool addDelimiters,
351 const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const;
354 PdfNameMap<PdfObject> m_Map;
358const typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAs(
const std::string_view& key)
const
360 return ObjectAdapter<T>::Get(
MustGetKey(key));
364typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAs(
const std::string_view& key)
366 return ObjectAdapter<T>::Get(
MustGetKey(key));
370const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAs(
const std::string_view& key)
const
372 return ObjectAdapter<T>::Get(MustFindKey(key));
376typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAs(
const std::string_view& key)
378 return ObjectAdapter<T>::Get(MustFindKey(key));
382const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAs(
const std::string_view& key)
const
384 return ObjectAdapter<T>::Get(MustFindKeyParent(key));
388typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAs(
const std::string_view& key)
390 return ObjectAdapter<T>::Get(MustFindKeyParent(key));
394const typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
const
396 auto obj = getKey(key);
400 return ObjectAdapter<T>::Get(
const_cast<const PdfObject&
>(*obj), fallback);
404typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
406 auto obj = getKey(key);
410 return ObjectAdapter<T>::Get(*obj, fallback);
414const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
const
416 auto obj = findKey(key);
420 return ObjectAdapter<T>::Get(
const_cast<const PdfObject&
>(*obj), fallback);
424typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
426 auto obj = findKey(key);
430 return ObjectAdapter<T>::Get(*obj, fallback);
434const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
const
436 auto obj = findKeyParent(key);
440 return ObjectAdapter<T>::Get(
const_cast<const PdfObject&
>(*obj), fallback);
444typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
446 auto obj = findKeyParent(key);
450 return ObjectAdapter<T>::Get(*obj, fallback);
454bool PdfDictionary::TryFindKeyAs(
const std::string_view& key, T& value)
const
456 auto obj = findKey(key);
457 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(
const_cast<const PdfObject&
>(*obj), value))
469bool PdfDictionary::TryFindKeyAs(
const std::string_view& key, T& value)
471 auto obj = findKey(key);
472 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(*obj, value))
484bool PdfDictionary::TryFindKeyParentAs(
const std::string_view& key, T& value)
const
486 auto obj = findKeyParent(key);
487 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(
const_cast<const PdfObject&
>(*obj), value))
499bool PdfDictionary::TryFindKeyParentAs(
const std::string_view& key, T& value)
501 auto obj = findKeyParent(key);
502 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(*obj, value))
513template <
typename TObject,
typename TMapIterator>
514PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase()
515 : m_dict(nullptr) { }
517template <
typename TObject,
typename TMapIterator>
518PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase(PdfDictionary& dict)
519 : PdfIndirectIterableBase(dict), m_dict(&dict) { }
521template <
typename TObject,
typename TMapIterator>
522typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::begin()
const
524 if (m_dict ==
nullptr)
527 return Iterator(m_dict->begin(), GetObjects());
530template <
typename TObject,
typename TMapIterator>
531typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::end()
const
533 if (m_dict ==
nullptr)
536 return Iterator(m_dict->end(), GetObjects());
539template<
typename TObject,
typename TMapIterator>
540PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator() : m_objects(nullptr) { }
542template<
typename TObject,
typename TMapIterator>
543PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator(TMapIterator&& iterator, PdfIndirectObjectList* objects)
544 : m_iterator(std::move(iterator)), m_objects(objects) { }
546template<
typename TObject,
typename TMapIterator>
547bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator==(
const Iterator& rhs)
const
549 return m_iterator == rhs.m_iterator;
552template<
typename TObject,
typename TMapIterator>
553bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator!=(
const Iterator& rhs)
const
555 return m_iterator != rhs.m_iterator;
558template<
typename TObject,
typename TMapIterator>
559typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator& PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++()
565template<
typename TObject,
typename TMapIterator>
566typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++(
int)
573template<
typename TObject,
typename TMapIterator>
574typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::reference PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator*()
580template<
typename TObject,
typename TMapIterator>
581typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::pointer PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator->()
587template<
typename TObject,
typename TMapIterator>
588void PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::resolve()
590 TObject& robj = m_iterator->second;
591 TObject* indirectobj;
593 if (m_objects !=
nullptr
594 && robj.TryGetReference(ref)
596 && (indirectobj = GetObject(*m_objects, ref)) !=
nullptr)
598 m_pair = value_type(m_iterator->first, indirectobj);
602 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