Exiv2
xmp_exiv2.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2018 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 */
27#ifndef XMP_HPP_
28#define XMP_HPP_
29
30// *****************************************************************************
31#include "exiv2lib_export.h"
32
33// included header files
34#include "metadatum.hpp"
35#include "properties.hpp"
36
37// *****************************************************************************
38// namespace extensions
39namespace Exiv2 {
40
41// *****************************************************************************
42// class declarations
43 class ExifData;
44
45// *****************************************************************************
46// class definitions
47
52 class EXIV2API Xmpdatum : public Metadatum {
53 public:
55
56
68 explicit Xmpdatum(const XmpKey& key,
69 const Value* pValue =0);
71 Xmpdatum(const Xmpdatum& rhs);
73 virtual ~Xmpdatum();
75
77
78
79 Xmpdatum& operator=(const Xmpdatum& rhs);
84 Xmpdatum& operator=(const std::string& value);
89 Xmpdatum& operator=(const char* value);
94 Xmpdatum& operator=(const bool& value);
99 template<typename T>
100 Xmpdatum& operator=(const T& value);
105 Xmpdatum& operator=(const Value& value);
106 void setValue(const Value* pValue);
114 int setValue(const std::string& value);
116
118
119
120 long copy(byte* buf, ByteOrder byteOrder) const;
121 std::ostream& write(std::ostream& os, const ExifData* pMetadata =0) const;
128 std::string key() const;
129 const char* familyName() const;
131 std::string groupName() const;
133 std::string tagName() const;
134 std::string tagLabel() const;
136 uint16_t tag() const;
137 TypeId typeId() const;
138 const char* typeName() const;
139 // Todo: Remove this method from the baseclass
141 long typeSize() const;
142 long count() const;
143 long size() const;
144 std::string toString() const;
145 std::string toString(long n) const;
146 long toLong(long n =0) const;
147 float toFloat(long n =0) const;
148 Rational toRational(long n =0) const;
149 Value::AutoPtr getValue() const;
150 const Value& value() const;
152
153 private:
154 // Pimpl idiom
155 struct Impl;
156 std::auto_ptr<Impl> p_;
157
158 }; // class Xmpdatum
159
161 typedef std::vector<Xmpdatum> XmpMetadata;
162
173 class EXIV2API XmpData {
174 public:
176 XmpData() : xmpMetadata_(), xmpPacket_(), usePacket_(0) {}
177
179 typedef XmpMetadata::iterator iterator;
181 typedef XmpMetadata::const_iterator const_iterator;
182
184
185
193 Xmpdatum& operator[](const std::string& key);
199 int add(const XmpKey& key, const Value* value);
204 int add(const Xmpdatum& xmpdatum);
205 /*
206 @brief Delete the Xmpdatum at iterator position pos, return the
207 position of the next Xmpdatum.
208
209 @note Iterators into the metadata, including pos, are potentially
210 invalidated by this call.
211 @brief Delete the Xmpdatum at iterator position pos and update pos
212 */
213 iterator erase(XmpData::iterator pos);
219 void eraseFamily(XmpData::iterator& pos);
221 void clear();
223 void sortByKey();
225 iterator begin();
227 iterator end();
232 iterator findKey(const XmpKey& key);
234
236
237
238 const_iterator begin() const;
240 const_iterator end() const;
245 const_iterator findKey(const XmpKey& key) const;
247 bool empty() const;
249 long count() const;
250
252 bool usePacket() const { return usePacket_; } ;
253
255 bool usePacket(bool b) { bool r = usePacket_; usePacket_=b ; return r; };
257 void setPacket(const std::string& xmpPacket) { xmpPacket_ = xmpPacket ; usePacket(false); };
258 // ! getPacket
259 const std::string& xmpPacket() const { return xmpPacket_ ; };
260
262
263 private:
264 // DATA
265 XmpMetadata xmpMetadata_;
266 std::string xmpPacket_ ;
267 bool usePacket_ ;
268 }; // class XmpData
269
275 class EXIV2API XmpParser {
276 public:
279 omitPacketWrapper = 0x0010UL,
280 readOnlyPacket = 0x0020UL,
281 useCompactFormat = 0x0040UL,
282 includeThumbnailPad = 0x0100UL,
283 exactPacketLength = 0x0200UL,
284 writeAliasComments = 0x0400UL,
285 omitAllFormatting = 0x0800UL
286 };
300 static int decode( XmpData& xmpData,
301 const std::string& xmpPacket);
319 static int encode( std::string& xmpPacket,
320 const XmpData& xmpData,
321 uint16_t formatFlags =useCompactFormat,
322 uint32_t padding =0);
333 typedef void (*XmpLockFct)(void* pLockData, bool lockUnlock);
334
385 static bool initialize(XmpParser::XmpLockFct xmpLockFct =0, void* pLockData =0);
392 static void terminate();
393
394 private:
398 static void registerNs(const std::string& ns,
399 const std::string& prefix);
405 static void unregisterNs(const std::string& ns);
406
410 static void registeredNamespaces(Exiv2::Dictionary&);
411
412 // DATA
413 static bool initialized_;
414 static XmpLockFct xmpLockFct_;
415 static void* pLockData_;
416
417 friend class XmpProperties; // permit XmpProperties -> registerNs() and registeredNamespaces()
418
419 }; // class XmpParser
420
421// *****************************************************************************
422// free functions, template and inline definitions
423
424 inline Xmpdatum& Xmpdatum::operator=(const char* value)
425 {
427 }
428
429 inline Xmpdatum& Xmpdatum::operator=(const bool& value)
430 {
431 return operator=(value ? "True" : "False");
432 }
433
434 template<typename T>
436 {
438 return *this;
439 }
440
441} // namespace Exiv2
442
443#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:126
Common interface for all types of values used with metadata.
Definition: value.hpp:60
std::auto_ptr< Value > AutoPtr
Shortcut for a Value auto pointer.
Definition: value.hpp:63
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:173
XmpData()
Default constructor.
Definition: xmp_exiv2.hpp:176
XmpMetadata::iterator iterator
XmpMetadata iterator type.
Definition: xmp_exiv2.hpp:179
bool usePacket(bool b)
set usePacket_
Definition: xmp_exiv2.hpp:255
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition: xmp_exiv2.hpp:181
bool usePacket() const
are we to use the packet?
Definition: xmp_exiv2.hpp:252
void setPacket(const std::string &xmpPacket)
setPacket
Definition: xmp_exiv2.hpp:257
Concrete keys for XMP metadata.
Definition: properties.hpp:242
Stateless parser class for XMP packets. Images use this class to parse and serialize XMP packets....
Definition: xmp_exiv2.hpp:275
XmpFormatFlags
Options to control the format of the serialized XMP packet.
Definition: xmp_exiv2.hpp:278
void(* XmpLockFct)(void *pLockData, bool lockUnlock)
Lock/unlock function type.
Definition: xmp_exiv2.hpp:333
XMP property reference, implemented as a static class.
Definition: properties.hpp:96
Information related to an XMP property. An XMP metadatum consists of an XmpKey and a Value and provid...
Definition: xmp_exiv2.hpp:52
Xmpdatum & operator=(const Xmpdatum &rhs)
Assignment operator.
Definition: xmp.cpp:167
const Value & value() const
Return a constant reference to the value.
Definition: xmp.cpp:264
void setValue(const Value *pValue)
Set the value. This method copies (clones) the value pointed to by pValue.
Definition: xmp.cpp:293
Provides abstract base classes Metadatum and Key.
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2155
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:130
@ string
IPTC string type.
Definition: types.hpp:147
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:110
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:193
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:521
std::vector< Xmpdatum > XmpMetadata
Container type to hold all metadata.
Definition: xmp_exiv2.hpp:161
std::map< std::string, std::string > Dictionary
typedef for string:string map
Definition: datasets.hpp:364
XMP property and type information. References: XMP Specification from Adobe (Property descriptions c...
Internal Pimpl structure of class Xmpdatum.
Definition: xmp.cpp:125