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
32 namespace 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  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  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  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>
428  Xmpdatum& Xmpdatum::operator=(const T& value)
429  {
431  return *this;
432  }
433 
434 } // namespace Exiv2
435 
436 #endif // #ifndef XMP_HPP_
Exiv2::LangAltValue::AutoPtr
std::auto_ptr< LangAltValue > AutoPtr
Shortcut for a LangAltValue auto pointer.
Definition: value.hpp:893
Exiv2::Xmpdatum::~Xmpdatum
virtual ~Xmpdatum()
Destructor.
Definition: xmp.cpp:338
Exiv2::XmpData::XmpData
XmpData()
Default constructor.
Definition: xmp_exiv2.hpp:169
Exiv2::XmpProperties::propertyType
static TypeId propertyType(const XmpKey &key)
Return the type for property key. The default for unknown keys is xmpText.
Exiv2::StringVector_i
StringVector::const_iterator StringVector_i
Class to provide a StringVector iterator.
Definition: datasets.hpp:398
Exiv2::XmpData::sortByKey
void sortByKey()
Sort metadata by key.
Definition: xmp.cpp:513
Exiv2::Xmpdatum::Impl::value_
Value::AutoPtr value_
Value.
Definition: xmp.cpp:295
Exiv2::Xmpdatum::value
const Value & value() const
Return a constant reference to the value.
Definition: xmp.cpp:427
Exiv2::XmpArrayValue
Value type for simple arrays. Each item in the array is a simple value, without qualifiers....
Definition: value.hpp:797
Exiv2::Xmpdatum::write
std::ostream & write(std::ostream &os, const ExifData *pMetadata=0) const
Write the interpreted value to an output stream, return the stream.
Definition: xmp.cpp:439
Exiv2::XmpValue
Base class for all Exiv2 values used to store XMP property values.
Definition: value.hpp:624
Exiv2::StringVector
std::vector< std::string > StringVector
typedef for string vector
Definition: datasets.hpp:390
Exiv2::XmpValue::xmpStruct
XmpStruct xmpStruct() const
Return XMP struct, indicates if an XMP value is a structure.
Definition: value.cpp:649
Exiv2::Value
Common interface for all types of values used with metadata.
Definition: value.hpp:51
Exiv2::Xmpdatum::setValue
void setValue(const Value *pValue)
Set the value. This method copies (clones) the value pointed to by pValue.
Definition: xmp.cpp:456
Exiv2::Xmpdatum::operator=
Xmpdatum & operator=(const Xmpdatum &rhs)
Assignment operator.
Definition: xmp.cpp:330
Exiv2::Xmpdatum::typeName
const char * typeName() const
Return the name of the type.
Definition: xmp.cpp:377
Exiv2::XmpParser::includeThumbnailPad
@ includeThumbnailPad
Include a padding allowance for a thumbnail image.
Definition: xmp_exiv2.hpp:275
Exiv2::Xmpdatum::Impl::operator=
Impl & operator=(const Impl &rhs)
Assignment.
Definition: xmp.cpp:310
Exiv2::Xmpdatum::Xmpdatum
Xmpdatum(const XmpKey &key, const Value *pValue=0)
Constructor for new tags created by an application. The Xmpdatum is created from a key / value pair....
Definition: xmp.cpp:320
Exiv2::XmpParser
Stateless parser class for XMP packets. Images use this class to parse and serialize XMP packets....
Definition: xmp_exiv2.hpp:268
Exiv2::XmpParser::omitAllFormatting
@ omitAllFormatting
Omit all formatting whitespace.
Definition: xmp_exiv2.hpp:278
Exiv2::Xmpdatum::copy
long copy(byte *buf, ByteOrder byteOrder) const
Not implemented. Calling this method will raise an exception.
Definition: xmp.cpp:433
Exiv2::XmpMetadata
std::vector< Xmpdatum > XmpMetadata
Container type to hold all metadata.
Definition: xmp_exiv2.hpp:154
Exiv2::XmpValue::XmpArrayType
XmpArrayType
XMP array types.
Definition: value.hpp:630
Exiv2::XmpParser::XmpFormatFlags
XmpFormatFlags
Options to control the format of the serialized XMP packet.
Definition: xmp_exiv2.hpp:271
Exiv2::XmpData::iterator
XmpMetadata::iterator iterator
XmpMetadata iterator type.
Definition: xmp_exiv2.hpp:172
Exiv2::XmpData::clear
void clear()
Delete all Xmpdatum instances resulting in an empty container.
Definition: xmp.cpp:508
Exiv2::Value::create
static AutoPtr create(TypeId typeId)
A (simple) factory to create a Value type.
Definition: value.cpp:93
Exiv2::XmpData::begin
iterator begin()
Begin of the metadata.
Definition: xmp.cpp:518
Exiv2::Xmpdatum::typeId
TypeId typeId() const
Return the type id of the value.
Definition: xmp.cpp:372
Exiv2::XmpData::setPacket
void setPacket(const std::string &xmpPacket)
setPacket
Definition: xmp_exiv2.hpp:250
Exiv2::XmpValue::xmpArrayType
XmpArrayType xmpArrayType() const
Return XMP array type, indicates if an XMP value is an array.
Definition: value.cpp:632
Exiv2::XmpProperties::ns
static std::string ns(const std::string &prefix)
Return the namespace name for the schema associated with prefix.
Exiv2::LangAltValue
Value type for XMP language alternative properties.
Definition: value.hpp:890
Exiv2::Xmpdatum::toRational
Rational toRational(long n=0) const
Return the n-th component of the value converted to Rational. The return value is -1/1 if the value i...
Definition: xmp.cpp:417
Exiv2::XmpTextValue
Value type suitable for simple XMP properties and XMP nodes of complex types which are not parsed int...
Definition: value.hpp:715
Exiv2::XmpTextValue::AutoPtr
std::auto_ptr< XmpTextValue > AutoPtr
Shortcut for a XmpTextValue auto pointer.
Definition: value.hpp:718
Exiv2::Xmpdatum
Information related to an XMP property. An XMP metadatum consists of an XmpKey and a Value and provid...
Definition: xmp_exiv2.hpp:45
Exiv2::XmpKey
Concrete keys for XMP metadata.
Definition: properties.hpp:230
Exiv2::Xmpdatum::Impl::Impl
Impl(const XmpKey &key, const Value *pValue)
Constructor.
Definition: xmp.cpp:298
Exiv2::LangAltValue::value_
ValueType value_
Map to store the language alternative values. The language qualifier is used as the key for the map e...
Definition: value.hpp:968
Exiv2::Xmpdatum::familyName
const char * familyName() const
Return the name of the metadata family (which is also the first part of the key)
Definition: xmp.cpp:347
Exiv2::Internal::groupName
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2540
Exiv2::XmpData::findKey
iterator findKey(const XmpKey &key)
Find the first Xmpdatum with the given key, return an iterator to it.
Definition: xmp.cpp:502
Exiv2::Xmpdatum::groupName
std::string groupName() const
Return the (preferred) schema namespace prefix.
Definition: xmp.cpp:352
Exiv2::Xmpdatum::count
long count() const
Return the number of components in the value.
Definition: xmp.cpp:387
Exiv2::XmpParser::readOnlyPacket
@ readOnlyPacket
Default is a writeable packet.
Definition: xmp_exiv2.hpp:273
Exiv2::Value::clone
AutoPtr clone() const
Return an auto-pointer to a copy of itself (deep copy). The caller owns this copy and the auto-pointe...
Definition: value.hpp:110
Exiv2::XmpParser::terminate
static void terminate()
Terminate the XMP Toolkit and unregister custom namespaces.
Definition: xmp.cpp:703
Exiv2::invalidTypeId
@ invalidTypeId
Invalid type id.
Definition: types.hpp:146
Exiv2::XmpProperties::unregisterNs
static void unregisterNs()
Unregister all custom namespaces.
Exiv2::xmpBag
@ xmpBag
XMP bag type.
Definition: types.hpp:143
Exiv2::Xmpdatum::toString
std::string toString() const
Return the value as a string.
Definition: xmp.cpp:397
Exiv2::XmpParser::useCompactFormat
@ useCompactFormat
Use a compact form of RDF.
Definition: xmp_exiv2.hpp:274
Exiv2::XmpData::count
long count() const
Get the number of metadata entries.
Definition: xmp.cpp:533
Exiv2::XmpParser::omitPacketWrapper
@ omitPacketWrapper
Omit the XML packet wrapper.
Definition: xmp_exiv2.hpp:272
Exiv2::XmpParser::encode
static int encode(std::string &xmpPacket, const XmpData &xmpData, uint16_t formatFlags=useCompactFormat, uint32_t padding=0)
Encode (serialize) XMP metadata from xmpData into a string xmpPacket. The XMP packet returned in the ...
Definition: xmp.cpp:1000
Exiv2::cmpMetadataByKey
EXIV2API bool cmpMetadataByKey(const Metadatum &lhs, const Metadatum &rhs)
Compare two metadata by key. Return true if the key of metadatum lhs is less than that of rhs.
Definition: metadatum.cpp:77
Exiv2::langAlt
@ langAlt
XMP language alternative type.
Definition: types.hpp:145
Exiv2::Xmpdatum::key
std::string key() const
Return the key of the Xmpdatum. The key is of the form 'Xmp.prefix.property'. Note however that the k...
Definition: xmp.cpp:342
Exiv2::Metadatum
Abstract base class defining the interface to access information related to one metadata tag.
Definition: metadatum.hpp:115
Exiv2::XmpValue::XmpStruct
XmpStruct
XMP structure indicator.
Definition: value.hpp:632
Exiv2::Xmpdatum::Impl::key_
XmpKey::AutoPtr key_
Key.
Definition: xmp.cpp:294
Exiv2::XmpParser::XmpLockFct
void(* XmpLockFct)(void *pLockData, bool lockUnlock)
Lock/unlock function type.
Definition: xmp_exiv2.hpp:326
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Exiv2::XmpData
A container for XMP data. This is a top-level class of the Exiv2 library.
Definition: xmp_exiv2.hpp:166
Exiv2::Rational
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:99
Exiv2::XmpData::empty
bool empty() const
Return true if there is no XMP metadata.
Definition: xmp.cpp:528
Exiv2::TypeId
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:119
Exiv2::getValue
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
Definition: value.hpp:1363
Exiv2::XmpProperties::registerNs
static void registerNs(const std::string &ns, const std::string &prefix)
Register namespace ns with preferred prefix prefix.
Exiv2::Xmpdatum::size
long size() const
Return the size of the value in bytes.
Definition: xmp.cpp:392
Exiv2::TypeInfo::typeName
static const char * typeName(TypeId typeId)
Return the name of the type, 0 if unknown.
Definition: types.cpp:102
Exiv2::XmpData::usePacket
bool usePacket(bool b)
set usePacket_
Definition: xmp_exiv2.hpp:248
EXV_WARNING
#define EXV_WARNING
Shorthand for a temp warning log message object and return its ostringstream.
Definition: error.hpp:148
Exiv2::Xmpdatum::tag
uint16_t tag() const
Properties don't have a tag number. Return 0.
Definition: xmp.cpp:367
Exiv2::XmpData::const_iterator
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition: xmp_exiv2.hpp:174
Exiv2::XmpParser::writeAliasComments
@ writeAliasComments
Show aliases as XML comments.
Definition: xmp_exiv2.hpp:277
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:102
Exiv2::Xmpdatum::tagName
std::string tagName() const
Return the property name.
Definition: xmp.cpp:357
Exiv2::XmpData::usePacket
bool usePacket() const
are we to use the packet?
Definition: xmp_exiv2.hpp:245
Exiv2::XmpProperties::nsRegistry_
static NsRegistry nsRegistry_
Namespace registry.
Definition: properties.hpp:218
Exiv2::XmpParser::exactPacketLength
@ exactPacketLength
The padding parameter is the overall packet length.
Definition: xmp_exiv2.hpp:276
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:474
Exiv2::XmpArrayValue::AutoPtr
std::auto_ptr< XmpArrayValue > AutoPtr
Shortcut for a XmpArrayValue auto pointer.
Definition: value.hpp:800
Exiv2::Metadatum::operator=
Metadatum & operator=(const Metadatum &rhs)
Assignment operator. Protected so that it can only be used by subclasses but not directly.
Definition: metadatum.cpp:59
Exiv2::XmpKey::AutoPtr
std::auto_ptr< XmpKey > AutoPtr
Shortcut for an XmpKey auto pointer.
Definition: properties.hpp:234
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:324
Exiv2::xmpText
@ xmpText
XMP text type.
Definition: types.hpp:141
Exiv2::Xmpdatum::tagLabel
std::string tagLabel() const
Return a label for the tag.
Definition: xmp.cpp:362
Exiv2::XmpParser::initialize
static bool initialize(XmpParser::XmpLockFct xmpLockFct=0, void *pLockData=0)
Initialize the XMP Toolkit.
Definition: xmp.cpp:641
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:485
Exiv2::XmpProperties::prefix
static std::string prefix(const std::string &ns)
Return the (preferred) prefix for schema namespace ns.
Exiv2::Dictionary
std::map< std::string, std::string > Dictionary
typedef for string:string map
Definition: datasets.hpp:364
Exiv2::setValue
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
Exiv2::Xmpdatum::getValue
Value::AutoPtr getValue() const
Return an auto-pointer to a copy (clone) of the value. The caller owns this copy and the auto-poiner ...
Definition: xmp.cpp:422
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:552
EXV_ERROR
#define EXV_ERROR
Shorthand for a temp error log message object and return its ostringstream.
Definition: error.hpp:150
Exiv2::xmpSeq
@ xmpSeq
XMP sequence type.
Definition: types.hpp:144
Exiv2::toString
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:510
Exiv2::Xmpdatum::typeSize
long typeSize() const
The Exif typeSize doesn't make sense here. Return 0.
Definition: xmp.cpp:382
Exiv2::XmpProperties::printProperty
static std::ostream & printProperty(std::ostream &os, const std::string &key, const Value &value)
Interpret and print the value of an XMP property.
Exiv2::xmpAlt
@ xmpAlt
XMP alternative type.
Definition: types.hpp:142
Exiv2::XmpProperties
XMP property reference, implemented as a static class.
Definition: properties.hpp:85
EXV_INFO
#define EXV_INFO
Shorthand for a temp info log message object and return its ostringstream.
Definition: error.hpp:146
Exiv2::XmpData::end
iterator end()
End of the metadata.
Definition: xmp.cpp:523
Exiv2::Xmpdatum::toFloat
float toFloat(long n=0) const
Return the n-th component of the value converted to float. The return value is -1 if the value is not...
Definition: xmp.cpp:412
Exiv2::Value::AutoPtr
std::auto_ptr< Value > AutoPtr
Shortcut for a Value auto pointer.
Definition: value.hpp:54
Exiv2::XmpParser::decode
static int decode(XmpData &xmpData, const std::string &xmpPacket)
Decode XMP metadata from an XMP packet xmpPacket into xmpData. The format of the XMP packet must foll...
Definition: xmp.cpp:887
error.hpp
Error class for exceptions, log message class.
Exiv2::Xmpdatum::Impl
Internal Pimpl structure of class Xmpdatum.
Definition: xmp.cpp:288
Exiv2::ExifData
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434
Exiv2::Xmpdatum::toLong
long toLong(long n=0) const
Return the n-th component of the value converted to long. The return value is -1 if the value is not ...
Definition: xmp.cpp:407