Exiv2
iptc.hpp
Go to the documentation of this file.
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 IPTC_HPP_
28 #define IPTC_HPP_
29 
30 // *****************************************************************************
31 #include "exiv2lib_export.h"
32 
33 // included header files
34 #include "metadatum.hpp"
35 #include "datasets.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 Iptcdatum : public Metadatum {
53  public:
55 
56 
68  explicit Iptcdatum(const IptcKey& key,
69  const Value* pValue =0);
71  Iptcdatum(const Iptcdatum& rhs);
73  virtual ~Iptcdatum();
75 
77 
78  Iptcdatum& operator=(const Iptcdatum& rhs);
84  Iptcdatum& operator=(const uint16_t& value);
89  Iptcdatum& operator=(const std::string& value);
94  Iptcdatum& operator=(const Value& value);
95  void setValue(const Value* pValue);
104  int setValue(const std::string& value);
106 
108 
109  long copy(byte* buf, ByteOrder byteOrder) const;
110  std::ostream& write(std::ostream& os, const ExifData* pMetadata =0) const;
117  std::string key() const;
122  std::string recordName() const;
127  uint16_t record() const;
128  const char* familyName() const;
129  std::string groupName() const;
134  std::string tagName() const;
135  std::string tagLabel() const;
137  uint16_t tag() const;
138  TypeId typeId() const;
139  const char* typeName() const;
140  long typeSize() const;
141  long count() const;
142  long size() const;
143  std::string toString() const;
144  std::string toString(long n) const;
145  long toLong(long n =0) const;
146  float toFloat(long n =0) const;
147  Rational toRational(long n =0) const;
148  Value::AutoPtr getValue() const;
149  const Value& value() const;
151 
152  private:
153  // DATA
154  IptcKey::AutoPtr key_;
155  Value::AutoPtr value_;
156 
157  }; // class Iptcdatum
158 
160  typedef std::vector<Iptcdatum> IptcMetadata;
161 
173  class EXIV2API IptcData {
174  public:
176  typedef IptcMetadata::iterator iterator;
178  typedef IptcMetadata::const_iterator const_iterator;
179 
180  // Use the compiler generated constructors and assignment operator
181 
183 
184 
192  Iptcdatum& operator[](const std::string& key);
200  int add(const IptcKey& key, Value* value);
207  int add(const Iptcdatum& iptcdatum);
214  iterator erase(iterator pos);
218  void clear() { iptcMetadata_.clear(); }
220  void sortByKey();
222  void sortByTag();
224  iterator begin() { return iptcMetadata_.begin(); }
226  iterator end() { return iptcMetadata_.end(); }
231  iterator findKey(const IptcKey& key);
236  iterator findId(uint16_t dataset,
237  uint16_t record = IptcDataSets::application2);
239 
241 
242  const_iterator begin() const { return iptcMetadata_.begin(); }
245  const_iterator end() const { return iptcMetadata_.end(); }
250  const_iterator findKey(const IptcKey& key) const;
255  const_iterator findId(uint16_t dataset,
256  uint16_t record = IptcDataSets::application2) const;
258  bool empty() const { return count() == 0; }
260  long count() const { return static_cast<long>(iptcMetadata_.size()); }
264  long size() const;
268  const char *detectCharset() const;
272  static void printStructure(std::ostream& out, const Slice<byte*>& bytes,uint32_t depth);
274 
275  private:
276  // DATA
277  IptcMetadata iptcMetadata_;
278  }; // class IptcData
279 
284  class EXIV2API IptcParser {
285  public:
297  static int decode(
298  IptcData& iptcData,
299  const byte* pData,
300  uint32_t size
301  );
311  static DataBuf encode(
312  const IptcData& iptcData
313  );
314 
315  private:
316  // Constant data
317  static const byte marker_; // Dataset marker
318 
319  }; // class IptcParser
320 
321 } // namespace Exiv2
322 
323 #endif // #ifndef IPTC_HPP_
Exiv2::IptcData::detectCharset
const char * detectCharset() const
Return the metadata charset name or 0.
Definition: iptc.cpp:377
Exiv2::Slice
Slice (= view) for STL containers.
Definition: slice.hpp:529
image_int.hpp
Internal image helpers.
Exiv2::IptcData::findId
iterator findId(uint16_t dataset, uint16_t record=IptcDataSets::application2)
Find the first Iptcdatum with the given record and dataset it, return a const iterator to it.
Definition: iptc.cpp:330
Exiv2::DataBuf::pData_
byte * pData_
Pointer to the buffer, 0 if none has been allocated.
Definition: types.hpp:269
Exiv2::Internal::indent
std::string indent(int32_t d)
indent output for kpsRecursive in printStructure() .
Definition: image_int.cpp:106
Exiv2::Iptcdatum::count
long count() const
Return the number of components in the value.
Definition: iptc.cpp:171
Exiv2::IptcData::begin
iterator begin()
Begin of the metadata.
Definition: iptc.hpp:224
Exiv2::Iptcdatum::write
std::ostream & write(std::ostream &os, const ExifData *pMetadata=0) const
Write the interpreted value to an output stream, return the stream.
Definition: iptc.cpp:111
Exiv2::Value
Common interface for all types of values used with metadata.
Definition: value.hpp:60
metadatum.hpp
Provides abstract base classes Metadatum and Key.
Exiv2::IptcData::sortByKey
void sortByKey()
Sort metadata by key.
Definition: iptc.cpp:336
types.hpp
Type definitions for Exiv2 and related functionality.
Exiv2::IptcData::empty
bool empty() const
Return true if there is no IPTC metadata.
Definition: iptc.hpp:258
Exiv2::IptcDataSets::dataSetRepeatable
static bool dataSetRepeatable(uint16_t number, uint16_t recordId)
Check if a given dataset is repeatable.
Definition: datasets.cpp:517
Exiv2::IptcParser::decode
static int decode(IptcData &iptcData, const byte *pData, uint32_t size)
Decode binary IPTC data in IPTC IIM4 format from a buffer pData of length size to the provided metada...
Definition: iptc.cpp:432
Exiv2::Iptcdatum::tagLabel
std::string tagLabel() const
Return a label for the tag.
Definition: iptc.cpp:146
Exiv2::makeSlice
Slice< T > makeSlice(T &cont, size_t begin, size_t end)
Return a new slice with the given bounds.
Definition: slice.hpp:673
Exiv2::Iptcdatum::size
long size() const
Return the size of the value in bytes.
Definition: iptc.cpp:176
Exiv2::Value::create
static AutoPtr create(TypeId typeId)
A (simple) factory to create a Value type.
Definition: value.cpp:100
Exiv2::Iptcdatum::typeSize
long typeSize() const
Return the size in bytes of one component of this type.
Definition: iptc.cpp:166
Exiv2::Iptcdatum
An IPTC metadatum ("dataset"), consisting of an IptcKey and a Value and methods to manipulate these.
Definition: iptc.hpp:52
Exiv2::IptcData::operator[]
Iptcdatum & operator[](const std::string &key)
Returns a reference to the Iptcdatum that is associated with a particular key. If IptcData does not a...
Definition: iptc.cpp:266
Exiv2::IptcData::end
const_iterator end() const
End of the metadata.
Definition: iptc.hpp:245
Exiv2::Iptcdatum::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: iptc.cpp:191
Exiv2::Iptcdatum::record
uint16_t record() const
Return the record id.
Definition: iptc.cpp:126
Exiv2::Iptcdatum::tagName
std::string tagName() const
Return the name of the tag (aka dataset)
Definition: iptc.cpp:141
Exiv2::Internal::binaryToString
binaryToStringHelper< T > binaryToString(const Slice< T > sl)
format binary data for display in Image::printStructure()
Definition: image_int.hpp:125
Exiv2::IptcData::clear
void clear()
Delete all Iptcdatum instances resulting in an empty container.
Definition: iptc.hpp:218
Exiv2::Iptcdatum::Iptcdatum
Iptcdatum(const IptcKey &key, const Value *pValue=0)
Constructor for new tags created by an application. The Iptcdatum is created from a key / value pair....
Definition: iptc.cpp:88
Exiv2::IptcDataSets::dataSetType
static TypeId dataSetType(uint16_t number, uint16_t recordId)
Return the type for dataSet number and Record id.
Definition: datasets.cpp:478
Exiv2::Internal::SliceBase::size
size_t size() const
Definition: slice.hpp:106
Exiv2::Internal::groupName
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2155
Exiv2::IptcData::end
iterator end()
End of the metadata.
Definition: iptc.hpp:226
Exiv2::IptcKey::AutoPtr
std::auto_ptr< IptcKey > AutoPtr
Shortcut for an IptcKey auto pointer.
Definition: datasets.hpp:278
Exiv2::IptcDataSets::dataSetName
static std::string dataSetName(uint16_t number, uint16_t recordId)
Return the name of the dataset.
Definition: datasets.cpp:485
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::Iptcdatum::recordName
std::string recordName() const
Return the name of the record (deprecated)
Definition: iptc.cpp:121
Exiv2::invalidTypeId
Invalid type id.
Definition: types.hpp:157
Exiv2::IptcData::printStructure
static void printStructure(std::ostream &out, const Slice< byte * > &bytes, uint32_t depth)
dump iptc formatted binary data (used by printStructure kpsRecursive)
Definition: iptc.cpp:351
Exiv2::byte
uint8_t byte
1 byte unsigned integer type.
Definition: types.hpp:105
Exiv2::IptcData::sortByTag
void sortByTag()
Sort metadata by tag (aka dataset)
Definition: iptc.cpp:341
Exiv2::Iptcdatum::~Iptcdatum
virtual ~Iptcdatum()
Destructor.
Definition: iptc.cpp:102
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:204
Exiv2::IptcData::findKey
iterator findKey(const IptcKey &key)
Find the first Iptcdatum with the given key, return an iterator to it.
Definition: iptc.cpp:318
Exiv2::us2Data
EXIV2API long us2Data(byte *buf, uint16_t s, ByteOrder byteOrder)
Convert an unsigned short to data, write the data to the buffer, return number of bytes written.
Definition: types.cpp:395
Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container >::at
value_type & at(size_t index)
Definition: slice.hpp:269
Exiv2::Iptcdatum::copy
long copy(byte *buf, ByteOrder byteOrder) const
Write value to a data buffer and return the number of bytes written.
Definition: iptc.cpp:106
Exiv2::Iptcdatum::familyName
const char * familyName() const
Return the name of the metadata family (which is also the first part of the key)
Definition: iptc.cpp:131
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::IptcData::erase
iterator erase(iterator pos)
Delete the Iptcdatum at iterator position pos, return the position of the next Iptcdatum....
Definition: iptc.cpp:346
Exiv2::Metadatum
Abstract base class defining the interface to access information related to one metadata tag.
Definition: metadatum.hpp:126
Exiv2::Iptcdatum::groupName
std::string groupName() const
Return the name of the metadata group (which is also the second part of the key)
Definition: iptc.cpp:136
Exiv2::Iptcdatum::value
const Value & value() const
Return a constant reference to the value.
Definition: iptc.cpp:211
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Exiv2::Rational
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:110
Exiv2::Iptcdatum::typeName
const char * typeName() const
Return the name of the type.
Definition: iptc.cpp:161
value.hpp
Value interface and concrete subclasses.
Exiv2::IptcMetadata
std::vector< Iptcdatum > IptcMetadata
Container type to hold all metadata.
Definition: iptc.hpp:160
Exiv2::TypeId
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:130
Exiv2::Iptcdatum::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: iptc.cpp:206
Exiv2::getValue
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
Definition: value.hpp:1372
Exiv2::ul2Data
EXIV2API long ul2Data(byte *buf, uint32_t l, ByteOrder byteOrder)
Convert an unsigned long to data, write the data to the buffer, return number of bytes written.
Definition: types.cpp:408
Exiv2::TypeInfo::typeName
static const char * typeName(TypeId typeId)
Return the name of the type, 0 if unknown.
Definition: types.cpp:107
EXV_WARNING
#define EXV_WARNING
Shorthand for a temp warning log message object and return its ostringstream.
Definition: error.hpp:148
Exiv2::Iptcdatum::setValue
void setValue(const Value *pValue)
Set the value. This method copies (clones) the value pointed to by pValue.
Definition: iptc.cpp:251
Exiv2::IptcData::add
int add(const IptcKey &key, Value *value)
Add an Iptcdatum from the supplied key and value pair. This method copies (clones) the value....
Definition: iptc.cpp:295
Exiv2::IptcData::iterator
IptcMetadata::iterator iterator
IptcMetadata iterator type.
Definition: iptc.hpp:176
Exiv2::IptcParser
Stateless parser class for IPTC data. Images use this class to decode and encode binary IPTC data.
Definition: iptc.hpp:284
Exiv2::getUShort
EXIV2API uint16_t getUShort(const byte *buf, ByteOrder byteOrder)
Read a 2 byte unsigned short value from the data buffer.
Definition: types.cpp:278
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
Exiv2::cmpMetadataByTag
EXIV2API bool cmpMetadataByTag(const Metadatum &lhs, const Metadatum &rhs)
Compare two metadata by tag. Return true if the tag of metadatum lhs is less than that of rhs.
Definition: metadatum.cpp:78
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::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:323
Exiv2::cmpIptcdataByRecord
bool cmpIptcdataByRecord(const Iptcdatum &lhs, const Iptcdatum &rhs)
Compare two iptc items by record. Return true if the record of lhs is less than that of rhs.
Definition: iptc.cpp:504
Exiv2::IptcKey
Concrete keys for IPTC metadata.
Definition: datasets.hpp:275
Exiv2::Iptcdatum::typeId
TypeId typeId() const
Return the type id of the value.
Definition: iptc.cpp:156
Exiv2::IptcData
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:173
Exiv2::Slice::subSlice
Slice subSlice(size_t begin, size_t end)
Definition: slice.hpp:567
Exiv2::ValueType::AutoPtr
std::auto_ptr< ValueType< T > > AutoPtr
Shortcut for a ValueType<T> auto pointer.
Definition: value.hpp:1247
Exiv2::Iptcdatum::operator=
Iptcdatum & operator=(const Iptcdatum &rhs)
Assignment operator.
Definition: iptc.cpp:217
Exiv2::IptcParser::encode
static DataBuf encode(const IptcData &iptcData)
Encode the IPTC datasets from iptcData to a binary representation in IPTC IIM4 format.
Definition: iptc.cpp:509
Exiv2::string
IPTC string type.
Definition: types.hpp:147
Exiv2::Iptcdatum::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: iptc.cpp:201
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::Iptcdatum::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: iptc.cpp:196
Exiv2::Iptcdatum::toString
std::string toString() const
Return the value as a string.
Definition: iptc.cpp:181
datasets.hpp
IPTC dataset and type information.
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::IptcData::size
long size() const
Return the exact size of all contained IPTC metadata.
Definition: iptc.cpp:277
Exiv2::ValueType
Template for a Value of a basic type. This is used for unsigned and signed short, long and rationals.
Definition: value.hpp:1244
Exiv2::IptcKey::record
uint16_t record() const
Return the record id.
Definition: datasets.cpp:654
Exiv2::IptcData::count
long count() const
Get the number of metadata entries.
Definition: iptc.hpp:260
Exiv2::IptcKey::tag
virtual uint16_t tag() const
Return the tag number.
Definition: datasets.cpp:644
Exiv2::Iptcdatum::key
std::string key() const
Return the key of the Iptcdatum. The key is of the form 'Iptc.recordName.datasetName'....
Definition: iptc.cpp:116
Exiv2::TypeInfo::typeSize
static long typeSize(TypeId typeId)
Return the size in bytes of one element of this type.
Definition: types.cpp:121
Exiv2::Iptcdatum::tag
uint16_t tag() const
Return the tag (aka dataset) number.
Definition: iptc.cpp:151
Exiv2::Value::AutoPtr
std::auto_ptr< Value > AutoPtr
Shortcut for a Value auto pointer.
Definition: value.hpp:63
error.hpp
Error class for exceptions, log message class.
jpgimage.hpp
Class JpegImage to access JPEG images.
iptc.hpp
Encoding and decoding of IPTC data.
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::IptcData::const_iterator
IptcMetadata::const_iterator const_iterator
IptcMetadata const iterator type.
Definition: iptc.hpp:178