Commit 0c8e9e591268983765dd510c02d259ac7733b664

Authored by Jay Berkenbilt
1 parent 7eeaf58b

QPDFJob: prepare for automatically generated json handlers

libqpdf/QPDFJob_argv.cc
... ... @@ -23,7 +23,7 @@ namespace
23 23 {
24 24 public:
25 25 ArgParser(QPDFArgParser& ap,
26   - std::shared_ptr<QPDFJob::Config> c_main, QPDFJob& o);
  26 + std::shared_ptr<QPDFJob::Config> c_main);
27 27 void parseOptions();
28 28  
29 29 private:
... ... @@ -47,7 +47,7 @@ namespace
47 47 }
48 48  
49 49 ArgParser::ArgParser(QPDFArgParser& ap,
50   - std::shared_ptr<QPDFJob::Config> c_main, QPDFJob& o) :
  50 + std::shared_ptr<QPDFJob::Config> c_main) :
51 51 ap(ap),
52 52 c_main(c_main),
53 53 pages_password(nullptr),
... ... @@ -495,7 +495,7 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
495 495 }
496 496 QPDFArgParser qap(argc, argv, progname_env);
497 497 setMessagePrefix(qap.getProgname());
498   - ArgParser ap(qap, config(), *this);
  498 + ArgParser ap(qap, config());
499 499 qap.addFinalCheck(
500 500 QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
501 501 ap.parseOptions();
... ...
libqpdf/QPDFJob_json.cc
... ... @@ -7,6 +7,100 @@
7 7  
8 8 static JSON JOB_SCHEMA = JSON::parse(QPDFJob::json_job_schema_v1().c_str());
9 9  
  10 +namespace
  11 +{
  12 + class Handlers
  13 + {
  14 + public:
  15 + Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main);
  16 + void handle(JSON&);
  17 +
  18 + private:
  19 +//# include <qpdf/auto_job_json_decl.hh>
  20 +
  21 + void usage(std::string const& message);
  22 + void initHandlers();
  23 +
  24 + JSONHandler& jh;
  25 + std::shared_ptr<QPDFJob::Config> c_main;
  26 + std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
  27 + std::shared_ptr<QPDFJob::AttConfig> c_att;
  28 + std::shared_ptr<QPDFJob::PagesConfig> c_pages;
  29 + std::shared_ptr<QPDFJob::UOConfig> c_uo;
  30 + std::shared_ptr<QPDFJob::EncConfig> c_enc;
  31 + };
  32 +}
  33 +
  34 +Handlers::Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main) :
  35 + jh(jh),
  36 + c_main(c_main)
  37 +{
  38 + initHandlers();
  39 +}
  40 +
  41 +void
  42 +Handlers::initHandlers()
  43 +{
  44 +//# include <qpdf/auto_job_json_init.hh>
  45 + jh.addDictHandlers(
  46 + [](std::string const&){},
  47 + [](std::string const&){});
  48 +
  49 + auto input = std::make_shared<JSONHandler>();
  50 + auto input_file = std::make_shared<JSONHandler>();
  51 + auto input_file_name = std::make_shared<JSONHandler>();
  52 + auto output = std::make_shared<JSONHandler>();
  53 + auto output_file = std::make_shared<JSONHandler>();
  54 + auto output_file_name = std::make_shared<JSONHandler>();
  55 + auto output_options = std::make_shared<JSONHandler>();
  56 + auto output_options_qdf = std::make_shared<JSONHandler>();
  57 +
  58 + input->addDictHandlers(
  59 + [](std::string const&){},
  60 + [](std::string const&){});
  61 + input_file->addDictHandlers(
  62 + [](std::string const&){},
  63 + [](std::string const&){});
  64 + output->addDictHandlers(
  65 + [](std::string const&){},
  66 + [](std::string const&){});
  67 + output_file->addDictHandlers(
  68 + [](std::string const&){},
  69 + [](std::string const&){});
  70 + output_options->addDictHandlers(
  71 + [](std::string const&){},
  72 + [](std::string const&){});
  73 +
  74 + jh.addDictKeyHandler("input", input);
  75 + input->addDictKeyHandler("file", input_file);
  76 + input_file->addDictKeyHandler("name", input_file_name);
  77 + jh.addDictKeyHandler("output", output);
  78 + output->addDictKeyHandler("file", output_file);
  79 + output_file->addDictKeyHandler("name", output_file_name);
  80 + output->addDictKeyHandler("options", output_options);
  81 + output_options->addDictKeyHandler("qdf", output_options_qdf);
  82 +
  83 + input_file_name->addStringHandler(
  84 + [this](std::string const&, std::string const& v) {
  85 + c_main->inputFile(v.c_str());
  86 + });
  87 + output_file_name->addStringHandler(
  88 + [this](std::string const&, std::string const& v) {
  89 + c_main->outputFile(v.c_str());
  90 + });
  91 + output_options_qdf->addBoolHandler(
  92 + [this](std::string const&, bool v) {
  93 + // QXXXQ require v to be true
  94 + c_main->qdf();
  95 + });
  96 +}
  97 +
  98 +void
  99 +Handlers::handle(JSON& j)
  100 +{
  101 + jh.handle(".", j);
  102 +}
  103 +
