Loading...
Searching...
No Matches
exiv2app.hpp
Go to the documentation of this file.
// ***************************************************************** -*- C++ -*-
/*
* Copyright (C) 2004-2021 Exiv2 authors
* This program is part of the Exiv2 distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
*/
#ifndef EXIV2APP_HPP_
#define EXIV2APP_HPP_
// *****************************************************************************
// included header files
#include <exiv2/exiv2.hpp>
#include "utils.hpp"
#include "types.hpp"
#include "getopt.hpp"
// + standard includes
#include <string>
#include <vector>
#include <set>
#include <iostream>
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h>
#endif
// stdin handler includes
#ifndef _MSC_VER
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#if defined(__CYGWIN__) || defined(__MINGW__)
#include <windows.h>
#else
#include <sys/select.h>
#endif
#endif
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__) || defined(_MSC_VER)
#include <fcntl.h>
#include <io.h>
#endif
// *****************************************************************************
// class definitions
enum CmdId { invalidCmdId, add, set, del, reg };
// enum MetadataId { invalidMetadataId, iptc, exif, xmp };
// mdNone=0, mdExif=1, mdIptc=2, mdComment=4, mdXmp=8
enum MetadataId { invalidMetadataId = Exiv2::mdNone
, iptc = Exiv2::mdIptc
, exif = Exiv2::mdExif
, xmp = Exiv2::mdXmp
} ;
struct ModifyCmd {
ModifyCmd() :
cmdId_(invalidCmdId), metadataId_(invalidMetadataId),
typeId_(Exiv2::invalidTypeId), explicitType_(false) {}
CmdId cmdId_;
std::string key_;
MetadataId metadataId_;
Exiv2::TypeId typeId_;
bool explicitType_;
std::string value_;
};
typedef std::vector<ModifyCmd> ModifyCmds;
struct CmdIdAndString {
CmdId cmdId_;
std::string cmdString_;
};
class Params : public Util::Getopt {
private:
std::string optstring_;
public:
typedef std::vector<std::string> CmdFiles;
typedef std::vector<std::string> CmdLines;
typedef std::vector<std::string> Files;
typedef std::set<int> PreviewNumbers;
typedef exv_grep_keys_t Greps;
typedef std::vector<std::string> Keys;
static Params& instance();
void cleanup();
enum PrintMode {
pmSummary,
pmList,
pmComment,
pmPreview,
pmStructure,
pmXMP,
pmIccProfile,
pmRecursive
};
enum PrintItem {
prTag = 1,
prGroup = 2,
prKey = 4,
prName = 8,
prLabel = 16,
prType = 32,
prCount = 64,
prSize = 128,
prValue = 256,
prTrans = 512,
prHex = 1024,
prSet = 2048
};
enum CommonTarget {
ctExif = 1,
ctIptc = 2,
ctComment = 4,
ctThumb = 8,
ctXmp = 16,
ctXmpSidecar = 32,
ctPreview = 64,
ctIccProfile = 128,
ctXmpRaw = 256,
ctStdInOut = 512,
ctIptcRaw =1024
};
enum FileExistsPolicy { overwritePolicy, renamePolicy, askPolicy };
enum Yod { yodYear, yodMonth, yodDay };
struct YodAdjust {
bool flag_;
const char* option_;
long adjustment_;
};
bool help_;
bool version_;
bool verbose_;
bool force_;
bool binary_;
bool unknown_;
bool preserve_;
bool timestamp_;
bool timestampOnly_;
FileExistsPolicy fileExistsPolicy_;
bool adjust_;
PrintMode printMode_;
unsigned long printItems_;
unsigned long printTags_;
int action_;
int target_;
long adjustment_;
YodAdjust yodAdjust_[3];
std::string format_;
bool formatSet_;
CmdFiles cmdFiles_;
CmdLines cmdLines_;
ModifyCmds modifyCmds_;
std::string jpegComment_;
std::string directory_;
std::string suffix_;
Files files_;
PreviewNumbers previewNumbers_;
Greps greps_;
Keys keys_;
std::string charset_;
Exiv2::DataBuf stdinBuf;
private:
static Params* instance_;
static const YodAdjust emptyYodAdjust_[];
bool first_;
private:
Params() : optstring_(":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:K:n:Q:"),
help_(false),
version_(false),
verbose_(false),
force_(false),
binary_(false),
unknown_(true),
preserve_(false),
timestamp_(false),
timestampOnly_(false),
fileExistsPolicy_(askPolicy),
adjust_(false),
printMode_(pmSummary),
printItems_(0),
printTags_(Exiv2::mdNone),
action_(0),
target_(ctExif|ctIptc|ctComment|ctXmp),
adjustment_(0),
format_("%Y%m%d_%H%M%S"),
formatSet_(false),
first_(true)
{
yodAdjust_[yodYear] = emptyYodAdjust_[yodYear];
yodAdjust_[yodMonth] = emptyYodAdjust_[yodMonth];
yodAdjust_[yodDay] = emptyYodAdjust_[yodDay];
}
Params(const Params& rhs);
~Params();
int setLogLevel(const std::string& optarg);
int evalGrep( const std::string& optarg);
int evalKey( const std::string& optarg);
int evalRename(int opt, const std::string& optarg);
int evalAdjust(const std::string& optarg);
int evalYodAdjust(const Yod& yod, const std::string& optarg);
int evalPrint(const std::string& optarg);
int evalPrintFlags(const std::string& optarg);
int evalDelete(const std::string& optarg);
int evalExtract(const std::string& optarg);
int evalInsert(const std::string& optarg);
int evalModify(int opt, const std::string& optarg);
public:
int getopt(int argc, char* const argv[]);
virtual int option(int opt, const std::string& optarg, int optopt);
virtual int nonoption(const std::string& argv);
void usage(std::ostream& os =std::cout) const;
void help(std::ostream& os =std::cout) const;
void version(bool verbose =false, std::ostream& os =std::cout) const;
static std::string printTarget(const std::string& before,int target,bool bPrint=false,std::ostream& os=std::cout);
/*
stdin can be used by multiple images in the exiv2 command line:
For example: $ cat foo.icc | exiv2 -iC- a.jpg b.jpg c.jpg will modify the ICC profile in several images.
*/
void getStdin(Exiv2::DataBuf& buf);
}; // class Params
#endif // #ifndef EXIV2APP_HPP_
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition types.hpp:193
Params
Implements the command line handling for the program.
Definition exiv2app.hpp:138
Params::nonoption
virtual int nonoption(const std::string &argv)
Handle non-option parameters.
Definition exiv2.cpp:822
Params::usage
void usage(std::ostream &os=std::cout) const
Print a minimal usage note to an output stream.
Definition exiv2.cpp:241
Params::charset_
std::string charset_
Charset to use for UNICODE Exif user comment.
Definition exiv2app.hpp:252
Params::preserve_
bool preserve_
Preserve timestamps flag.
Definition exiv2app.hpp:226
Params::help
void help(std::ostream &os=std::cout) const
Print further usage explanations to an output stream.
Definition exiv2.cpp:267
Params::target_
int target_
What common target to process.
Definition exiv2app.hpp:236
Params::version_
bool version_
Version option flag.
Definition exiv2app.hpp:221
Params::Greps
exv_grep_keys_t Greps
Container for greps.
Definition exiv2app.hpp:152
Params::Yod
Yod
Enumerates year, month and day adjustments.
Definition exiv2app.hpp:211
Params::printMode_
PrintMode printMode_
Print mode.
Definition exiv2app.hpp:231
Params::cmdFiles_
CmdFiles cmdFiles_
Names of the modification command files.
Definition exiv2app.hpp:242
Params::previewNumbers_
PreviewNumbers previewNumbers_
List of preview numbers.
Definition exiv2app.hpp:249
Params::format_
std::string format_
Filename format (-r option arg).
Definition exiv2app.hpp:240
Params::verbose_
bool verbose_
Verbose (talkative) option flag.
Definition exiv2app.hpp:222
Params::force_
bool force_
Force overwrites flag.
Definition exiv2app.hpp:223
Params::jpegComment_
std::string jpegComment_
Jpeg comment to set in the image.
Definition exiv2app.hpp:245
Params::getopt
int getopt(int argc, char *const argv[])
Call Getopt::getopt() with optstring, to inititate command line argument parsing, perform consistency...
Definition exiv2.cpp:1007
Params::CmdLines
std::vector< std::string > CmdLines
Container for commands from the command line.
Definition exiv2app.hpp:146
Params::CmdFiles
std::vector< std::string > CmdFiles
Container for command files.
Definition exiv2app.hpp:144
Params::Files
std::vector< std::string > Files
Container to store filenames.
Definition exiv2app.hpp:148
Params::formatSet_
bool formatSet_
Whether the format is set with -r.
Definition exiv2app.hpp:241
Params::directory_
std::string directory_
Location for files to extract/insert.
Definition exiv2app.hpp:246
Params::printTags_
unsigned long printTags_
Print tags (bitmap of MetadataId flags). Action (integer rather than TaskType to avoid dependency).
Definition exiv2app.hpp:233
Params::adjustment_
long adjustment_
Adjustment in seconds.
Definition exiv2app.hpp:238
Params::FileExistsPolicy
FileExistsPolicy
Enumerates the policies to handle existing files in rename action.
Definition exiv2app.hpp:208
Params::unknown_
bool unknown_
Suppress unknown tags.
Definition exiv2app.hpp:225
Params::greps_
Greps greps_
List of keys to 'grep' from the metadata.
Definition exiv2app.hpp:250
Params::printItems_
unsigned long printItems_
Print items.
Definition exiv2app.hpp:232
Params::cmdLines_
CmdLines cmdLines_
Commands from the command line.
Definition exiv2app.hpp:243
Params::getStdin
void getStdin(Exiv2::DataBuf &buf)
getStdin binary data read from stdin to DataBuf
Definition exiv2.cpp:951
Params::option
virtual int option(int opt, const std::string &optarg, int optopt)
Handle options and their arguments.
Definition exiv2.cpp:373
Params::printTarget
static std::string printTarget(const std::string &before, int target, bool bPrint=false, std::ostream &os=std::cout)
Print target_.
Definition exiv2.cpp:248
Params::cleanup
void cleanup()
Destructor.
Definition exiv2.cpp:211
Params::fileExistsPolicy_
FileExistsPolicy fileExistsPolicy_
What to do if file to rename exists.
Definition exiv2app.hpp:229
Params::stdinBuf
Exiv2::DataBuf stdinBuf
DataBuf with the binary bytes from stdin.
Definition exiv2app.hpp:254
Params::PreviewNumbers
std::set< int > PreviewNumbers
Container for preview image numbers.
Definition exiv2app.hpp:150
Params::version
void version(bool verbose=false, std::ostream &os=std::cout) const
Print version information to an output stream.
Definition exiv2.cpp:217
Params::timestamp_
bool timestamp_
Rename also sets the file timestamp.
Definition exiv2app.hpp:227
Params::CommonTarget
CommonTarget
Enumerates common targets, bitmap.
Definition exiv2app.hpp:193
Params::suffix_
std::string suffix_
File extension of the file to insert.
Definition exiv2app.hpp:247
Params::Keys
std::vector< std::string > Keys
Container for keys.
Definition exiv2app.hpp:154
Params::PrintItem
PrintItem
Individual items to print, bitmap.
Definition exiv2app.hpp:177
Params::PrintMode
PrintMode
Enumerates print modes.
Definition exiv2app.hpp:165
Params::modifyCmds_
ModifyCmds modifyCmds_
Parsed modification commands.
Definition exiv2app.hpp:244
Params::timestampOnly_
bool timestampOnly_
Rename only sets the file timestamp.
Definition exiv2app.hpp:228
Params::adjust_
bool adjust_
Adjustment flag.
Definition exiv2app.hpp:230
Params::yodAdjust_
YodAdjust yodAdjust_[3]
Year, month and day adjustment info.
Definition exiv2app.hpp:239
Params::files_
Files files_
List of non-option arguments.
Definition exiv2app.hpp:248
Params::instance
static Params & instance()
Controls all access to the global Params instance.
Definition exiv2.cpp:195
Params::keys_
Keys keys_
List of keys to match from the metadata.
Definition exiv2app.hpp:251
Params::help_
bool help_
Help option flag.
Definition exiv2app.hpp:220
Params::binary_
bool binary_
Suppress long binary values.
Definition exiv2app.hpp:224
MetadataId
MetadataId
Metadata identifiers.
Definition exiv2app.hpp:75
ModifyCmds
std::vector< ModifyCmd > ModifyCmds
Container for modification commands.
Definition exiv2app.hpp:96
CmdId
CmdId
Command identifiers.
Definition exiv2app.hpp:70
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition asfvideo.hpp:36
Exiv2::TypeId
TypeId
Exiv2 value type identifiers.
Definition types.hpp:119
CmdIdAndString
Structure to link command identifiers to strings.
Definition exiv2app.hpp:98
CmdIdAndString::cmdId_
CmdId cmdId_
Commands identifier.
Definition exiv2app.hpp:99
CmdIdAndString::cmdString_
std::string cmdString_
Command string.
Definition exiv2app.hpp:100
ModifyCmd
Structure for one parsed modification command.
Definition exiv2app.hpp:82
ModifyCmd::ModifyCmd
ModifyCmd()
C'tor.
Definition exiv2app.hpp:84
ModifyCmd::typeId_
Exiv2::TypeId typeId_
Exiv2 type identifier Flag to indicate if the type was explicitly specified (true)
Definition exiv2app.hpp:90
ModifyCmd::cmdId_
CmdId cmdId_
Command identifier.
Definition exiv2app.hpp:87
ModifyCmd::value_
std::string value_
Data.
Definition exiv2app.hpp:93
ModifyCmd::key_
std::string key_
Exiv2 key string.
Definition exiv2app.hpp:88
ModifyCmd::metadataId_
MetadataId metadataId_
Metadata identifier.
Definition exiv2app.hpp:89
Params::YodAdjust
Structure for year, month and day adjustment command line arguments.
Definition exiv2app.hpp:214
Params::YodAdjust::adjustment_
long adjustment_
Adjustment value.
Definition exiv2app.hpp:217
Params::YodAdjust::option_
const char * option_
Adjustment option string.
Definition exiv2app.hpp:216
Params::YodAdjust::flag_
bool flag_
Adjustment flag.
Definition exiv2app.hpp:215