Commit 8a9100f674dcfe8b865641a37c3b303798129917
1 parent
0c8e9e59
QPDFJob: add checkConfiguration to Config
Showing
5 changed files
with
21 additions
and
13 deletions
examples/pdf-job.cc
| @@ -35,7 +35,8 @@ int main(int argc, char* argv[]) | @@ -35,7 +35,8 @@ int main(int argc, char* argv[]) | ||
| 35 | ->pages() | 35 | ->pages() |
| 36 | ->pageSpec(".", "1-z") | 36 | ->pageSpec(".", "1-z") |
| 37 | ->endPages() | 37 | ->endPages() |
| 38 | - ->qdf(); | 38 | + ->qdf() |
| 39 | + ->checkConfiguration(); | ||
| 39 | j.run(); | 40 | j.run(); |
| 40 | } | 41 | } |
| 41 | catch (std::exception& e) | 42 | catch (std::exception& e) |
include/qpdf/QPDFJob.hh
| @@ -90,8 +90,9 @@ class QPDFJob | @@ -90,8 +90,9 @@ class QPDFJob | ||
| 90 | // Check to make sure no contradictory options have been | 90 | // Check to make sure no contradictory options have been |
| 91 | // specified. This is called automatically after initializing from | 91 | // specified. This is called automatically after initializing from |
| 92 | // argv or json and is also called by run, but you can call it | 92 | // argv or json and is also called by run, but you can call it |
| 93 | - // manually as well. It throws a Usage exception if there are any | ||
| 94 | - // errors. | 93 | + // manually as well. It throws a QPDFUsage exception if there are |
| 94 | + // any errors. This Config object (see CONFIGURATION) also has a | ||
| 95 | + // checkConfiguration method which calls this one. | ||
| 95 | QPDF_DLL | 96 | QPDF_DLL |
| 96 | void checkConfiguration(); | 97 | void checkConfiguration(); |
| 97 | 98 | ||
| @@ -272,6 +273,10 @@ class QPDFJob | @@ -272,6 +273,10 @@ class QPDFJob | ||
| 272 | { | 273 | { |
| 273 | friend class QPDFJob; | 274 | friend class QPDFJob; |
| 274 | public: | 275 | public: |
| 276 | + // Proxy to QPDFJob::checkConfiguration() | ||
| 277 | + QPDF_DLL | ||
| 278 | + void checkConfiguration(); | ||
| 279 | + | ||
| 275 | QPDF_DLL | 280 | QPDF_DLL |
| 276 | Config* inputFile(char const* filename); | 281 | Config* inputFile(char const* filename); |
| 277 | QPDF_DLL | 282 | QPDF_DLL |
libqpdf/QPDFJob_argv.cc
| @@ -64,6 +64,7 @@ ArgParser::initOptionTables() | @@ -64,6 +64,7 @@ ArgParser::initOptionTables() | ||
| 64 | { | 64 | { |
| 65 | 65 | ||
| 66 | # include <qpdf/auto_job_init.hh> | 66 | # include <qpdf/auto_job_init.hh> |
| 67 | + this->ap.addFinalCheck([this](){c_main->checkConfiguration();}); | ||
| 67 | // add_help is defined in auto_job_help.hh | 68 | // add_help is defined in auto_job_help.hh |
| 68 | add_help(this->ap); | 69 | add_help(this->ap); |
| 69 | } | 70 | } |
| @@ -496,7 +497,5 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | @@ -496,7 +497,5 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | ||
| 496 | QPDFArgParser qap(argc, argv, progname_env); | 497 | QPDFArgParser qap(argc, argv, progname_env); |
| 497 | setMessagePrefix(qap.getProgname()); | 498 | setMessagePrefix(qap.getProgname()); |
| 498 | ArgParser ap(qap, config()); | 499 | ArgParser ap(qap, config()); |
| 499 | - qap.addFinalCheck( | ||
| 500 | - QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this)); | ||
| 501 | ap.parseOptions(); | 500 | ap.parseOptions(); |
| 502 | } | 501 | } |
libqpdf/QPDFJob_config.cc
| @@ -3,6 +3,12 @@ | @@ -3,6 +3,12 @@ | ||
| 3 | #include <qpdf/QTC.hh> | 3 | #include <qpdf/QTC.hh> |
| 4 | #include <cstring> | 4 | #include <cstring> |
| 5 | 5 | ||
| 6 | +void | ||
| 7 | +QPDFJob::Config::checkConfiguration() | ||
| 8 | +{ | ||
| 9 | + o.checkConfiguration(); | ||
| 10 | +} | ||
| 11 | + | ||
| 6 | QPDFJob::Config* | 12 | QPDFJob::Config* |
| 7 | QPDFJob::Config::inputFile(char const* filename) | 13 | QPDFJob::Config::inputFile(char const* filename) |
| 8 | { | 14 | { |
libqpdf/QPDFJob_json.cc
| @@ -12,7 +12,7 @@ namespace | @@ -12,7 +12,7 @@ namespace | ||
| 12 | class Handlers | 12 | class Handlers |
| 13 | { | 13 | { |
| 14 | public: | 14 | public: |
| 15 | - Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main); | 15 | + Handlers(std::shared_ptr<QPDFJob::Config> c_main); |
| 16 | void handle(JSON&); | 16 | void handle(JSON&); |
| 17 | 17 | ||
| 18 | private: | 18 | private: |
| @@ -21,7 +21,7 @@ namespace | @@ -21,7 +21,7 @@ namespace | ||
| 21 | void usage(std::string const& message); | 21 | void usage(std::string const& message); |
| 22 | void initHandlers(); | 22 | void initHandlers(); |
| 23 | 23 | ||
| 24 | - JSONHandler& jh; | 24 | + JSONHandler jh; |
| 25 | std::shared_ptr<QPDFJob::Config> c_main; | 25 | std::shared_ptr<QPDFJob::Config> c_main; |
| 26 | std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att; | 26 | std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att; |
| 27 | std::shared_ptr<QPDFJob::AttConfig> c_att; | 27 | std::shared_ptr<QPDFJob::AttConfig> c_att; |
| @@ -31,8 +31,7 @@ namespace | @@ -31,8 +31,7 @@ namespace | ||
| 31 | }; | 31 | }; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | -Handlers::Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main) : | ||
| 35 | - jh(jh), | 34 | +Handlers::Handlers(std::shared_ptr<QPDFJob::Config> c_main) : |
| 36 | c_main(c_main) | 35 | c_main(c_main) |
| 37 | { | 36 | { |
| 38 | initHandlers(); | 37 | initHandlers(); |
| @@ -44,7 +43,7 @@ Handlers::initHandlers() | @@ -44,7 +43,7 @@ Handlers::initHandlers() | ||
| 44 | //# include <qpdf/auto_job_json_init.hh> | 43 | //# include <qpdf/auto_job_json_init.hh> |
| 45 | jh.addDictHandlers( | 44 | jh.addDictHandlers( |
| 46 | [](std::string const&){}, | 45 | [](std::string const&){}, |
| 47 | - [](std::string const&){}); | 46 | + [this](std::string const&){c_main->checkConfiguration();}); |
| 48 | 47 | ||
| 49 | auto input = std::make_shared<JSONHandler>(); | 48 | auto input = std::make_shared<JSONHandler>(); |
| 50 | auto input_file = std::make_shared<JSONHandler>(); | 49 | auto input_file = std::make_shared<JSONHandler>(); |
| @@ -118,7 +117,5 @@ QPDFJob::initializeFromJson(std::string const& json) | @@ -118,7 +117,5 @@ QPDFJob::initializeFromJson(std::string const& json) | ||
| 118 | throw std::runtime_error(msg.str()); | 117 | throw std::runtime_error(msg.str()); |
| 119 | } | 118 | } |
| 120 | 119 | ||
| 121 | - JSONHandler jh; | ||
| 122 | - Handlers h(jh, config()); | ||
| 123 | - h.handle(j); | 120 | + Handlers(config()).handle(j); |
| 124 | } | 121 | } |