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
39 namespace 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  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  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  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>
435  Xmpdatum& Xmpdatum::operator=(const T& value)
436  {
438  return *this;
439  }
440 
441 } // namespace Exiv2
442 
443 #endif // #ifndef XMP_HPP_
Exiv2::LangAltValue::AutoPtr
std::auto_ptr< LangAltValue > AutoPtr
Shortcut for a LangAltValue auto pointer.
Definition: value.hpp:902
Exiv2::Xmpdatum::~Xmpdatum
virtual ~Xmpdatum()
Destructor.
Definition: xmp.cpp:175
Exiv2::XmpData::XmpData
XmpData()
Default constructor.
Definition: xmp_exiv2.hpp:176
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:350
Exiv2::Xmpdatum::Impl::value_
Value::AutoPtr value_
Value.
Definition: xmp.cpp:132
Exiv2::Xmpdatum::value
const Value & value() const
Return a constant reference to the value.
Definition: xmp.cpp:264
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:276
Exiv2::StringVector
std::vector< std::string > StringVector
typedef for string vector
Definition: datasets.hpp:390
Exiv2::Value
Common interface for all types of values used with metadata.
Definition: value.hpp:60
Exiv2::Xmpdatum::setValue
void setValue(const Value *pValue)
Set the value. This method copies (clones) the value pointed to by pValue.
Definition: xmp.cpp:293
metadatum.hpp
Provides abstract base classes Metadatum and Key.
Exiv2::Xmpdatum::operator=
Xmpdatum & operator=(const Xmpdatum &rhs)
Assignment operator.
Definition: xmp.cpp:167
Exiv2::Xmpdatum::typeName
const char * typeName() const
Return the name of the type.
Definition: xmp.cpp:214
Exiv2::XmpParser::includeThumbnailPad
@ includeThumbnailPad
Include a padding allowance for a thumbnail image.
Definition: xmp_exiv2.hpp:282
Exiv2::Xmpdatum::Impl::operator=
Impl & operator=(const Impl &rhs)
Assignment.
Definition: xmp.cpp:147
types.hpp
Type definitions for Exiv2 and related functionality.
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:157
Exiv2::XmpParser
Stateless parser class for XMP packets. Images use this class to parse and serialize XMP packets....
Definition: xmp_exiv2.hpp:275
Exiv2::XmpParser::omitAllFormatting
@ omitAllFormatting
Omit all formatting whitespace.
Definition: xmp_exiv2.hpp:285
Exiv2::Xmpdatum::copy
long copy(byte *buf, ByteOrder byteOrder) const
Not implemented. Calling this method will raise an exception.
Definition: xmp.cpp:270
Exiv2::XmpMetadata
std::vector< Xmpdatum > XmpMetadata
Container type to hold all metadata.
Definition: xmp_exiv2.hpp:161
Exiv2::XmpValue::XmpArrayType
XmpArrayType
XMP array types.
Definition: value.hpp:639
Exiv2::XmpParser::XmpFormatFlags
XmpFormatFlags
Options to control the format of the serialized XMP packet.
Definition: xmp_exiv2.hpp:278
Exiv2::XmpData::iterator
XmpMetadata::iterator iterator
XmpMetadata iterator type.
Definition: xmp_exiv2.hpp:179
Exiv2::XmpData::clear
void clear()
Delete all Xmpdatum instances resulting in an empty container.
Definition: xmp.cpp:345
Exiv2::Value::create
static AutoPtr create(TypeId typeId)
A (simple) factory to create a Value type.
Definition: value.cpp:100
Exiv2::XmpData::begin
iterator begin()
Begin of the metadata.
Definition: xmp.cpp:355
Exiv2::Xmpdatum::typeId
TypeId typeId() const
Return the type id of the value.
Definition: xmp.cpp:209
Exiv2::XmpData::setPacket
void setPacket(const std::string &xmpPacket)
setPacket
Definition: xmp_exiv2.hpp:257
Exiv2::XmpValue::xmpArrayType
XmpArrayType xmpArrayType() const
Return XMP array type, indicates if an XMP value is an array.
Definition: value.cpp:651
Exiv2::XmpProperties::ns
static std::string ns(const std::string &prefix)
Return the namespace name for the schema associated with prefix.
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:254
Exiv2::XmpTextValue::AutoPtr
std::auto_ptr< XmpTextValue > AutoPtr
Shortcut for a XmpTextValue auto pointer.
Definition: value.hpp:727
Exiv2::Xmpdatum
Information related to an XMP property. An XMP metadatum consists of an XmpKey and a Value and provid...
Definition: xmp_exiv2.hpp:52
Exiv2::XmpKey
Concrete keys for XMP metadata.
Definition: properties.hpp:241
Exiv2::Xmpdatum::Impl::Impl
Impl(const XmpKey &key, const Value *pValue)
Constructor.
Definition: xmp.cpp:135
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:184
Exiv2::Internal::groupName
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2158
Exiv2::XmpData::findKey
iterator findKey(const XmpKey &key)
Find the first Xmpdatum with the given key, return an iterator to it.
Definition: xmp.cpp:339
Exiv2::Xmpdatum::groupName
std::string groupName() const
Return the (preferred) schema namespace prefix.
Definition: xmp.cpp:189
Exiv2::Xmpdatum::count
long count() const
Return the number of components in the value.
Definition: xmp.cpp:224
Exiv2::XmpParser::readOnlyPacket
@ readOnlyPacket
Default is a writeable packet.
Definition: xmp_exiv2.hpp:280
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:119
Exiv2::XmpParser::terminate
static void terminate()
Terminate the XMP Toolkit and unregister custom namespaces.
Definition: xmp.cpp:540
Exiv2::invalidTypeId
@ invalidTypeId
Invalid type id.
Definition: types.hpp:157
Exiv2::XmpProperties::unregisterNs
static void unregisterNs()
Unregister all custom namespaces.
Exiv2::xmpBag
@ xmpBag
XMP bag type.
Definition: types.hpp:154
Exiv2::Xmpdatum::toString
std::string toString() const
Return the value as a string.
Definition: xmp.cpp:234
Exiv2::XmpParser::useCompactFormat
@ useCompactFormat
Use a compact form of RDF.
Definition: xmp_exiv2.hpp:281
Exiv2::XmpData::count
long count() const
Get the number of metadata entries.
Definition: xmp.cpp:370
Exiv2::XmpParser::omitPacketWrapper
@ omitPacketWrapper
Omit the XML packet wrapper.
Definition: xmp_exiv2.hpp:279
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:836
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:84
Exiv2::langAlt
@ langAlt
XMP language alternative type.
Definition: types.hpp:156
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:179
Exiv2::Metadatum
Abstract base class defining the interface to access information related to one metadata tag.
Definition: metadatum.hpp:126
properties.hpp
XMP property and type information. References: XMP Specification from Adobe (Property descriptions c...
Exiv2::XmpValue::XmpStruct
XmpStruct
XMP structure indicator.
Definition: value.hpp:641
Exiv2::Xmpdatum::Impl::key_
XmpKey::AutoPtr key_
Key.
Definition: xmp.cpp:131
Exiv2::XmpParser::XmpLockFct
void(* XmpLockFct)(void *pLockData, bool lockUnlock)
Lock/unlock function type.
Definition: xmp_exiv2.hpp:333
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:173
Exiv2::Rational
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:110
Exiv2::XmpData::empty
bool empty() const
Return true if there is no XMP metadata.
Definition: xmp.cpp:365
value.hpp
Value interface and concrete subclasses.
Exiv2::TypeId
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:130
Exiv2::getValue
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
Definition: value.hpp:1372
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:229
Exiv2::TypeInfo::typeName
static const char * typeName(TypeId typeId)
Return the name of the type, 0 if unknown.
Definition: types.cpp:107
Exiv2::XmpData::usePacket
bool usePacket(bool b)
set usePacket_
Definition: xmp_exiv2.hpp:255
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:204
Exiv2::XmpData::const_iterator
XmpMetadata::const_iterator const_iterator
XmpMetadata const iterator type.
Definition: xmp_exiv2.hpp:181
Exiv2::XmpParser::writeAliasComments
@ writeAliasComments
Show aliases as XML comments.
Definition: xmp_exiv2.hpp:284
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
Exiv2::Xmpdatum::tagName
std::string tagName() const
Return the property name.
Definition: xmp.cpp:194
Exiv2::XmpData::usePacket
bool usePacket() const
are we to use the packet?
Definition: xmp_exiv2.hpp:252
Exiv2::XmpProperties::nsRegistry_
static NsRegistry nsRegistry_
Namespace registry.
Definition: properties.hpp:229
Exiv2::XmpParser::exactPacketLength
@ exactPacketLength
The padding parameter is the overall packet length.
Definition: xmp_exiv2.hpp:283
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:311
Exiv2::XmpArrayValue::AutoPtr
std::auto_ptr< XmpArrayValue > AutoPtr
Shortcut for a XmpArrayValue auto pointer.
Definition: value.hpp:809
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:66
Exiv2::XmpKey::AutoPtr
std::auto_ptr< XmpKey > AutoPtr
Shortcut for an XmpKey auto pointer.
Definition: properties.hpp:245
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:323
Exiv2::xmpText
@ xmpText
XMP text type.
Definition: types.hpp:152
Exiv2::Xmpdatum::tagLabel
std::string tagLabel() const
Return a label for the tag.
Definition: xmp.cpp:199
Exiv2::XmpParser::initialize
static bool initialize(XmpParser::XmpLockFct xmpLockFct=0, void *pLockData=0)
Initialize the XMP Toolkit.
Definition: xmp.cpp:478
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:322
Exiv2::XmpProperties::prefix
static std::string prefix(const std::string &ns)
Return the (preferred) prefix for schema namespace ns.
Exiv2::string
@ string
IPTC string type.
Definition: types.hpp:147
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:259
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:389
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:155
Exiv2::toString
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:521
Exiv2::Xmpdatum::typeSize
long typeSize() const
The Exif typeSize doesn't make sense here. Return 0.
Definition: xmp.cpp:219
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:153
Exiv2::XmpProperties
XMP property reference, implemented as a static class.
Definition: properties.hpp:96
Exiv2::XmpData::end
iterator end()
End of the metadata.
Definition: xmp.cpp:360
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:249
Exiv2::Value::AutoPtr
std::auto_ptr< Value > AutoPtr
Shortcut for a Value auto pointer.
Definition: value.hpp:63
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:723
error.hpp
Error class for exceptions, log message class.
Exiv2::Xmpdatum::Impl
Internal Pimpl structure of class Xmpdatum.
Definition: xmp.cpp:125
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:244