Commit 79187e585a7c1ac26fe8b2a347a9546885a973e5
1 parent
160e869d
QPDFJob: begin configuration API with verbose
Showing
4 changed files
with
49 additions
and
9 deletions
include/qpdf/QPDFJob.hh
| ... | ... | @@ -97,6 +97,30 @@ class QPDFJob |
| 97 | 97 | QPDF_DLL |
| 98 | 98 | bool createsOutput() const; |
| 99 | 99 | |
| 100 | + // CONFIGURATION | |
| 101 | + // (implemented in QPDFJob_config.cc) | |
| 102 | + | |
| 103 | + // Configuration is performed by calling methods XXX QXXXQ document | |
| 104 | + class Config | |
| 105 | + { | |
| 106 | + friend class QPDFJob; | |
| 107 | + public: | |
| 108 | + QPDF_DLL | |
| 109 | + Config& verbose(bool); | |
| 110 | + | |
| 111 | + private: | |
| 112 | + Config() = delete; | |
| 113 | + Config(QPDFJob& job) : | |
| 114 | + o(job) | |
| 115 | + { | |
| 116 | + } | |
| 117 | + QPDFJob& o; | |
| 118 | + }; | |
| 119 | + friend class Config; | |
| 120 | + | |
| 121 | + QPDF_DLL | |
| 122 | + Config config(); | |
| 123 | + | |
| 100 | 124 | // QXXXQ set options -- implemented in QPDFJob_options.cc |
| 101 | 125 | |
| 102 | 126 | // QXXXQ these will not be in the final interface |
| ... | ... | @@ -220,7 +244,6 @@ class QPDFJob |
| 220 | 244 | bool linearize; |
| 221 | 245 | bool decrypt; |
| 222 | 246 | int split_pages; |
| 223 | - bool verbose; | |
| 224 | 247 | bool progress; |
| 225 | 248 | bool suppress_warnings; |
| 226 | 249 | bool warnings_exit_zero; |
| ... | ... | @@ -410,6 +433,7 @@ class QPDFJob |
| 410 | 433 | std::ostream* cout; |
| 411 | 434 | std::ostream* cerr; |
| 412 | 435 | unsigned long encryption_status; |
| 436 | + bool verbose; | |
| 413 | 437 | }; |
| 414 | 438 | std::shared_ptr<Members> m; |
| 415 | 439 | }; | ... | ... |
libqpdf/QPDFJob.cc
| ... | ... | @@ -324,7 +324,8 @@ QPDFJob::Members::Members() : |
| 324 | 324 | warnings(false), |
| 325 | 325 | cout(&std::cout), |
| 326 | 326 | cerr(&std::cerr), |
| 327 | - encryption_status(0) | |
| 327 | + encryption_status(0), | |
| 328 | + verbose(false) | |
| 328 | 329 | { |
| 329 | 330 | } |
| 330 | 331 | |
| ... | ... | @@ -333,7 +334,6 @@ QPDFJob::QPDFJob() : |
| 333 | 334 | linearize(false), |
| 334 | 335 | decrypt(false), |
| 335 | 336 | split_pages(0), |
| 336 | - verbose(false), | |
| 337 | 337 | progress(false), |
| 338 | 338 | suppress_warnings(false), |
| 339 | 339 | warnings_exit_zero(false), |
| ... | ... | @@ -447,12 +447,18 @@ void |
| 447 | 447 | QPDFJob::doIfVerbose( |
| 448 | 448 | std::function<void(std::ostream&, std::string const& prefix)> fn) |
| 449 | 449 | { |
| 450 | - if (this->verbose && (this->m->cout != nullptr)) | |
| 450 | + if (this->m->verbose && (this->m->cout != nullptr)) | |
| 451 | 451 | { |
| 452 | 452 | fn(*(this->m->cout), this->m->message_prefix); |
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | +QPDFJob::Config | |
| 457 | +QPDFJob::config() | |
| 458 | +{ | |
| 459 | + return Config(*this); | |
| 460 | +} | |
| 461 | + | |
| 456 | 462 | void |
| 457 | 463 | QPDFJob::run() |
| 458 | 464 | { |
| ... | ... | @@ -596,7 +602,7 @@ QPDFJob::checkConfiguration() |
| 596 | 602 | usage("--split-pages may not be used when" |
| 597 | 603 | " writing to standard output"); |
| 598 | 604 | } |
| 599 | - if (o.verbose) | |
| 605 | + if (this->m->verbose) | |
| 600 | 606 | { |
| 601 | 607 | usage("--verbose may not be used when" |
| 602 | 608 | " writing to standard output"); | ... | ... |
libqpdf/QPDFJob_argv.cc
| ... | ... | @@ -26,7 +26,7 @@ namespace |
| 26 | 26 | class ArgParser |
| 27 | 27 | { |
| 28 | 28 | public: |
| 29 | - ArgParser(QPDFArgParser& ap, QPDFJob& o); | |
| 29 | + ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o); | |
| 30 | 30 | void parseOptions(); |
| 31 | 31 | |
| 32 | 32 | private: |
| ... | ... | @@ -42,14 +42,16 @@ namespace |
| 42 | 42 | |
| 43 | 43 | QPDFArgParser ap; |
| 44 | 44 | QPDFJob& o; |
| 45 | + QPDFJob::Config& jc; | |
| 45 | 46 | std::vector<char*> accumulated_args; // points to member in ap |
| 46 | 47 | char* pages_password; |
| 47 | 48 | }; |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | -ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob& o) : | |
| 51 | +ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o) : | |
| 51 | 52 | ap(ap), |
| 52 | 53 | o(o), |
| 54 | + jc(jc), | |
| 53 | 55 | pages_password(nullptr) |
| 54 | 56 | { |
| 55 | 57 | initOptionTables(); |
| ... | ... | @@ -803,7 +805,7 @@ void |
| 803 | 805 | ArgParser::argVerbose() |
| 804 | 806 | { |
| 805 | 807 | // QXXXQ @TRIVIAL |
| 806 | - o.verbose = true; | |
| 808 | + jc.verbose(true); | |
| 807 | 809 | } |
| 808 | 810 | |
| 809 | 811 | void |
| ... | ... | @@ -1558,7 +1560,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) |
| 1558 | 1560 | } |
| 1559 | 1561 | QPDFArgParser qap(argc, argv, progname_env); |
| 1560 | 1562 | setMessagePrefix(qap.getProgname()); |
| 1561 | - ArgParser ap(qap, *this); | |
| 1563 | + auto jc = config(); | |
| 1564 | + ArgParser ap(qap, jc, *this); | |
| 1562 | 1565 | ap.parseOptions(); |
| 1563 | 1566 | } |
| 1564 | 1567 | ... | ... |