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_
std::vector< Iptcdatum > IptcMetadata
Container type to hold all metadata.
Definition: iptc.hpp:160
Slice (= view) for STL containers.
Definition: slice.hpp:529
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:434
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:204
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:110
T getValue(const byte *buf, ByteOrder byteOrder)
Read a value of type T from the data buffer.
Definition: value.hpp:1372
TypeId
Exiv2 value type identifiers.
Definition: types.hpp:130
iterator begin()
Begin of the metadata.
Definition: iptc.hpp:224
Provides abstract base classes Metadatum and Key.
uint8_t byte
1 byte unsigned integer type.
Definition: types.hpp:105
An IPTC metadatum ("dataset"), consisting of an IptcKey and a Value and methods to manipulate these...
Definition: iptc.hpp:52
void clear()
Delete all Iptcdatum instances resulting in an empty container.
Definition: iptc.hpp:218
std::string toString(const T &arg)
Utility function to convert the argument of any type to a string.
Definition: types.hpp:521
A container for IPTC data. This is a top-level class of the Exiv2 library.
Definition: iptc.hpp:173
bool empty() const
Return true if there is no IPTC metadata.
Definition: iptc.hpp:258
iterator end()
End of the metadata.
Definition: iptc.hpp:226
Concrete keys for IPTC metadata.
Definition: datasets.hpp:275
Stateless parser class for IPTC data. Images use this class to decode and encode binary IPTC data...
Definition: iptc.hpp:284
IPTC dataset and type information.
const_iterator end() const
End of the metadata.
Definition: iptc.hpp:245
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. Otherwise a new ValueType<T> value is created and set to value.
Definition: exif.cpp:193
const char * groupName(IfdId ifdId)
Return the group name for a group id.
Definition: tags_int.cpp:2155
IPTC string type.
Definition: types.hpp:147
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
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Abstract base class defining the interface to access information related to one metadata tag...
Definition: metadatum.hpp:126
IptcMetadata::const_iterator const_iterator
IptcMetadata const iterator type.
Definition: iptc.hpp:178
IptcMetadata::iterator iterator
IptcMetadata iterator type.
Definition: iptc.hpp:176
long count() const
Get the number of metadata entries.
Definition: iptc.hpp:260
std::auto_ptr< IptcKey > AutoPtr
Shortcut for an IptcKey auto pointer.
Definition: datasets.hpp:278