Commit 8a9100f674dcfe8b865641a37c3b303798129917

Authored by Jay Berkenbilt
1 parent 0c8e9e59

QPDFJob: add checkConfiguration to Config

examples/pdf-job.cc
... ... @@ -35,7 +35,8 @@ int main(int argc, char* argv[])
35 35 ->pages()
36 36 ->pageSpec(".", "1-z")
37 37 ->endPages()
38   - ->qdf();
  38 + ->qdf()
  39 + ->checkConfiguration();
39 40 j.run();
40 41 }
41 42 catch (std::exception& e)
... ...
include/qpdf/QPDFJob.hh
... ... @@ -90,8 +90,9 @@ class QPDFJob
90 90 // Check to make sure no contradictory options have been
91 91 // specified. This is called automatically after initializing from
92 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 96 QPDF_DLL
96 97 void checkConfiguration();
97 98  
... ... @@ -272,6 +273,10 @@ class QPDFJob
272 273 {
273 274 friend class QPDFJob;
274 275 public:
  276 + // Proxy to QPDFJob::checkConfiguration()
  277 + QPDF_DLL
  278 + void checkConfiguration();
  279 +
275 280 QPDF_DLL
276 281 Config* inputFile(char const* filename);
277 282 QPDF_DLL
... ...
libqpdf/QPDFJob_argv.cc
... ... @@ -64,6 +64,7 @@ ArgParser::initOptionTables()
64 64 {
65 65  
66 66 # include <qpdf/auto_job_init.hh>
  67 + this->ap.addFinalCheck([this](){c_main->checkConfiguration();});
67 68 // add_help is defined in auto_job_help.hh
68 69 add_help(this->ap);
69 70 }
... ... @@ -496,7 +497,5 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
496 497 QPDFArgParser qap(argc, argv, progname_env);
497 498 setMessagePrefix(qap.getProgname());
498 499 ArgParser ap(qap, config());
499   - qap.addFinalCheck(
500   - QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
501 500 ap.parseOptions();
502 501 }
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -3,6 +3,12 @@
3 3 #include <qpdf/QTC.hh>
4 4 #include <cstring>
5 5  
  6 +void
  7 +QPDFJob::Config::checkConfiguration()
  8 +{
  9 + o.checkConfiguration();
  10 +}
  11 +
6 12 QPDFJob::Config*
7 13 QPDFJob::Config::inputFile(char const* filename)
8 14 {
... ...
libqpdf/QPDFJob_json.cc
... ... @@ -12,7 +12,7 @@ namespace
12 12 class Handlers
13 13 {
14 14 public:
15   - Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main);
  15 + Handlers(std::shared_ptr<QPDFJob::Config> c_main);
16 16 void handle(JSON&);
17 17  
18 18 private:
... ... @@ -21,7 +21,7 @@ namespace
21 21 void usage(std::string const& message);
22 22 void initHandlers();
23 23  
24   - JSONHandler& jh;
  24 + JSONHandler jh;
25 25 std::shared_ptr<QPDFJob::Config> c_main;
26 26 std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
27 27 std::shared_ptr<QPDFJob::AttConfig> c_att;
... ... @@ -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 35 c_main(c_main)
37 36 {
38 37 initHandlers();
... ... @@ -44,7 +43,7 @@ Handlers::initHandlers()
44 43 //# include <qpdf/auto_job_json_init.hh>
45 44 jh.addDictHandlers(
46 45 [](std::string const&){},
47   - [](std::string const&){});
  46 + [this](std::string const&){c_main->checkConfiguration();});
48 47  
49 48 auto input = std::make_shared<JSONHandler>();
50 49 auto input_file = std::make_shared<JSONHandler>();
... ... @@ -118,7 +117,5 @@ QPDFJob::initializeFromJson(std::string const&amp; json)
118 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 }
... ...