| Exiv2

Loading...
Searching...
No Matches
xmp_exiv2.hpp
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#ifndef XMP_HPP_
4#define XMP_HPP_
5
6// *****************************************************************************
7#include "exiv2lib_export.h"
8
9// included header files
10#include "metadatum.hpp"
11#include "properties.hpp"
12
13// *****************************************************************************
14// namespace extensions
15 namespace Exiv2 {
16// *****************************************************************************
17// class declarations
18 class ExifData;
19
20// *****************************************************************************
21// class definitions
22
27 class EXIV2API Xmpdatum : public Metadatum {
28 public:
30
31
43 explicit Xmpdatum(const XmpKey& key, const Value* pValue = nullptr);
45 Xmpdatum(const Xmpdatum& rhs);
47 ~Xmpdatum() override;
49
51
52
53 Xmpdatum& operator=(const Xmpdatum& rhs);
58 Xmpdatum& operator=(const std::string& value);
63 template <typename T>
64 Xmpdatum& operator=(const T& value);
69 Xmpdatum& operator=(const Value& value);
70 void setValue(const Value* pValue) override;
78 int setValue(const std::string& value) override;
80
82
83
84 size_t copy(byte* buf, ByteOrder byteOrder) const override;
85 std::ostream& write(std::ostream& os, const ExifData* pMetadata = nullptr) const override;
92 [[nodiscard]] std::string key() const override;
93 [[nodiscard]] const char* familyName() const override;
95 [[nodiscard]] std::string groupName() const override;
97 [[nodiscard]] std::string tagName() const override;
98 [[nodiscard]] std::string tagLabel() const override;
99 [[nodiscard]] std::string tagDesc() const override;
101 [[nodiscard]] uint16_t tag() const override;
102 [[nodiscard]] TypeId typeId() const override;
103 [[nodiscard]] const char* typeName() const override;
104 // Todo: Remove this method from the baseclass
106 [[nodiscard]] size_t typeSize() const override;
107 [[nodiscard]] size_t count() const override;
108 [[nodiscard]] size_t size() const override;
109 [[nodiscard]] std::string toString() const override;
110 [[nodiscard]] std::string toString(size_t n) const override;
111 [[nodiscard]] int64_t toInt64(size_t n = 0) const override;
112 [[nodiscard]] float toFloat(size_t n = 0) const override;
113 [[nodiscard]] Rational toRational(size_t n = 0) const override;
114 [[nodiscard]] Value::UniquePtr getValue() const override;
115 [[nodiscard]] const Value& value() const override;
117
118 private:
119 // Pimpl idiom
120 struct Impl;
121 std::unique_ptr<Impl> p_;
122
123}; // class Xmpdatum
124
126 using XmpMetadata = std::vector<Xmpdatum>;
127
138 class EXIV2API XmpData {
139 public:
141 XmpData() = default;
142
144 using iterator = XmpMetadata::iterator;
146 using const_iterator = XmpMetadata::const_iterator;
147
149
150
158 Xmpdatum& operator[](const std::string& key);
164 int add(const XmpKey& key, const Value* value);
169 int add(const Xmpdatum& xmpdatum);
170 /*
171 @brief Delete the Xmpdatum at iterator position pos, return the
172 position of the next Xmpdatum.
173
174 @note Iterators into the metadata, including pos, are potentially
175 invalidated by this call.
176 @brief Delete the Xmpdatum at iterator position pos and update pos
177 */
178 iterator erase(XmpData::iterator pos);
184 void eraseFamily(XmpData::iterator& pos);
186 void clear();
188 void sortByKey();
190 iterator begin();
192 iterator end();
197 iterator findKey(const XmpKey& key);
199
201
202
203 [[nodiscard]] const_iterator begin() const;
205 [[nodiscard]] const_iterator end() const;
210 [[nodiscard]] const_iterator findKey(const XmpKey& key) const;
212 [[nodiscard]] bool empty() const;
214 [[nodiscard]] long count() const;
215
217 [[nodiscard]] bool usePacket() const {
218 return usePacket_;
219 }
220
222 bool usePacket(bool b) {
223 bool r = usePacket_;
224 usePacket_ = b;
225 return r;
226 }
227
228 void setPacket(std::string xmpPacket) {
229 xmpPacket_ = std::move(xmpPacket);
230 usePacket(false);
231 }
232 // ! getPacket
233 [[nodiscard]] const std::string& xmpPacket() const {
234 return xmpPacket_;
235 }
236
238
239 private:
240 // DATA
241 XmpMetadata xmpMetadata_;
242 std::string xmpPacket_;
243 bool usePacket_{};
244}; // class XmpData
245
251 class EXIV2API XmpParser {
252 public:
254 enum XmpFormatFlags {
255 omitPacketWrapper = 0x0010UL,
256 readOnlyPacket = 0x0020UL,
257 useCompactFormat = 0x0040UL,
258 includeThumbnailPad = 0x0100UL,
259 exactPacketLength = 0x0200UL,
260 writeAliasComments = 0x0400UL,
261 omitAllFormatting = 0x0800UL
262 };
263
276 static int decode(XmpData& xmpData, const std::string& xmpPacket);
294 static int encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t formatFlags = useCompactFormat,
295 uint32_t padding = 0);
306 using XmpLockFct = void (*)(void* pLockData, bool lockUnlock);
307
358 static bool initialize(XmpParser::XmpLockFct xmpLockFct = nullptr, void* pLockData = nullptr);
365 static void terminate();
366
367 private:
371 static void registerNs(const std::string& ns, const std::string& prefix);
377 static void unregisterNs(const std::string& ns);
378
382 static void registeredNamespaces(Exiv2::Dictionary&);
383
384 // DATA
385 static bool initialized_;
386 static XmpLockFct xmpLockFct_;
387 static void* pLockData_;
388
389 friend class XmpProperties; // permit XmpProperties -> registerNs() and registeredNamespaces()
390
391}; // class XmpParser
392
393// *****************************************************************************
394// free functions, template and inline definitions
395
396 template <typename T>
397 Xmpdatum& Xmpdatum::operator=(const T& value) {
398#ifdef __cpp_if_constexpr
399 if constexpr (std::is_same_v<T, bool>) {
400#else
401 if (std::is_same<T, bool>::value) {
402#endif
403 setValue(Exiv2::toString(value ? "True" : "False"));
404 return *this;
405 } else {
406 setValue(Exiv2::toString(value));
407 return *this;
408 }
409}
410
411} // namespace Exiv2
412
413#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