"Fossies" - the Fresh Open Source Software Archive

Member "exiv2-0.27.5-Source/src/actions.hpp" (21 Oct 2021, 15312 Bytes) of package /linux/misc/exiv2-0.27.5-Source.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "actions.hpp": 0.27.3_vs_0.27.4.

    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 /*!
   21   @file    actions.hpp
   22   @brief   Implements base class Task, TaskFactory and the various supported
   23            actions (derived from Task).
   24   @author  Andreas Huggel (ahu)
   25            <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
   26   @date    11-Dec-03, ahu: created
   27  */
   28 #ifndef ACTIONS_HPP_
   29 #define ACTIONS_HPP_
   30 
   31 // *****************************************************************************
   32 // included header files
   33 #include "exiv2app.hpp"
   34 
   35 // *****************************************************************************
   36 // class declarations
   37 
   38 namespace Exiv2 {
   39     class ExifData;
   40     class Image;
   41     class Metadatum;
   42     class PreviewImage;
   43 }
   44 
   45 // *****************************************************************************
   46 // namespace extensions
   47 /*!
   48   @brief Contains all action classes (task subclasses).
   49  */
   50 namespace Action {
   51 
   52     //! Enumerates all tasks
   53     enum TaskType { none, adjust, print, rename, erase, extract, insert,
   54                     modify, fixiso, fixcom };
   55 
   56 // *****************************************************************************
   57 // class definitions
   58 
   59     /*!
   60       @brief Abstract base class for all concrete actions.
   61 
   62       Task provides a simple interface that actions must implement and a few
   63       commonly used helpers.
   64      */
   65     class Task {
   66     public:
   67         //! Shortcut for an auto pointer.
   68         typedef std::auto_ptr<Task> AutoPtr;
   69         //! Contructor.
   70         Task() : binary_(false) {}
   71         //! Virtual destructor.
   72         virtual ~Task();
   73         //! Virtual copy construction.
   74         AutoPtr clone() const;
   75         /*!
   76           @brief Application interface to perform a task.
   77 
   78           @param path Path of the file to process.
   79           @return 0 if successful.
   80          */
   81         virtual int run(const std::string& path) =0;
   82         
   83         /*!
   84           @brief Application interface to perform a task.
   85 
   86           @param path Path of the file to process.
   87           @return 0 if successful.
   88          */
   89         bool setBinary(bool b) { bool bResult = binary_ ; binary_ = b ; return bResult ;}
   90         bool binary() { return binary_ ; }
   91 
   92     private:
   93         //! Internal virtual copy constructor.
   94         virtual Task* clone_() const =0;
   95         
   96         //! copy binary_ from command-line params to task
   97         bool binary_;
   98 
   99     }; // class Task
  100 
  101     /*!
  102       @brief Task factory.
  103 
  104       Creates an instance of the task of the requested type.  The factory is
  105       implemented as a singleton, which can be accessed only through the static
  106       member function instance().
  107     */
  108     class TaskFactory {
  109     public:
  110         /*!
  111           @brief Get access to the task factory.
  112 
  113           Clients access the task factory exclusively through
  114           this method.
  115         */
  116         static TaskFactory& instance();
  117         //! Destructor
  118         void cleanup();
  119 
  120         /*!
  121           @brief  Create a task.
  122 
  123           @param  type Identifies the type of task to create.
  124           @return An auto pointer that owns a task of the requested type.  If
  125                   the task type is not supported, the pointer is 0.
  126           @remark The caller of the function should check the content of the
  127                   returned auto pointer and take appropriate action (e.g., throw
  128                   an exception) if it is 0.
  129          */
  130         Task::AutoPtr create(TaskType type);
  131 
  132         /*!
  133           @brief Register a task prototype together with its type.
  134 
  135           The task factory creates new tasks of a given type by cloning its
  136           associated prototype. Additional tasks can be registered.  If called
  137           for a type which already exists in the list, the corresponding
  138           prototype is replaced.
  139 
  140           @param type Task type.
  141           @param task Pointer to the prototype. Ownership is transferred to the
  142                  task factory. That's what the auto pointer indicates.
  143         */
  144         void registerTask(TaskType type, Task::AutoPtr task);
  145 
  146     private:
  147         //! Prevent construction other than through instance().
  148         TaskFactory();
  149         //! Prevent copy construction: not implemented.
  150         TaskFactory(const TaskFactory& rhs);
  151 
  152         //! Pointer to the one and only instance of this class.
  153         static TaskFactory* instance_;
  154         //! Type used to store Task prototype classes
  155         typedef std::map<TaskType, Task*> Registry;
  156         //! List of task types and corresponding prototypes.
  157         Registry registry_;
  158 
  159     }; // class TaskFactory
  160 
  161     //! %Print the Exif (or other metadata) of a file to stdout
  162     class Print : public Task {
  163     public:
  164         virtual ~Print();
  165         virtual int run(const std::string& path);
  166         typedef std::auto_ptr<Print> AutoPtr;
  167         AutoPtr clone() const;
  168 
  169         //! Print the Jpeg comment
  170         int printComment();
  171         //! Print list of available preview images
  172         int printPreviewList();
  173         //! Print Exif summary information
  174         int printSummary();
  175         //! Print Exif, IPTC and XMP metadata in user defined format
  176         int printList();
  177         //! Return true if key should be printed, else false
  178         bool grepTag(const std::string& key);
  179         //! Return true if key should be printed, else false
  180         bool keyTag(const std::string& key);
  181         //! Print all metadata in a user defined format
  182         int printMetadata(const Exiv2::Image* image);
  183         //! Print a metadatum in a user defined format, return true if something was printed
  184         bool printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* image);
  185         //! Print the label for a summary line
  186         void printLabel(const std::string& label) const;
  187         /*!
  188           @brief Print one summary line with a label (if provided) and requested
  189                  data. A line break is printed only if a label is provided.
  190           @return 1 if a line was written, 0 if the key was not found.
  191          */
  192         int printTag(const Exiv2::ExifData& exifData,
  193                      const std::string& key,
  194                      const std::string& label ="") const;
  195         //! Type for an Exiv2 Easy access function
  196         typedef Exiv2::ExifData::const_iterator (*EasyAccessFct)(const Exiv2::ExifData& ed);
  197         /*!
  198           @brief Print one summary line with a label (if provided) and requested
  199                  data. A line break is printed only if a label is provided.
  200           @return 1 if a line was written, 0 if the information was not found.
  201          */
  202         int printTag(const Exiv2::ExifData& exifData,
  203                      EasyAccessFct easyAccessFct,
  204                      const std::string& label ="",
  205                      EasyAccessFct easyAccessFctFallback =NULL) const;
  206 
  207     private:
  208         virtual Print* clone_() const;
  209 
  210         std::string path_;
  211         int align_;                // for the alignment of the summary output
  212     }; // class Print
  213 
  214     /*!
  215       @brief %Rename a file to its metadate creation timestamp,
  216              in the specified format.
  217      */
  218     class Rename : public Task {
  219     public:
  220         virtual ~Rename();
  221         virtual int run(const std::string& path);
  222         typedef std::auto_ptr<Rename> AutoPtr;
  223         AutoPtr clone() const;
  224 
  225     private:
  226         virtual Rename* clone_() const;
  227     }; // class Rename
  228 
  229     //! %Adjust the Exif (or other metadata) timestamps
  230     class Adjust : public Task {
  231     public:
  232         virtual ~Adjust();
  233         virtual int run(const std::string& path);
  234         typedef std::auto_ptr<Adjust> AutoPtr;
  235         AutoPtr clone() const;
  236 
  237     private:
  238         virtual Adjust* clone_() const;
  239         int adjustDateTime(Exiv2::ExifData& exifData,
  240                            const std::string& key,
  241                            const std::string& path) const;
  242 
  243         long adjustment_;
  244         long yearAdjustment_;
  245         long monthAdjustment_;
  246         long dayAdjustment_;
  247 
  248     }; // class Adjust
  249 
  250     /*!
  251       @brief %Erase the entire exif data or only the thumbnail section.
  252      */
  253     class Erase : public Task {
  254     public:
  255         virtual ~Erase();
  256         virtual int run(const std::string& path);
  257         typedef std::auto_ptr<Erase> AutoPtr;
  258         AutoPtr clone() const;
  259 
  260         /*!
  261           @brief Delete the thumbnail image, incl IFD1 metadata from the file.
  262          */
  263         int eraseThumbnail(Exiv2::Image* image) const;
  264         /*!
  265           @brief Erase the complete Exif data block from the file.
  266          */
  267         int eraseExifData(Exiv2::Image* image) const;
  268         /*!
  269           @brief Erase all Iptc data from the file.
  270          */
  271         int eraseIptcData(Exiv2::Image* image) const;
  272         /*!
  273           @brief Erase Jpeg comment from the file.
  274          */
  275         int eraseComment(Exiv2::Image* image) const;
  276         /*!
  277           @brief Erase XMP packet from the file.
  278          */
  279         int eraseXmpData(Exiv2::Image* image) const;
  280         /*!
  281           @brief Erase ICCProfile from the file.
  282          */
  283         int eraseIccProfile(Exiv2::Image* image) const;
  284 
  285 
  286     private:
  287         virtual Erase* clone_() const;
  288         std::string path_;
  289 
  290     }; // class Erase
  291 
  292     /*!
  293       @brief %Extract the entire exif data or only the thumbnail section.
  294      */
  295     class Extract : public Task {
  296     public:
  297         virtual ~Extract();
  298         virtual int run(const std::string& path);
  299         typedef std::auto_ptr<Extract> AutoPtr;
  300         AutoPtr clone() const;
  301 
  302         /*!
  303           @brief Write the thumbnail image to a file. The filename is composed by
  304                  removing the suffix from the image filename and appending
  305                  "-thumb" and the appropriate suffix (".jpg" or ".tif"), depending
  306                  on the format of the Exif thumbnail image.
  307          */
  308         int writeThumbnail() const;
  309         /*!
  310           @brief Write preview images to files.
  311          */
  312         int writePreviews() const;
  313         /*!
  314           @brief Write one preview image to a file. The filename is composed by
  315                  removing the suffix from the image filename and appending
  316                  "-preview<num>" and the appropriate suffix (".jpg" or ".tif"),
  317                  depending on the format of the Exif thumbnail image.
  318          */
  319         void writePreviewFile(const Exiv2::PreviewImage& pvImg, int num) const;
  320         /*!
  321           @brief Write embedded iccProfile files.
  322          */
  323         int writeIccProfile(const std::string& path) const;
  324 
  325     private:
  326         virtual Extract* clone_() const;
  327         std::string path_;
  328 
  329     }; // class Extract
  330 
  331     /*!
  332       @brief %Insert the Exif data from corresponding *.exv files.
  333      */
  334     class Insert : public Task {
  335     public:
  336         virtual ~Insert();
  337         virtual int run(const std::string& path);
  338         typedef std::auto_ptr<Insert> AutoPtr;
  339         AutoPtr clone() const;
  340 
  341         /*!
  342           @brief Insert a Jpeg thumbnail image from a file into file \em path.
  343                  The filename of the thumbnail is expected to be the image
  344                  filename (\em path) minus its suffix plus "-thumb.jpg".
  345          */
  346         int insertThumbnail(const std::string& path) const;
  347 
  348         /*!
  349           @brief Insert an XMP packet from a xmpPath into file \em path.
  350          */
  351         int insertXmpPacket(const std::string& path,const std::string& xmpPath) const;
  352         /*!
  353           @brief Insert xmp from a DataBuf into file \em path.
  354          */
  355         int insertXmpPacket(const std::string& path,const Exiv2::DataBuf& xmpBlob,bool usePacket=false) const;
  356 
  357         /*!
  358           @brief Insert an ICC profile from iccPath into file \em path.
  359          */
  360         int insertIccProfile(const std::string& path,const std::string& iccPath) const;
  361         /*!
  362           @brief Insert an ICC profile from binary DataBuf into file \em path.
  363          */
  364         int insertIccProfile(const std::string& path,Exiv2::DataBuf& iccProfileBlob) const;
  365 
  366     private:
  367         virtual Insert* clone_() const;
  368 
  369     }; // class Insert
  370 
  371     /*!
  372       @brief %Modify the Exif data according to the commands in the
  373              modification table.
  374      */
  375     class Modify : public Task {
  376     public:
  377         virtual ~Modify();
  378         virtual int run(const std::string& path);
  379         typedef std::auto_ptr<Modify> AutoPtr;
  380         AutoPtr clone() const;
  381         Modify() {}
  382         //! Apply modification commands to the \em pImage, return 0 if successful.
  383         static int applyCommands(Exiv2::Image* pImage);
  384 
  385     private:
  386         virtual Modify* clone_() const;
  387         //! Copy constructor needed because of AutoPtr member
  388         Modify(const Modify& /*src*/) : Task() {}
  389 
  390         //! Add a metadatum to \em pImage according to \em modifyCmd
  391         static int addMetadatum(Exiv2::Image* pImage,
  392                                 const ModifyCmd& modifyCmd);
  393         //! Set a metadatum in \em pImage according to \em modifyCmd
  394         static int setMetadatum(Exiv2::Image* pImage,
  395                                 const ModifyCmd& modifyCmd);
  396         //! Delete a metadatum from \em pImage according to \em modifyCmd
  397         static void delMetadatum(Exiv2::Image* pImage,
  398                                  const ModifyCmd& modifyCmd);
  399         //! Register an XMP namespace according to \em modifyCmd
  400         static void regNamespace(const ModifyCmd& modifyCmd);
  401 
  402     }; // class Modify
  403 
  404     /*!
  405       @brief %Copy ISO settings from any of the Nikon makernotes to the
  406              regular Exif tag, Exif.Photo.ISOSpeedRatings.
  407      */
  408     class FixIso : public Task {
  409     public:
  410         virtual ~FixIso();
  411         virtual int run(const std::string& path);
  412         typedef std::auto_ptr<FixIso> AutoPtr;
  413         AutoPtr clone() const;
  414 
  415     private:
  416         virtual FixIso* clone_() const;
  417         std::string path_;
  418 
  419     }; // class FixIso
  420 
  421     /*!
  422       @brief Fix the character encoding of Exif UNICODE user comments.
  423              Decodes the comment using the auto-detected or specified
  424              character encoding and writes it back in UCS-2.
  425      */
  426     class FixCom : public Task {
  427     public:
  428         virtual ~FixCom();
  429         virtual int run(const std::string& path);
  430         typedef std::auto_ptr<FixCom> AutoPtr;
  431         AutoPtr clone() const;
  432 
  433     private:
  434         virtual FixCom* clone_() const;
  435         std::string path_;
  436 
  437     }; // class FixCom
  438 
  439 }                                       // namespace Action
  440 
  441 #endif                                  // #ifndef ACTIONS_HPP_