Blame include/exiv2/iptc.hpp

Packit Service 21b5d1
// ***************************************************************** -*- C++ -*-
Packit Service 21b5d1
/*
Packit Service 21b5d1
 * Copyright (C) 2004-2018 Exiv2 authors
Packit Service 21b5d1
 * This program is part of the Exiv2 distribution.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * This program is free software; you can redistribute it and/or
Packit Service 21b5d1
 * modify it under the terms of the GNU General Public License
Packit Service 21b5d1
 * as published by the Free Software Foundation; either version 2
Packit Service 21b5d1
 * of the License, or (at your option) any later version.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * This program is distributed in the hope that it will be useful,
Packit Service 21b5d1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 21b5d1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 21b5d1
 * GNU General Public License for more details.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * You should have received a copy of the GNU General Public License
Packit Service 21b5d1
 * along with this program; if not, write to the Free Software
Packit Service 21b5d1
 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
Packit Service 21b5d1
 */
Packit Service 21b5d1
/*!
Packit Service 21b5d1
  @file    iptc.hpp
Packit Service 21b5d1
  @brief   Encoding and decoding of IPTC data
Packit Service 21b5d1
  @author  Brad Schick (brad)
Packit Service 21b5d1
           brad@robotbattle.com
Packit Service 21b5d1
  @date    31-Jul-04, brad: created
Packit Service 21b5d1
 */
