Exiv2
xmp_exiv2.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2021 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
20#ifndef XMP_HPP_
21#define XMP_HPP_
22
23// *****************************************************************************
24#include "exiv2lib_export.h"
25
26// included header files
27#include "metadatum.hpp"
28#include "properties.hpp"
29
30// *****************************************************************************
31// namespace extensions
32namespace Exiv2 {
33
34// *****************************************************************************
35// class declarations
36 class ExifData;
37
38// *****************************************************************************
39// class definitions
40
45 class EXIV2API Xmpdatum : public Metadatum {
46 public:
48
49
61 explicit Xmpdatum(const XmpKey& key, const Value* pValue = nullptr);
63 Xmpdatum(const Xmpdatum& rhs);
65 ~Xmpdatum() override;
67
69
70
71 Xmpdatum& operator=(const Xmpdatum& rhs);
76 Xmpdatum& operator=(const std::string& value);
81 Xmpdatum& operator=(const char* value);
86 Xmpdatum& operator=(const bool& value);
91 template<typename T>
92 Xmpdatum& operator=(const T& value);
97 Xmpdatum& operator=(const Value& value);
98 void setValue(const Value* pValue) override;
106 int setValue(const std::string& value) override;
108
110
111
112 long copy(byte* buf, ByteOrder byteOrder) const override;
113 std::ostream& write(std::ostream& os, const ExifData* pMetadata = nullptr) const override;
120 std::string key() const override;
121 const char* familyName() const override;
123 std::string groupName() const override;
125 std::string tagName() const override;
126 std::string tagLabel() const override;
128 uint16_t tag() const override;
129 TypeId typeId() const override;
130 const char* typeName() const override;
131 // Todo: Remove this method from the baseclass
133 long typeSize() const override;
134 long count() const override;
135 long size() const override;
136 std::string toString() const override;
137 std::string toString(long n) const override;
138 long toLong(long n = 0) const override;
139 float toFloat(long n = 0) const override;
140 Rational toRational(long n = 0) const override;
141 Value::UniquePtr getValue() const override;
142 const Value& value() const override;
144
145 private:
146 // Pimpl idiom
147 struct Impl;
148 std::unique_ptr<Impl> p_;
149
150 }; // class Xmpdatum
151
153 typedef std::vector<Xmpdatum> XmpMetadata;
154
165 class EXIV2API XmpData {
166 public:
168 XmpData() = default;
169
171 typedef XmpMetadata::iterator iterator;
173 typedef XmpMetadata::const_iterator const_iterator;
174
176
177
185 Xmpdatum& operator[](const std::string& key);
191 int add(const XmpKey& key, const Value* value);
196 int add(const Xmpdatum& xmpdatum);
197 /*
198 @brief Delete the Xmpdatum at iterator position pos, return the
199 position of the next Xmpdatum.
200
201 @note Iterators into the metadata, including pos, are potentially
202 invalidated by this call.
203 @brief Delete the Xmpdatum at iterator position pos and update pos
204 */
205 iterator erase(XmpData::iterator pos);
211 void eraseFamily(XmpData::iterator& pos);
213 void clear();
215 void sortByKey();
217 iterator begin();
219 iterator end();
224 iterator findKey(const XmpKey& key);
226
228
229
230 const_iterator begin() const;
232 const_iterator end() const;
237 const_iterator findKey(const XmpKey& key) const;
239 bool empty() const;
241 long count() const;
242
244 bool usePacket() const { return usePacket_; } ;
245
247 bool usePacket(bool b) { bool r = usePacket_; usePacket_=b ; return r; };
249 void setPacket(const std::string& xmpPacket) { xmpPacket_ = xmpPacket ; usePacket(false); };
250 // ! getPacket
251 const std::string& xmpPacket() const { return xmpPacket_ ; };
252
254
255 private:
256 // DATA
257 XmpMetadata xmpMetadata_;
258 std::string xmpPacket_ ;
259 bool usePacket_{};
260 }; // class XmpData
261
267 class EXIV2API XmpParser {
268 public:
271 omitPacketWrapper = 0x0010UL,
272 readOnlyPacket = 0x0020UL,
273 useCompactFormat = 0x0040UL,
274 includeThumbnailPad = 0x0100UL,
275 exactPacketLength = 0x0200UL,
276 writeAliasComments = 0x0400UL,
277 omitAllFormatting = 0x0800UL
278 };
292 static int decode( XmpData& xmpData,
293 const std::string& xmpPacket);
311 static int encode( std::string& xmpPacket,
312 const XmpData& xmpData,
313 uint16_t formatFlags =useCompactFormat,
314 uint32_t padding =0);
325 typedef void (*XmpLockFct)(void* pLockData, bool lockUnlock);
326
377 static bool initialize(XmpParser::XmpLockFct xmpLockFct = nullptr, void* pLockData = nullptr);
384 static void terminate();
385
386 private:
390 static void registerNs(const std::string& ns,
391 const std::string& prefix);
397 static void unregisterNs(const std::string& ns);
398
402 static void registeredNamespaces(Exiv2::Dictionary&);
403
404 // DATA
405 static bool initialized_;
406 static XmpLockFct xmpLockFct_;
407 static void* pLockData_;
408
409 friend class XmpProperties; // permit XmpProperties -> registerNs() and registeredNamespaces()
410
411 }; // class XmpParser
412
413// *****************************************************************************
414// free functions, template and inline definitions
415
416 inline Xmpdatum& Xmpdatum::operator=(const char* value)
417 {
418 return Xmpdatum::operator=(std::string(value));
419 }
420
421 inline Xmpdatum& Xmpdatum::operator=(const bool& value)
422 {
423 return operator=(value ? "True" : "False");
424 }
425
426 template<typename T>
428 {
430 return *this;
431 }
432
433} // namespace Exiv2
434
435#endif // #ifndef XMP_HPP_
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434
Abstract base class defining the interface to access information related to one metadata tag.
Definition: metadatum.hpp:115
Common interface for all types of values used with metadata.
Definition: value.hpp:51
std::unique_ptr< Value > UniquePtr
Shortcut for a Value auto pointer.
Definition: value.hpp:54
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:165
XmpData()=default
Default constructor.
XmpMetadata::iterator iterator
XmpMetadata iterator type.
Definition: xmp_exiv2.hpp:171
bool usePacket(bool b)
set usePacket_
Definition: xmp_exiv2.hpp:247
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition: xmp_exiv2.hpp:173
bool usePacket() const
are we to use the packet?
Definition: xmp_exiv2.hpp:244
void setPacket(const std::string &xmpPacket)
setPacket
Definition: xmp_exiv2.hpp:249
Concrete keys for XMP metadata.
Definition: properties.hpp:238
Stateless parser class for XMP packets. Images use this class to parse and serialize XMP packets....
Definition: xmp_exiv2.hpp:267
XmpFormatFlags
Options to control the format of the serialized XMP packet.
Definition: xmp_exiv2.hpp:270
void(* XmpLockFct)(void *pLockData, bool lockUnlock)
Lock/unlock function type.
Definition: xmp_exiv2.hpp:325
XMP property reference, implemented as a static class.
Definition: properties.hpp:85
Information related to an XMP property. An XMP metadatum consists of an XmpKey and a Value and provid...
Definition: xmp_exiv2.hpp:45
~Xmpdatum() override
Destructor.
const Value & value() const override
Return a constant reference to the value.
Definition: xmp.cpp:426
Xmpdatum & operator=(const Xmpdatum &rhs)
Assignment operator.
Definition: xmp.cpp:331
void setValue(const Value *pValue) override
Set the value. This method copies (clones) the value pointed to by pValue.
Definition: xmp.cpp:456
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2559
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: basicio.hpp:43
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
Definition: value.hpp:1346
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:100
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:83
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:80
Exiv2::Exifdatum & setValue(Exiv2::Exifdatum &exifDatum, const T &value)
Set the value of exifDatum to value. If the object already has a value, it is replaced....
Definition: exif.cpp:195
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:510
std::vector< Xmpdatum > XmpMetadata
Container type to hold all metadata.
Definition: xmp_exiv2.hpp:153
std::map< std::string, std::string > Dictionary
typedef for string:string map
Definition: datasets.hpp:347
Internal Pimpl structure of class Xmpdatum.
Definition: xmp.cpp:285