10 104 void
11 105 QPDFJob::initializeFromJson(std::string const& json)
12 106 {
... ... @@ -25,75 +119,6 @@ QPDFJob::initializeFromJson(std::string const&amp; json)
25 119 }
26 120  
27 121 JSONHandler jh;
28   - {
29   - jh.addDictHandlers(
30   - [](std::string const&){},
31   - [](std::string const&){});
32   -
33   - auto input = std::make_shared<JSONHandler>();
34   - auto input_file = std::make_shared<JSONHandler>();
35   - auto input_file_name = std::make_shared<JSONHandler>();
36   - auto output = std::make_shared<JSONHandler>();
37   - auto output_file = std::make_shared<JSONHandler>();
38   - auto output_file_name = std::make_shared<JSONHandler>();
39   - auto output_options = std::make_shared<JSONHandler>();
40   - auto output_options_qdf = std::make_shared<JSONHandler>();
41   -
42   - input->addDictHandlers(
43   - [](std::string const&){},
44   - [](std::string const&){});
45   - input_file->addDictHandlers(
46   - [](std::string const&){},
47   - [](std::string const&){});
48   - output->addDictHandlers(
49   - [](std::string const&){},
50   - [](std::string const&){});
51   - output_file->addDictHandlers(
52   - [](std::string const&){},
53   - [](std::string const&){});
54   - output_options->addDictHandlers(
55   - [](std::string const&){},
56   - [](std::string const&){});
57   -
58   - jh.addDictKeyHandler("input", input);
59   - input->addDictKeyHandler("file", input_file);
60   - input_file->addDictKeyHandler("name", input_file_name);
61   - jh.addDictKeyHandler("output", output);
62   - output->addDictKeyHandler("file", output_file);
63   - output_file->addDictKeyHandler("name", output_file_name);
64   - output->addDictKeyHandler("options", output_options);
65   - output_options->addDictKeyHandler("qdf", output_options_qdf);
66   -
67   - input_file_name->addStringHandler(
68   - [this](std::string const&, std::string const& v) {
69   - config()->inputFile(v.c_str());
70   - });
71   - output_file_name->addStringHandler(
72   - [this](std::string const&, std::string const& v) {
73   - config()->outputFile(v.c_str());
74   - });
75   - output_options_qdf->addBoolHandler(
76   - [this](std::string const&, bool v) {
77   - // QXXXQ require v to be true
78   - config()->qdf();
79   - });
80   - }
81   -
82   - // {
83   - // "input": {
84   - // "file": {
85   - // "name": "/home/ejb/source/examples/pdf/minimal.pdf"
86   - // }
87   - // },
88   - // "output": {
89   - // "file": {
90   - // "name": "/tmp/a.pdf"
91   - // },
92   - // "options": {
93   - // "qdf": true
94   - // }
95   - // }
96   - // }
97   -
98   - jh.handle(".", j);
  122 + Handlers h(jh, config());
  123 + h.handle(j);
99 124 }
... ...