PoDoFo
1.0.0-dev
|
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such representations) Note: manipulation function accepts PdfName for the key, while getters accept std::string_view. More...
#include <PdfDictionary.h>
Public Types | |
using | iterator = PdfNameMap< PdfObject >::iterator |
using | const_iterator = PdfNameMap< PdfObject >::const_iterator |
Public Member Functions | |
PdfDictionary () | |
Create a new, empty dictionary. | |
PdfDictionary (const PdfDictionary &rhs) | |
Deep copy a dictionary. More... | |
PdfDictionary (PdfDictionary &&rhs) noexcept | |
PdfDictionary & | operator= (const PdfDictionary &rhs) |
Assignment operator. More... | |
PdfDictionary & | operator= (PdfDictionary &&rhs) noexcept |
bool | operator== (const PdfDictionary &rhs) const |
Comparison operator. More... | |
bool | operator!= (const PdfDictionary &rhs) const |
void | Clear () |
Removes all keys from the dictionary. | |
PdfObject & | AddKey (const PdfName &key, const PdfObject &obj) |
Add a key to the dictionary. More... | |
PdfObject & | AddKey (const PdfName &key, PdfObject &&obj) |
void | AddKeyIndirect (const PdfName &key, const PdfObject &obj) |
Add a key to the dictionary. More... | |
PdfObject & | AddKeyIndirectSafe (const PdfName &key, const PdfObject &obj) |
Add a key to the dictionary. More... | |
const PdfObject * | GetKey (const std::string_view &key) const |
Get the key's value out of the dictionary. More... | |
PdfObject * | GetKey (const std::string_view &key) |
Get the key's value out of the dictionary. More... | |
const PdfObject * | FindKey (const std::string_view &key) const |
Get the keys value out of the dictionary. More... | |
PdfObject * | FindKey (const std::string_view &key) |
const PdfObject & | MustFindKey (const std::string_view &key) const |
PdfObject & | MustFindKey (const std::string_view &key) |
const PdfObject * | FindKeyParent (const std::string_view &key) const |
Get the keys value out of the dictionary. More... | |
PdfObject * | FindKeyParent (const std::string_view &key) |
const PdfObject & | MustFindKeyParent (const std::string_view &key) const |
PdfObject & | MustFindKeyParent (const std::string_view &key) |
const PdfObject & | MustGetKey (const std::string_view &key) const |
Get the key's value out of the dictionary. More... | |
PdfObject & | MustGetKey (const std::string_view &key) |
template<typename T > | |
T | GetKeyAs (const std::string_view &key, const std::common_type_t< T > &defvalue={ }) const |
template<typename T > | |
T | FindKeyAs (const std::string_view &key, const std::common_type_t< T > &defvalue={ }) const |
template<typename T > | |
T | FindKeyParentAs (const std::string_view &key, const std::common_type_t< T > &defvalue={ }) const |
template<typename T > | |
T | FindKeyAsSafe (const std::string_view &key, const std::common_type_t< T > &defvalue={ }) const |
template<typename T > | |
T | FindKeyParentAsSafe (const std::string_view &key, const std::common_type_t< T > &defvalue={ }) const |
template<typename T > | |
bool | TryFindKeyAs (const std::string_view &key, T &value) const |
template<typename T > | |
bool | TryFindKeyParentAs (const std::string_view &key, T &value) const |
bool | HasKey (const std::string_view &key) const |
Allows to check if a dictionary contains a certain key. More... | |
bool | RemoveKey (const std::string_view &key) |
Remove a key from this dictionary. More... | |
void | Write (OutputStream &stream, PdfWriteFlags writeMode, const PdfStatefulEncrypt *encrypt, charbuff &buffer) const override |
Write the complete datatype to a file. More... | |
unsigned | GetSize () const |
PdfDictionaryIndirectIterable | GetIndirectIterator () |
PdfDictionaryConstIndirectIterable | GetIndirectIterator () const |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
size_t | size () const |
Public Member Functions inherited from PoDoFo::PdfDataContainer | |
const PdfObject * | GetOwner () const |
PdfObject * | GetOwner () |
Public Member Functions inherited from PoDoFo::PdfDataProvider< PdfDataContainer > | |
std::string | ToString (PdfWriteFlags flags=PdfWriteFlags::None) const |
Converts the current object into a string representation which can be written directly to a PDF file on disc. More... | |
void | ToString (std::string &str, PdfWriteFlags flags=PdfWriteFlags::None) const |
Protected Member Functions | |
void | resetDirty () override |
void | setChildrenParent () override |
Protected Member Functions inherited from PoDoFo::PdfDataContainer | |
PdfObject * | GetIndirectObject (const PdfReference &reference) const |
PdfDocument * | GetObjectDocument () |
void | SetDirty () |
bool | IsIndirectReferenceAllowed (const PdfObject &obj) |
void | AssertMutable () const |
Friends | |
class | PdfObject |
class | PdfTokenizer |
class | PdfSignature |
class | PdfObjectStream |
class | PdfObjectOutputStream |
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such representations) Note: manipulation function accepts PdfName for the key, while getters accept std::string_view.
This is an optimization since we do lookup with both types. We also assume doing lookups with strings will only use characters compatible with PdfDocEncoding
PdfDictionary::PdfDictionary | ( | const PdfDictionary & | rhs | ) |
Deep copy a dictionary.
rhs | the PdfDictionary to copy |
Add a key to the dictionary.
If an existing key of this name exists, its value is replaced and the old value object will be deleted. The given object is copied.
This will set the dirty flag of this object.
key | the key is identified by this name in the dictionary |
obj | object containing the data. The object is copied. |
Add a key to the dictionary.
If an existing key of this name exists, its value is replaced and the old value object will be deleted. The object must be indirect and the object reference will be added instead to the dictionary
This will set the dirty flag of this object.
key | the key is identified by this name in the dictionary |
obj | object containing the data |
PdfError::InvalidHandle | on nullptr obj or if the object can't be added as an indirect reference |
Add a key to the dictionary.
If an existing key of this name exists, its value is replaced and the old value object will be deleted. If the object is indirect the object reference will be added instead to the dictionary, otherwise the object is copied
This will set the dirty flag of this object.
key | the key is identified by this name in the dictionary |
obj | a variant object containing the data |
PdfError::InvalidHandle | on nullptr obj |
const PdfObject* PoDoFo::PdfDictionary::FindKey | ( | const std::string_view & | key | ) | const |
Get the keys value out of the dictionary.
Lookup in the indirect objects as well, if the shallow object was a reference. The returned value is a pointer to the internal object in the dictionary so it MUST not be deleted.
key | look for the key names key in the dictionary |
const PdfObject* PoDoFo::PdfDictionary::FindKeyParent | ( | const std::string_view & | key | ) | const |
Get the keys value out of the dictionary.
Lookup in the indirect objects as well, if the shallow object was a reference. Also lookup the parent objects, if /Parent key is found in the dictionary. The returned value is a pointer to the internal object in the dictionary so it MUST not be deleted.
key | look for the key names key in the dictionary |
PdfObject* PoDoFo::PdfDictionary::GetKey | ( | const std::string_view & | key | ) |
Get the key's value out of the dictionary.
This is an overloaded member function.
The returned value is a pointer to the internal object in the dictionary. It may be modified but is still owned by the dictionary so it MUST not be deleted.
key | look for the key named key in the dictionary |
const PdfObject* PoDoFo::PdfDictionary::GetKey | ( | const std::string_view & | key | ) | const |
Get the key's value out of the dictionary.
The returned value is a pointer to the internal object in the dictionary so it MUST not be deleted.
key | look for the key named key in the dictionary |
unsigned PdfDictionary::GetSize | ( | ) | const |
bool PdfDictionary::HasKey | ( | const std::string_view & | key | ) | const |
Allows to check if a dictionary contains a certain key.
key | look for the key named key.Name() in the dictionary |
const PdfObject& PoDoFo::PdfDictionary::MustGetKey | ( | const std::string_view & | key | ) | const |
Get the key's value out of the dictionary.
The returned value is a reference to the internal object in the dictionary so it MUST not be deleted. If the key is not found, this throws a PdfError exception with error code PdfErrorCode::NoObject, instead of returning. This is intended to make code more readable by sparing (especially multiple) nullptr checks.
key | look for the key named key in the dictionary |
PdfError(PdfErrorCode::NoObject). |
bool PdfDictionary::operator!= | ( | const PdfDictionary & | rhs | ) | const |
PdfDictionary & PdfDictionary::operator= | ( | const PdfDictionary & | rhs | ) |
Assignment operator.
Assign another PdfDictionary to this dictionary. This is a deep copy; all elements of the source dictionary are duplicated.
rhs | the PdfDictionary to copy. |
This will set the dirty flag of this object.
bool PdfDictionary::operator== | ( | const PdfDictionary & | rhs | ) | const |
Comparison operator.
If this dictionary contains all the same keys as the other dictionary, and for each key the values compare equal, the dictionaries are considered equal.
bool PdfDictionary::RemoveKey | ( | const std::string_view & | key | ) |
Remove a key from this dictionary.
If the key does not exist, this function does nothing.
key | the name of the key to delete |
This will set the dirty flag of this object.
|
overridevirtual |
Write the complete datatype to a file.
device | write the object to this device |
writeMode | additional options for writing this object |
encrypt | an encryption object which is used to encrypt this object or nullptr to not encrypt this object |
Implements PoDoFo::PdfDataContainer.