Loading...
Searching...
No Matches
xmp_exiv2.hpp
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef XMP_HPP_
#define XMP_HPP_
// *****************************************************************************
#include "exiv2lib_export.h"
// included header files
#include "metadatum.hpp"
#include "properties.hpp"
// *****************************************************************************
// namespace extensions
namespace Exiv2 {
// *****************************************************************************
// class declarations
class ExifData;
// *****************************************************************************
// class definitions
class EXIV2API Xmpdatum : public Metadatum {
public:
explicit Xmpdatum(const XmpKey& key, const Value* pValue = nullptr);
Xmpdatum(const Xmpdatum& rhs);
~Xmpdatum() override;
Xmpdatum& operator=(const Xmpdatum& rhs);
Xmpdatum& operator=(const std::string& value);
template <typename T>
Xmpdatum& operator=(const T& value);
Xmpdatum& operator=(const Value& value);
void setValue(const Value* pValue) override;
int setValue(const std::string& value) override;
size_t copy(byte* buf, ByteOrder byteOrder) const override;
std::ostream& write(std::ostream& os, const ExifData* pMetadata = nullptr) const override;
[[nodiscard]] std::string key() const override;
[[nodiscard]] const char* familyName() const override;
[[nodiscard]] std::string groupName() const override;
[[nodiscard]] std::string tagName() const override;
[[nodiscard]] std::string tagLabel() const override;
[[nodiscard]] std::string tagDesc() const override;
[[nodiscard]] uint16_t tag() const override;
[[nodiscard]] TypeId typeId() const override;
[[nodiscard]] const char* typeName() const override;
// Todo: Remove this method from the baseclass
[[nodiscard]] size_t typeSize() const override;
[[nodiscard]] size_t count() const override;
[[nodiscard]] size_t size() const override;
[[nodiscard]] std::string toString() const override;
[[nodiscard]] std::string toString(size_t n) const override;
[[nodiscard]] int64_t toInt64(size_t n = 0) const override;
[[nodiscard]] float toFloat(size_t n = 0) const override;
[[nodiscard]] Rational toRational(size_t n = 0) const override;
[[nodiscard]] Value::UniquePtr getValue() const override;
[[nodiscard]] const Value& value() const override;
private:
// Pimpl idiom
struct Impl;
std::unique_ptr<Impl> p_;
}; // class Xmpdatum
using XmpMetadata = std::vector<Xmpdatum>;
class EXIV2API XmpData {
public:
XmpData() = default;
using iterator = XmpMetadata::iterator;
using const_iterator = XmpMetadata::const_iterator;
Xmpdatum& operator[](const std::string& key);
int add(const XmpKey& key, const Value* value);
int add(const Xmpdatum& xmpdatum);
/*
@brief Delete the Xmpdatum at iterator position pos, return the
position of the next Xmpdatum.
@note Iterators into the metadata, including pos, are potentially
invalidated by this call.
@brief Delete the Xmpdatum at iterator position pos and update pos
*/
iterator erase(XmpData::iterator pos);
void eraseFamily(XmpData::iterator& pos);
void clear();
void sortByKey();
iterator begin();
iterator end();
iterator findKey(const XmpKey& key);
[[nodiscard]] const_iterator begin() const;
[[nodiscard]] const_iterator end() const;
[[nodiscard]] const_iterator findKey(const XmpKey& key) const;
[[nodiscard]] bool empty() const;
[[nodiscard]] long count() const;
[[nodiscard]] bool usePacket() const {
return usePacket_;
}
bool usePacket(bool b) {
bool r = usePacket_;
usePacket_ = b;
return r;
}
void setPacket(std::string xmpPacket) {
xmpPacket_ = std::move(xmpPacket);
usePacket(false);
}
// ! getPacket
[[nodiscard]] const std::string& xmpPacket() const {
return xmpPacket_;
}
private:
// DATA
XmpMetadata xmpMetadata_;
std::string xmpPacket_;
bool usePacket_{};
}; // class XmpData
class EXIV2API XmpParser {
public:
enum XmpFormatFlags {
omitPacketWrapper = 0x0010UL,
readOnlyPacket = 0x0020UL,
useCompactFormat = 0x0040UL,
includeThumbnailPad = 0x0100UL,
exactPacketLength = 0x0200UL,
writeAliasComments = 0x0400UL,
omitAllFormatting = 0x0800UL
};
static int decode(XmpData& xmpData, const std::string& xmpPacket);
static int encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t formatFlags = useCompactFormat,
uint32_t padding = 0);
using XmpLockFct = void (*)(void* pLockData, bool lockUnlock);
static bool initialize(XmpParser::XmpLockFct xmpLockFct = nullptr, void* pLockData = nullptr);
static void terminate();
private:
static void registerNs(const std::string& ns, const std::string& prefix);
static void unregisterNs(const std::string& ns);
static void registeredNamespaces(Exiv2::Dictionary&);
// DATA
static bool initialized_;
static XmpLockFct xmpLockFct_;
static void* pLockData_;
friend class XmpProperties; // permit XmpProperties -> registerNs() and registeredNamespaces()
}; // class XmpParser
// *****************************************************************************
// free functions, template and inline definitions
template <typename T>
Xmpdatum& Xmpdatum::operator=(const T& value) {
#ifdef __cpp_if_constexpr
if constexpr (std::is_same_v<T, bool>) {
#else
if (std::is_same<T, bool>::value) {
#endif
setValue(Exiv2::toString(value ? "True" : "False"));
return *this;
} else {
setValue(Exiv2::toString(value));
return *this;
}
}
} // namespace Exiv2
#endif // #ifndef XMP_HPP_
Exiv2::ExifData
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition exif.hpp:379
Exiv2::Value
Common interface for all types of values used with metadata.
Definition value.hpp:33
Exiv2::Value::UniquePtr
std::unique_ptr< Value > UniquePtr
Shortcut for a Value auto pointer.
Definition value.hpp:36
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition xmp_exiv2.hpp:138
Exiv2::XmpData::empty
bool empty() const
Return true if there is no XMP metadata.
Definition xmp.cpp:464
Exiv2::XmpData::end
iterator end()
End of the metadata.
Definition xmp.cpp:476
Exiv2::XmpData::count
long count() const
Get the number of metadata entries.
Definition xmp.cpp:468
Exiv2::XmpData::XmpData
XmpData()=default
Default constructor.
Exiv2::XmpData::eraseFamily
void eraseFamily(XmpData::iterator &pos)
Delete the Xmpdatum at iterator position pos and update pos erases all following keys from the same f...
Definition xmp.cpp:484
Exiv2::XmpData::setPacket
void setPacket(std::string xmpPacket)
setPacket
Definition xmp_exiv2.hpp:228
Exiv2::XmpData::usePacket
bool usePacket(bool b)
set usePacket_
Definition xmp_exiv2.hpp:222
Exiv2::XmpData::add
int add(const XmpKey &key, const Value *value)
Add an Xmpdatum from the supplied key and value pair. This method copies (clones) the value.
Definition xmp.cpp:431
Exiv2::XmpData::findKey
iterator findKey(const XmpKey &key)
Find the first Xmpdatum with the given key, return an iterator to it.
Definition xmp.cpp:444
Exiv2::XmpData::sortByKey
void sortByKey()
Sort metadata by key.
Definition xmp.cpp:452
Exiv2::XmpData::usePacket
bool usePacket() const
are we to use the packet?
Definition xmp_exiv2.hpp:217
Exiv2::XmpData::begin
iterator begin()
Begin of the metadata.
Definition xmp.cpp:472
Exiv2::XmpData::clear
void clear()
Delete all Xmpdatum instances resulting in an empty container.
Definition xmp.cpp:448
Exiv2::XmpData::const_iterator
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition xmp_exiv2.hpp:146
Exiv2::XmpData::operator[]
Xmpdatum & operator[](const std::string &key)
Returns a reference to the Xmpdatum that is associated with a particular key. If XmpData does not alr...
Definition xmp.cpp:421
Exiv2::XmpData::iterator
XmpMetadata::iterator iterator
XmpMetadata iterator type.
Definition xmp_exiv2.hpp:144
Exiv2::XmpKey
Concrete keys for XMP metadata.
Definition properties.hpp:207
Exiv2::XmpParser
Stateless parser class for XMP packets. Images use this class to parse and serialize XMP packets....
Definition xmp_exiv2.hpp:251
Exiv2::XmpParser::XmpLockFct
void(*)(void *pLockData, bool lockUnlock) XmpLockFct
Lock/unlock function type.
Definition xmp_exiv2.hpp:306
Exiv2::XmpParser::initialize
static bool initialize(XmpParser::XmpLockFct xmpLockFct=nullptr, void *pLockData=nullptr)
Initialize the XMP Toolkit.
Definition xmp.cpp:568
Exiv2::XmpParser::XmpFormatFlags
XmpFormatFlags
Options to control the format of the serialized XMP packet.
Definition xmp_exiv2.hpp:254
Exiv2::XmpParser::omitAllFormatting
@ omitAllFormatting
Omit all formatting whitespace.
Definition xmp_exiv2.hpp:261
Exiv2::XmpParser::writeAliasComments
@ writeAliasComments
Show aliases as XML comments.
Definition xmp_exiv2.hpp:260
Exiv2::XmpParser::omitPacketWrapper
@ omitPacketWrapper
Omit the XML packet wrapper.
Definition xmp_exiv2.hpp:255
Exiv2::XmpParser::readOnlyPacket
@ readOnlyPacket
Default is a writeable packet.
Definition xmp_exiv2.hpp:256
Exiv2::XmpParser::includeThumbnailPad
@ includeThumbnailPad
Include a padding allowance for a thumbnail image.
Definition xmp_exiv2.hpp:258
Exiv2::XmpParser::exactPacketLength
@ exactPacketLength
The padding parameter is the overall packet length.
Definition xmp_exiv2.hpp:259
Exiv2::XmpParser::useCompactFormat
@ useCompactFormat
Use a compact form of RDF.
Definition xmp_exiv2.hpp:257
Exiv2::XmpParser::terminate
static void terminate()
Terminate the XMP Toolkit and unregister custom namespaces.
Definition xmp.cpp:623
Exiv2::Xmpdatum
Information related to an XMP property. An XMP metadatum consists of an XmpKey and a Value and provid...
Definition xmp_exiv2.hpp:27
Exiv2::Xmpdatum::toFloat
float toFloat(size_t n=0) const override
Return the n-th component of the value converted to float. The return value is -1 if the value is not...
Definition xmp.cpp:368
Exiv2::Xmpdatum::write
std::ostream & write(std::ostream &os, const ExifData *pMetadata=nullptr) const override
Write the interpreted value to an output stream, return the stream.
Definition xmp.cpp:390
Exiv2::Xmpdatum::~Xmpdatum
~Xmpdatum() override
Destructor.
Exiv2::Xmpdatum::key
std::string key() const override
Return the key of the Xmpdatum. The key is of the form 'Xmp.prefix.property'. Note however that the k...
Definition xmp.cpp:308
Exiv2::Xmpdatum::toRational
Rational toRational(size_t n=0) const override
Return the n-th component of the value converted to Rational. The return value is -1/1 if the value i...
Definition xmp.cpp:372
Exiv2::Xmpdatum::value
const Value & value() const override
Return a constant reference to the value.
Definition xmp.cpp:380
Exiv2::Xmpdatum::typeId
TypeId typeId() const override
Return the type id of the value.
Definition xmp.cpp:336
Exiv2::Xmpdatum::operator=
Xmpdatum & operator=(const Xmpdatum &rhs)
Assignment operator.
Definition xmp.cpp:298
Exiv2::Xmpdatum::tagDesc
std::string tagDesc() const override
Return a description for the tag.
Definition xmp.cpp:328
Exiv2::Xmpdatum::groupName
std::string groupName() const override
Return the (preferred) schema namespace prefix.
Definition xmp.cpp:316
Exiv2::Xmpdatum::size
size_t size() const override
Return the size of the value in bytes.
Definition xmp.cpp:352
Exiv2::Xmpdatum::count
size_t count() const override
Return the number of components in the value.
Definition xmp.cpp:348
Exiv2::Xmpdatum::tag
uint16_t tag() const override
Properties don't have a tag number. Return 0.
Definition xmp.cpp:332
Exiv2::Xmpdatum::tagLabel
std::string tagLabel() const override
Return a label for the tag.
Definition xmp.cpp:324
Exiv2::Xmpdatum::typeSize
size_t typeSize() const override
The Exif typeSize doesn't make sense here. Return 0.
Definition xmp.cpp:344
Exiv2::Xmpdatum::getValue
Value::UniquePtr getValue() const override
Return an auto-pointer to a copy (clone) of the value. The caller owns this copy and the auto-poiner ...
Definition xmp.cpp:376
Exiv2::Xmpdatum::copy
size_t copy(byte *buf, ByteOrder byteOrder) const override
Not implemented. Calling this method will raise an exception.
Definition xmp.cpp:386
Exiv2::Xmpdatum::tagName
std::string tagName() const override
Return the property name.
Definition xmp.cpp:320
Exiv2::Xmpdatum::typeName
const char * typeName() const override
Return the name of the type.
Definition xmp.cpp:340
Exiv2::Xmpdatum::setValue
void setValue(const Value *pValue) override
Set the value. This method copies (clones) the value pointed to by pValue.
Definition xmp.cpp:404
Exiv2::Xmpdatum::toString
std::string toString() const override
Return the value as a string.
Definition xmp.cpp:356
Exiv2::Xmpdatum::toInt64
int64_t toInt64(size_t n=0) const override
Return the n-th component of the value converted to int64_t. The return value is -1 if the value is n...
Definition xmp.cpp:364
Exiv2::Xmpdatum::familyName
const char * familyName() const override
Return the name of the metadata family (which is also the first part of the key).
Definition xmp.cpp:312
Exiv2::Xmpdatum::Xmpdatum
Xmpdatum(const XmpKey &key, const Value *pValue=nullptr)
Constructor for new tags created by an application. The Xmpdatum is created from a key / value pair....
Definition xmp.cpp:292
Exiv2
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
Exiv2::TypeId
TypeId
Exiv2 value type identifiers.
Definition types.hpp:70
Exiv2::Rational
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition types.hpp:31
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian).
Definition types.hpp:34
Exiv2::Dictionary
std::map< std::string, std::string > Dictionary
typedef for string:string map
Definition datasets.hpp:312
Exiv2::XmpMetadata
std::vector< Xmpdatum > XmpMetadata
Container type to hold all metadata.
Definition xmp_exiv2.hpp:126
Exiv2::Xmpdatum::Impl
Internal Pimpl structure of class Xmpdatum.
Definition xmp.cpp:257