5#ifndef PDF_DICTIONARY_H
6#define PDF_DICTIONARY_H
9#include "PdfDataContainer.h"
16template <
typename TObject,
typename TMapIterator>
32 using difference_type =
void;
33 using value_type = std::pair<PdfName, TObject*>;
34 using pointer =
const value_type*;
35 using reference =
const value_type&;
36 using iterator_category = std::forward_iterator_tag;
42 Iterator(
const Iterator&) =
default;
43 Iterator& operator=(
const Iterator&) =
default;
44 bool operator==(
const Iterator&
rhs)
const;
45 bool operator!=(
const Iterator&
rhs)
const;
46 Iterator& operator++();
47 Iterator operator++(
int);
48 reference operator*();
59 Iterator begin()
const;
80 friend class PdfSignature;
82 friend class PdfObjectOutputStream;
189 const PdfObject& MustFindKey(
const std::string_view&
key)
const;
203 const PdfObject& MustFindKeyParent(
const std::string_view&
key)
const;
204 PdfObject& MustFindKeyParent(
const std::string_view&
key);
221 template <
typename T>
222 const typename ObjectAdapter<T>::TRet GetKeyAs(
const std::string_view&
key)
const;
224 template <
typename T>
225 typename ObjectAdapter<T>::TRet GetKeyAs(
const std::string_view&
key);
227 template <
typename T>
228 const typename ObjectAdapter<T>::TRet FindKeyAs(
const std::string_view&
key)
const;
230 template <
typename T>
231 typename ObjectAdapter<T>::TRet FindKeyAs(
const std::string_view&
key);
233 template <
typename T>
234 const typename ObjectAdapter<T>::TRet FindKeyParentAs(
const std::string_view&
key)
const;
236 template <
typename T>
237 typename ObjectAdapter<T>::TRet FindKeyParentAs(
const std::string_view&
key);
239 template <
typename T>
240 const typename ObjectAdapter<T>::TRet GetKeyAsSafe(
const std::string_view&
key,
const std::common_type_t<T>&
fallback = { })
const;
242 template <
typename T>
243 typename ObjectAdapter<T>::TRet GetKeyAsSafe(
const std::string_view&
key,
const std::common_type_t<T>&
fallback = { });
245 template <
typename T>
246 const typename ObjectAdapter<T>::TRet FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { })
const;
248 template <
typename T>
249 typename ObjectAdapter<T>::TRet FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { });
251 template <
typename T>
252 const typename ObjectAdapter<T>::TRet FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { })
const;
254 template <
typename T>
255 typename ObjectAdapter<T>::TRet FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback = { });
257 template <
typename T>
258 bool TryFindKeyAs(
const std::string_view& key, T& value)
const;
260 template <
typename T>
261 bool TryFindKeyAs(
const std::string_view& key, T& value);
263 template <
typename T>
264 bool TryFindKeyParentAs(
const std::string_view& key, T& value)
const;
266 template <
typename T>
267 bool TryFindKeyParentAs(
const std::string_view& key, T& value);
273 bool HasKey(
const std::string_view& key)
const;
285 bool RemoveKey(
const std::string_view& key);
287 void Write(OutputStream& stream, PdfWriteFlags writeMode,
288 const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const override;
291 unsigned GetSize()
const;
293 PdfDictionaryIndirectIterable GetIndirectIterator();
295 PdfDictionaryConstIndirectIterable GetIndirectIterator()
const;
298 using iterator = PdfNameMap<PdfObject>::iterator;
299 using const_iterator = PdfNameMap<PdfObject>::const_iterator;
304 const_iterator begin()
const;
305 const_iterator end()
const;
309 void resetDirty()
override;
310 void setChildrenParent()
override;
314 void AddKeyNoDirtySet(
const PdfName& key, PdfObject&& obj);
315 void AddKeyNoDirtySet(
const PdfName& key, PdfVariant&& var);
316 void RemoveKeyNoDirtySet(
const std::string_view& key);
318 PdfObject& EmplaceNoDirtySet(
const PdfName& key);
321 PdfObject& addKey(
const PdfName& key, PdfObject&& obj);
322 PdfObject* getKey(
const std::string_view& key)
const;
323 PdfObject* findKey(
const std::string_view& key)
const;
324 PdfObject* findKeyParent(
const std::string_view& key)
const;
325 void write(OutputStream& stream, PdfWriteFlags writeMode,
bool addDelimiters,
326 const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const;
329 PdfNameMap<PdfObject> m_Map;
333const typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAs(
const std::string_view& key)
const
335 return ObjectAdapter<T>::Get(
MustGetKey(key));
339typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAs(
const std::string_view& key)
341 return ObjectAdapter<T>::Get(
MustGetKey(key));
345const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAs(
const std::string_view& key)
const
347 return ObjectAdapter<T>::Get(MustFindKey(key));
351typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAs(
const std::string_view& key)
353 return ObjectAdapter<T>::Get(MustFindKey(key));
357const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAs(
const std::string_view& key)
const
359 return ObjectAdapter<T>::Get(MustFindKeyParent(key));
363typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAs(
const std::string_view& key)
365 return ObjectAdapter<T>::Get(MustFindKeyParent(key));
369const typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
const
371 auto obj = getKey(key);
375 return ObjectAdapter<T>::Get(
const_cast<const PdfObject&
>(*obj), fallback);
379typename ObjectAdapter<T>::TRet PdfDictionary::GetKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
381 auto obj = getKey(key);
385 return ObjectAdapter<T>::Get(*obj, fallback);
389const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
const
391 auto obj = findKey(key);
395 return ObjectAdapter<T>::Get(
const_cast<const PdfObject&
>(*obj), fallback);
399typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
401 auto obj = findKey(key);
405 return ObjectAdapter<T>::Get(*obj, fallback);
409const typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
const
411 auto obj = findKeyParent(key);
415 return ObjectAdapter<T>::Get(
const_cast<const PdfObject&
>(*obj), fallback);
419typename ObjectAdapter<T>::TRet PdfDictionary::FindKeyParentAsSafe(
const std::string_view& key,
const std::common_type_t<T>& fallback)
421 auto obj = findKeyParent(key);
425 return ObjectAdapter<T>::Get(*obj, fallback);
429bool PdfDictionary::TryFindKeyAs(
const std::string_view& key, T& value)
const
431 auto obj = findKey(key);
432 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(
const_cast<const PdfObject&
>(*obj), value))
444bool PdfDictionary::TryFindKeyAs(
const std::string_view& key, T& value)
446 auto obj = findKey(key);
447 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(*obj, value))
459bool PdfDictionary::TryFindKeyParentAs(
const std::string_view& key, T& value)
const
461 auto obj = findKeyParent(key);
462 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(
const_cast<const PdfObject&
>(*obj), value))
474bool PdfDictionary::TryFindKeyParentAs(
const std::string_view& key, T& value)
476 auto obj = findKeyParent(key);
477 if (obj !=
nullptr && ObjectAdapter<T>::TryGet(*obj, value))
488template <
typename TObject,
typename TMapIterator>
489PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase()
490 : m_dict(nullptr) { }
492template <
typename TObject,
typename TMapIterator>
493PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::PdfDictionaryIndirectIterableBase(PdfDictionary& dict)
494 : PdfIndirectIterableBase(dict), m_dict(&dict) { }
496template <
typename TObject,
typename TMapIterator>
497typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::begin()
const
499 if (m_dict ==
nullptr)
502 return Iterator(m_dict->begin(), GetObjects());
505template <
typename TObject,
typename TMapIterator>
506typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::end()
const
508 if (m_dict ==
nullptr)
511 return Iterator(m_dict->end(), GetObjects());
514template<
typename TObject,
typename TMapIterator>
515PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator() : m_objects(nullptr) { }
517template<
typename TObject,
typename TMapIterator>
518PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::Iterator(TMapIterator&& iterator, PdfIndirectObjectList* objects)
519 : m_iterator(std::move(iterator)), m_objects(objects) { }
521template<
typename TObject,
typename TMapIterator>
522bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator==(
const Iterator& rhs)
const
524 return m_iterator == rhs.m_iterator;
527template<
typename TObject,
typename TMapIterator>
528bool PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator!=(
const Iterator& rhs)
const
530 return m_iterator != rhs.m_iterator;
533template<
typename TObject,
typename TMapIterator>
534typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator& PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++()
540template<
typename TObject,
typename TMapIterator>
541typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator++(
int)
548template<
typename TObject,
typename TMapIterator>
549typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::reference PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator*()
555template<
typename TObject,
typename TMapIterator>
556typename PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::pointer PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::operator->()
562template<
typename TObject,
typename TMapIterator>
563void PdfDictionaryIndirectIterableBase<TObject, TMapIterator>::Iterator::resolve()
565 TObject& robj = m_iterator->second;
566 TObject* indirectobj;
568 if (m_objects !=
nullptr
569 && robj.TryGetReference(ref)
571 && (indirectobj = GetObject(*m_objects, ref)) !=
nullptr)
573 m_pair = value_type(m_iterator->first, indirectobj);
577 m_pair = value_type(m_iterator->first, &robj);
This file should be included as the FIRST file in every header of PoDoFo lib.
A PdfDataProvider object with a PdfObject owner, specialized in holding objects.
Definition PdfDataContainer.h:18
Helper class to iterate through indirect objects.
Definition PdfDictionary.h:18
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition PdfDictionary.h:77
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:28
This class represents a PdfName.
Definition PdfName.h:21
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition PdfObjectStream.h:82
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
A simple tokenizer for PDF files and PDF content streams.
Definition PdfTokenizer.h:32
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13