QPDFJob: begin configuration API with verbose

This commit is contained in:
Jay Berkenbilt 2022-01-23 19:29:18 -05:00
parent 160e869d1e
commit 79187e585a
4 changed files with 49 additions and 9 deletions

View File

@ -97,6 +97,30 @@ class QPDFJob
QPDF_DLL
bool createsOutput() const;
// CONFIGURATION
// (implemented in QPDFJob_config.cc)
// Configuration is performed by calling methods XXX QXXXQ document
class Config
{
friend class QPDFJob;
public:
QPDF_DLL
Config& verbose(bool);
private:
Config() = delete;
Config(QPDFJob& job) :
o(job)
{
}
QPDFJob& o;
};
friend class Config;
QPDF_DLL
Config config();
// QXXXQ set options -- implemented in QPDFJob_options.cc
// QXXXQ these will not be in the final interface
@ -220,7 +244,6 @@ class QPDFJob
bool linearize;
bool decrypt;
int split_pages;
bool verbose;
bool progress;
bool suppress_warnings;
bool warnings_exit_zero;
@ -410,6 +433,7 @@ class QPDFJob
std::ostream* cout;
std::ostream* cerr;
unsigned long encryption_status;
bool verbose;
};
std::shared_ptr<Members> m;
};

View File

@ -324,7 +324,8 @@ QPDFJob::Members::Members() :
warnings(false),
cout(&std::cout),
cerr(&std::cerr),
encryption_status(0)
encryption_status(0),
verbose(false)
{
}
@ -333,7 +334,6 @@ QPDFJob::QPDFJob() :
linearize(false),
decrypt(false),
split_pages(0),
verbose(false),
progress(false),
suppress_warnings(false),
warnings_exit_zero(false),
@ -447,12 +447,18 @@ void
QPDFJob::doIfVerbose(
std::function<void(std::ostream&, std::string const& prefix)> fn)
{
if (this->verbose && (this->m->cout != nullptr))
if (this->m->verbose && (this->m->cout != nullptr))
{
fn(*(this->m->cout), this->m->message_prefix);
}
}
QPDFJob::Config
QPDFJob::config()
{
return Config(*this);
}
void
QPDFJob::run()
{
@ -596,7 +602,7 @@ QPDFJob::checkConfiguration()
usage("--split-pages may not be used when"
" writing to standard output");
}
if (o.verbose)
if (this->m->verbose)
{
usage("--verbose may not be used when"
" writing to standard output");

View File

@ -26,7 +26,7 @@ namespace
class ArgParser
{
public:
ArgParser(QPDFArgParser& ap, QPDFJob& o);
ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o);
void parseOptions();
private:
@ -42,14 +42,16 @@ namespace
QPDFArgParser ap;
QPDFJob& o;
QPDFJob::Config& jc;
std::vector<char*> accumulated_args; // points to member in ap
char* pages_password;
};
}
ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob& o) :
ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o) :
ap(ap),
o(o),
jc(jc),
pages_password(nullptr)
{
initOptionTables();
@ -803,7 +805,7 @@ void
ArgParser::argVerbose()
{
// QXXXQ @TRIVIAL
o.verbose = true;
jc.verbose(true);
}
void
@ -1558,7 +1560,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
}
QPDFArgParser qap(argc, argv, progname_env);
setMessagePrefix(qap.getProgname());
ArgParser ap(qap, *this);
auto jc = config();
ArgParser ap(qap, jc, *this);
ap.parseOptions();
}

View File

@ -1 +1,8 @@
#include <qpdf/QPDFJob.hh>
QPDFJob::Config&
QPDFJob::Config::verbose(bool)
{
o.m->verbose = true;
return *this;
}