Packit Service 21b5d1
#ifndef IPTC_HPP_
Packit Service 21b5d1
#define IPTC_HPP_
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
#include "exiv2lib_export.h"
Packit Service 21b5d1
Packit Service 21b5d1
// included header files
Packit Service 21b5d1
#include "metadatum.hpp"
Packit Service 21b5d1
#include "datasets.hpp"
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
// namespace extensions
Packit Service 21b5d1
namespace Exiv2 {
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
// class declarations
Packit Service 21b5d1
    class ExifData;
Packit Service 21b5d1
Packit Service 21b5d1
// *****************************************************************************
Packit Service 21b5d1
// class definitions
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief An IPTC metadatum ("dataset"), consisting of an IptcKey and a
Packit Service 21b5d1
             Value and methods to manipulate these.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    class EXIV2API Iptcdatum : public Metadatum {
Packit Service 21b5d1
    public:
Packit Service 21b5d1
        //! @name Creators
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Constructor for new tags created by an application. The
Packit Service 21b5d1
                 %Iptcdatum is created from a key / value pair. %Iptcdatum
Packit Service 21b5d1
                 copies (clones) the value if one is provided. Alternatively, a
Packit Service 21b5d1
                 program can create an 'empty' %Iptcdatum with only a key and
Packit Service 21b5d1
                 set the value using setValue().
Packit Service 21b5d1
Packit Service 21b5d1
          @param key The key of the %Iptcdatum.
Packit Service 21b5d1
          @param pValue Pointer to a %Iptcdatum value.
Packit Service 21b5d1
          @throw Error if the key cannot be parsed and converted
Packit Service 21b5d1
                 to a tag number and record id.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        explicit Iptcdatum(const IptcKey& key,
Packit Service 21b5d1
                           const Value* pValue =0);
Packit Service 21b5d1
        //! Copy constructor
Packit Service 21b5d1
        Iptcdatum(const Iptcdatum& rhs);
Packit Service 21b5d1
        //! Destructor
Packit Service 21b5d1
        virtual ~Iptcdatum();
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Manipulators
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        //! Assignment operator
Packit Service 21b5d1
        Iptcdatum& operator=(const Iptcdatum& rhs);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Assign \em value to the %Iptcdatum. The type of the new Value
Packit Service 21b5d1
                 is set to UShortValue.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        Iptcdatum& operator=(const uint16_t& value);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Assign \em value to the %Iptcdatum.
Packit Service 21b5d1
                 Calls setValue(const std::string&).
Packit Service 21b5d1
         */
Packit Service 21b5d1
        Iptcdatum& operator=(const std::string& value);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Assign \em value to the %Iptcdatum.
Packit Service 21b5d1
                 Calls setValue(const Value*).
Packit Service 21b5d1
         */
Packit Service 21b5d1
        Iptcdatum& operator=(const Value& value);
Packit Service 21b5d1
        void setValue(const Value* pValue);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Set the value to the string \em value, using
Packit Service 21b5d1
                 Value::read(const std::string&).
Packit Service 21b5d1
                 If the %Iptcdatum does not have a Value yet, then a %Value of
Packit Service 21b5d1
                 the correct type for this %Iptcdatum is created. If that
Packit Service 21b5d1
                 fails (because of an unknown dataset), a StringValue is
Packit Service 21b5d1
                 created. Return 0 if the value was read successfully.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        int setValue(const std::string& value);
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Accessors
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        long copy(byte* buf, ByteOrder byteOrder) const;
Packit Service 21b5d1
        std::ostream& write(std::ostream& os, const ExifData* pMetadata =0) const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the key of the Iptcdatum. The key is of the form
Packit Service 21b5d1
                 'Iptc.recordName.datasetName'. Note however that the key
Packit Service 21b5d1
                 is not necessarily unique, i.e., an IptcData object may contain
Packit Service 21b5d1
                 multiple metadata with the same key.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        std::string key() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
           @brief Return the name of the record (deprecated)
Packit Service 21b5d1
           @return record name
Packit Service 21b5d1
         */
Packit Service 21b5d1
        std::string recordName() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
           @brief Return the record id
Packit Service 21b5d1
           @return record id
Packit Service 21b5d1
         */
Packit Service 21b5d1
        uint16_t record() const;
Packit Service 21b5d1
        const char* familyName() const;
Packit Service 21b5d1
        std::string groupName() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
           @brief Return the name of the tag (aka dataset)
Packit Service 21b5d1
           @return tag name
Packit Service 21b5d1
         */
Packit Service 21b5d1
        std::string tagName() const;
Packit Service 21b5d1
        std::string tagLabel() const;
Packit Service 21b5d1
        //! Return the tag (aka dataset) number
Packit Service 21b5d1
        uint16_t tag() const;
Packit Service 21b5d1
        TypeId typeId() const;
Packit Service 21b5d1
        const char* typeName() const;
Packit Service 21b5d1
        long typeSize() const;
Packit Service 21b5d1
        long count() const;
Packit Service 21b5d1
        long size() const;
Packit Service 21b5d1
        std::string toString() const;
Packit Service 21b5d1
        std::string toString(long n) const;
Packit Service 21b5d1
        long toLong(long n =0) const;
Packit Service 21b5d1
        float toFloat(long n =0) const;
Packit Service 21b5d1
        Rational toRational(long n =0) const;
Packit Service 21b5d1
        Value::AutoPtr getValue() const;
Packit Service 21b5d1
        const Value& value() const;
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
    private:
Packit Service 21b5d1
        // DATA
Packit Service 21b5d1
        IptcKey::AutoPtr key_;                  //!< Key
Packit Service 21b5d1
        Value::AutoPtr   value_;                //!< Value
Packit Service 21b5d1
Packit Service 21b5d1
    }; // class Iptcdatum
Packit Service 21b5d1
Packit Service 21b5d1
    //! Container type to hold all metadata
Packit Service 21b5d1
    typedef std::vector<Iptcdatum> IptcMetadata;
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief A container for IPTC data. This is a top-level class of
Packit Service 21b5d1
             the %Exiv2 library.
Packit Service 21b5d1
Packit Service 21b5d1
      Provide high-level access to the IPTC data of an image:
Packit Service 21b5d1
      - read IPTC information from JPEG files
Packit Service 21b5d1
      - access metadata through keys and standard C++ iterators
Packit Service 21b5d1
      - add, modify and delete metadata
Packit Service 21b5d1
      - write IPTC data to JPEG files
Packit Service 21b5d1
      - extract IPTC metadata to files, insert from these files
Packit Service 21b5d1
    */
Packit Service 21b5d1
    class EXIV2API IptcData {
Packit Service 21b5d1
    public:
Packit Service 21b5d1
        //! IptcMetadata iterator type
Packit Service 21b5d1
        typedef IptcMetadata::iterator iterator;
Packit Service 21b5d1
        //! IptcMetadata const iterator type
Packit Service 21b5d1
        typedef IptcMetadata::const_iterator const_iterator;
Packit Service 21b5d1
Packit Service 21b5d1
        // Use the compiler generated constructors and assignment operator
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Manipulators
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Returns a reference to the %Iptcdatum that is associated with a
Packit Service 21b5d1
                 particular \em key. If %IptcData does not already contain such
Packit Service 21b5d1
                 an %Iptcdatum, operator[] adds object \em Iptcdatum(key).
Packit Service 21b5d1
Packit Service 21b5d1
          @note  Since operator[] might insert a new element, it can't be a const
Packit Service 21b5d1
                 member function.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        Iptcdatum& operator[](const std::string& key);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Add an %Iptcdatum from the supplied key and value pair. This
Packit Service 21b5d1
                 method copies (clones) the value. A check for non-repeatable
Packit Service 21b5d1
                 datasets is performed.
Packit Service 21b5d1
          @return 0 if successful;
Packit Service 21b5d1
                  6 if the dataset already exists and is not repeatable
Packit Service 21b5d1
         */
Packit Service 21b5d1
        int add(const IptcKey& key, Value* value);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Add a copy of the Iptcdatum to the IPTC metadata. A check
Packit Service 21b5d1
                 for non-repeatable datasets is performed.
Packit Service 21b5d1
          @return 0 if successful;
Packit Service 21b5d1
                 6 if the dataset already exists and is not repeatable;
Packit Service 21b5d1
         */
Packit Service 21b5d1
        int add(const Iptcdatum& iptcdatum);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Delete the Iptcdatum at iterator position pos, return the
Packit Service 21b5d1
                 position of the next Iptcdatum. Note that iterators into
Packit Service 21b5d1
                 the metadata, including pos, are potentially invalidated
Packit Service 21b5d1
                 by this call.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        iterator erase(iterator pos);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Delete all Iptcdatum instances resulting in an empty container.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        void clear() { iptcMetadata_.clear(); }
Packit Service 21b5d1
        //! Sort metadata by key
Packit Service 21b5d1
        void sortByKey();
Packit Service 21b5d1
        //! Sort metadata by tag (aka dataset)
Packit Service 21b5d1
        void sortByTag();
Packit Service 21b5d1
        //! Begin of the metadata
Packit Service 21b5d1
        iterator begin() { return iptcMetadata_.begin(); }
Packit Service 21b5d1
        //! End of the metadata
Packit Service 21b5d1
        iterator end() { return iptcMetadata_.end(); }
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Find the first Iptcdatum with the given key, return an iterator
Packit Service 21b5d1
                 to it.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        iterator findKey(const IptcKey& key);
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Find the first Iptcdatum with the given record and dataset it,
Packit Service 21b5d1
                return a const iterator to it.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        iterator findId(uint16_t dataset,
Packit Service 21b5d1
                        uint16_t record = IptcDataSets::application2);
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
        //! @name Accessors
Packit Service 21b5d1
        //@{
Packit Service 21b5d1
        //! Begin of the metadata
Packit Service 21b5d1
        const_iterator begin() const { return iptcMetadata_.begin(); }
Packit Service 21b5d1
        //! End of the metadata
Packit Service 21b5d1
        const_iterator end() const { return iptcMetadata_.end(); }
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Find the first Iptcdatum with the given key, return a const
Packit Service 21b5d1
                 iterator to it.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        const_iterator findKey(const IptcKey& key) const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Find the first Iptcdatum with the given record and dataset
Packit Service 21b5d1
                 number, return a const iterator to it.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        const_iterator findId(uint16_t dataset,
Packit Service 21b5d1
                              uint16_t record = IptcDataSets::application2) const;
Packit Service 21b5d1
        //! Return true if there is no IPTC metadata
Packit Service 21b5d1
        bool empty() const { return count() == 0; }
Packit Service 21b5d1
        //! Get the number of metadata entries
Packit Service 21b5d1
        long count() const { return static_cast<long>(iptcMetadata_.size()); }
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the exact size of all contained IPTC metadata
Packit Service 21b5d1
         */
Packit Service 21b5d1
        long size() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Return the metadata charset name or 0
Packit Service 21b5d1
         */
Packit Service 21b5d1
        const char *detectCharset() const;
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief dump iptc formatted binary data (used by printStructure kpsRecursive)
Packit Service 21b5d1
        */
Packit Service 21b5d1
        static void printStructure(std::ostream& out, const Slice<byte*>& bytes,uint32_t depth);
Packit Service 21b5d1
        //@}
Packit Service 21b5d1
Packit Service 21b5d1
    private:
Packit Service 21b5d1
        // DATA
Packit Service 21b5d1
        IptcMetadata iptcMetadata_;
Packit Service 21b5d1
    }; // class IptcData
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Stateless parser class for IPTC data. Images use this class to
Packit Service 21b5d1
             decode and encode binary IPTC data.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    class EXIV2API IptcParser {
Packit Service 21b5d1
    public:
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Decode binary IPTC data in IPTC IIM4 format from a buffer \em pData
Packit Service 21b5d1
                 of length \em size to the provided metadata container.
Packit Service 21b5d1
Packit Service 21b5d1
          @param iptcData Metadata container to add the decoded IPTC datasets to.
Packit Service 21b5d1
          @param pData    Pointer to the data buffer to read from.
Packit Service 21b5d1
          @param size     Number of bytes in the data buffer.
Packit Service 21b5d1
Packit Service 21b5d1
          @return 0 if successful;
Packit Service 21b5d1
                  5 if the binary IPTC data is invalid or corrupt
Packit Service 21b5d1
         */
Packit Service 21b5d1
        static int decode(
Packit Service 21b5d1
                  IptcData& iptcData,
Packit Service 21b5d1
            const byte*     pData,
Packit Service 21b5d1
                  uint32_t  size
Packit Service 21b5d1
        );
Packit Service 21b5d1
        /*!
Packit Service 21b5d1
          @brief Encode the IPTC datasets from \em iptcData to a binary
Packit Service 21b5d1
                 representation in IPTC IIM4 format.
Packit Service 21b5d1
Packit Service 21b5d1
          Convert the IPTC datasets to binary format and return it.  Caller owns
Packit Service 21b5d1
          the returned buffer. The copied data follows the IPTC IIM4 standard.
Packit Service 21b5d1
Packit Service 21b5d1
          @return Data buffer containing the binary IPTC data in IPTC IIM4 format.
Packit Service 21b5d1
         */
Packit Service 21b5d1
        static DataBuf encode(
Packit Service 21b5d1
            const IptcData& iptcData
Packit Service 21b5d1
        );
Packit Service 21b5d1
Packit Service 21b5d1
    private:
Packit Service 21b5d1
        // Constant data
Packit Service 21b5d1
        static const byte marker_;      // Dataset marker
Packit Service 21b5d1
Packit Service 21b5d1
    }; // class IptcParser
Packit Service 21b5d1
Packit Service 21b5d1
}                                       // namespace Exiv2
Packit Service 21b5d1
Packit Service 21b5d1
#endif                                  // #ifndef IPTC_HPP_