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,
62 const Value* pValue =0);
64 Xmpdatum(const Xmpdatum& rhs);
66 virtual ~Xmpdatum();
68
70
71
72 Xmpdatum& operator=(const Xmpdatum& rhs);
77 Xmpdatum& operator=(const std::string& value);
82 Xmpdatum& operator=(const char* value);
87 Xmpdatum& operator=(const bool& value);
92 template<typename T>
93 Xmpdatum& operator=(const T& value);
98 Xmpdatum& operator=(const Value& value);
99 void setValue(const Value* pValue);
107 int setValue(const std::string& value);
109
111
112
113 long copy(byte* buf, ByteOrder byteOrder) const;
114 std::ostream& write(std::ostream& os, const ExifData* pMetadata =0) const;
121 std::string key() const;
122 const char* familyName() const;
124 std::string groupName() const;
126 std::string tagName() const;
127 std::string tagLabel() const;
129 uint16_t tag() const;
130 TypeId typeId() const;
131 const char* typeName() const;
132 // Todo: Remove this method from the baseclass
134 long typeSize() const;
135 long count() const;
136 long size() const;
137 std::string toString() const;
138 std::string toString(long n) const;
139 long toLong(long n =0) const;
140 float toFloat(long n =0) const;
141 Rational toRational(long n =0) const;
142 Value::AutoPtr getValue() const;
143 const Value& value() const;
145
146 private:
147 // Pimpl idiom
148 struct Impl;
149 std::auto_ptr<Impl> p_;
150
151 }; // class Xmpdatum
152
154 typedef std::vector<Xmpdatum> XmpMetadata;
155
166 class EXIV2API XmpData {
167 public:
169 XmpData() : xmpMetadata_(), xmpPacket_(), usePacket_(0) {}
170
172 typedef XmpMetadata::iterator iterator;
174 typedef XmpMetadata::const_iterator const_iterator;
175
177
178
186 Xmpdatum& operator[](const std::string& key);
192 int add(const XmpKey& key, const Value* value);
197 int add(const Xmpdatum& xmpdatum);
198 /*
199 @brief Delete the Xmpdatum at iterator position pos, return the
200 position of the next Xmpdatum.
201
202 @note Iterators into the metadata, including pos, are potentially
203 invalidated by this call.
204 @brief Delete the Xmpdatum at iterator position pos and update pos
205 */
206 iterator erase(XmpData::iterator pos);
212 void eraseFamily(XmpData::iterator& pos);
214 void clear();
216 void sortByKey();
218 iterator begin();
220 iterator end();
225 iterator findKey(const XmpKey& key);
227
229
230
231 const_iterator begin() const;
233 const_iterator end() const;
238 const_iterator findKey(const XmpKey& key) const;
240 bool empty() const;
242 long count() const;
243
245 bool usePacket() const { return usePacket_; } ;
246
248 bool usePacket(bool b) { bool r = usePacket_; usePacket_=b ; return r; };
250 void setPacket(const std::string& xmpPacket) { xmpPacket_ = xmpPacket ; usePacket(false); };
251 // ! getPacket
252 const std::string& xmpPacket() const { return xmpPacket_ ; };
253
255
256 private:
257 // DATA
258 XmpMetadata xmpMetadata_;
259 std::string xmpPacket_ ;
260 bool usePacket_ ;
261 }; // class XmpData
262
268 class EXIV2API XmpParser {
269 public:
272 omitPacketWrapper = 0x0010UL,
273 readOnlyPacket = 0x0020UL,
274 useCompactFormat = 0x0040UL,
275 includeThumbnailPad = 0x0100UL,
276 exactPacketLength = 0x0200UL,
277 writeAliasComments = 0x0400UL,
278 omitAllFormatting = 0x0800UL
279 };
293 static int decode( XmpData& xmpData,
294 const std::string& xmpPacket);
312 static int encode( std::string& xmpPacket,
313 const XmpData& xmpData,
314 uint16_t formatFlags =useCompactFormat,
315 uint32_t padding =0);
326 typedef void (*XmpLockFct)(void* pLockData, bool lockUnlock);
327
378 static bool initialize(XmpParser::XmpLockFct xmpLockFct =0, void* pLockData =0);
385 static void terminate();
386
387 private:
391 static void registerNs(const std::string& ns,
392 const std::string& prefix);
398 static void unregisterNs(const std::string& ns);
399
403 static void registeredNamespaces(Exiv2::Dictionary&);
404
405 // DATA
406 static bool initialized_;
407 static XmpLockFct xmpLockFct_;
408 static void* pLockData_;
409
410 friend class XmpProperties; // permit XmpProperties -> registerNs() and registeredNamespaces()
411
412 }; // class XmpParser
413
414// *****************************************************************************
415// free functions, template and inline definitions
416
417 inline Xmpdatum& Xmpdatum::operator=(const char* value)
418 {
419 return Xmpdatum::operator=(std::string(value));
420 }
421
422 inline Xmpdatum& Xmpdatum::operator=(const bool& value)
423 {
424 return operator=(value ? "True" : "False");
425 }
426
427 template<typename T>
429 {
431 return *this;
432 }
433
434} // namespace Exiv2
435
436#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::auto_ptr< Value > AutoPtr
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:166
XmpData()
Default constructor.
Definition: xmp_exiv2.hpp:169
XmpMetadata::iterator iterator
XmpMetadata iterator type.
Definition: xmp_exiv2.hpp:172
bool usePacket(bool b)
set usePacket_
Definition: xmp_exiv2.hpp:248
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition: xmp_exiv2.hpp:174
bool usePacket() const
are we to use the packet?
Definition: xmp_exiv2.hpp:245
void setPacket(const std::string &xmpPacket)
setPacket
Definition: xmp_exiv2.hpp:250
Concrete keys for XMP metadata.
Definition: properties.hpp:231
Stateless parser class for XMP packets. Images use this class to parse and serialize XMP packets....
Definition: xmp_exiv2.hpp:268
XmpFormatFlags
Options to control the format of the serialized XMP packet.
Definition: xmp_exiv2.hpp:271
void(* XmpLockFct)(void *pLockData, bool lockUnlock)
Lock/unlock function type.
Definition: xmp_exiv2.hpp:326
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 & operator=(const Xmpdatum &rhs)
Assignment operator.
Definition: xmp.cpp:330
const Value & value() const
Return a constant reference to the value.
Definition: xmp.cpp:427
void setValue(const Value *pValue)
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:2569
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:119
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:102
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:99
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:194
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:154
std::map< std::string, std::string > Dictionary
typedef for string:string map
Definition: datasets.hpp:364
Internal Pimpl structure of class Xmpdatum.
Definition: xmp.cpp:288