Commit da14ab4dc7b1caee1708483cf714683f7d811ca7
1 parent
dab27c9b
Move definition of QPDF::JSONReactor into QPDF_json
Allow access to private header files when defining data members.
Showing
3 changed files
with
84 additions
and
84 deletions
include/qpdf/QPDF.hh
| @@ -32,7 +32,6 @@ | @@ -32,7 +32,6 @@ | ||
| 32 | #include <memory> | 32 | #include <memory> |
| 33 | #include <stdio.h> | 33 | #include <stdio.h> |
| 34 | #include <string> | 34 | #include <string> |
| 35 | -#include <variant> | ||
| 36 | #include <vector> | 35 | #include <vector> |
| 37 | 36 | ||
| 38 | #include <qpdf/Buffer.hh> | 37 | #include <qpdf/Buffer.hh> |
| @@ -51,7 +50,6 @@ class BitStream; | @@ -51,7 +50,6 @@ class BitStream; | ||
| 51 | class BitWriter; | 50 | class BitWriter; |
| 52 | class QPDFLogger; | 51 | class QPDFLogger; |
| 53 | class QPDFParser; | 52 | class QPDFParser; |
| 54 | -struct JSON_Descr; | ||
| 55 | 53 | ||
| 56 | class QPDF | 54 | class QPDF |
| 57 | { | 55 | { |
| @@ -1110,72 +1108,7 @@ class QPDF | @@ -1110,72 +1108,7 @@ class QPDF | ||
| 1110 | std::set<QPDFObjGen>::const_iterator iter; | 1108 | std::set<QPDFObjGen>::const_iterator iter; |
| 1111 | }; | 1109 | }; |
| 1112 | 1110 | ||
| 1113 | - class JSONReactor: public JSON::Reactor | ||
| 1114 | - { | ||
| 1115 | - public: | ||
| 1116 | - JSONReactor( | ||
| 1117 | - QPDF&, std::shared_ptr<InputSource> is, bool must_be_complete); | ||
| 1118 | - virtual ~JSONReactor() = default; | ||
| 1119 | - virtual void dictionaryStart() override; | ||
| 1120 | - virtual void arrayStart() override; | ||
| 1121 | - virtual void containerEnd(JSON const& value) override; | ||
| 1122 | - virtual void topLevelScalar() override; | ||
| 1123 | - virtual bool | ||
| 1124 | - dictionaryItem(std::string const& key, JSON const& value) override; | ||
| 1125 | - virtual bool arrayItem(JSON const& value) override; | ||
| 1126 | - | ||
| 1127 | - bool anyErrors() const; | ||
| 1128 | - | ||
| 1129 | - private: | ||
| 1130 | - enum state_e { | ||
| 1131 | - st_initial, | ||
| 1132 | - st_top, | ||
| 1133 | - st_qpdf, | ||
| 1134 | - st_qpdf_meta, | ||
| 1135 | - st_objects, | ||
| 1136 | - st_trailer, | ||
| 1137 | - st_object_top, | ||
| 1138 | - st_stream, | ||
| 1139 | - st_object, | ||
| 1140 | - st_ignore, | ||
| 1141 | - }; | ||
| 1142 | - | ||
| 1143 | - void containerStart(); | ||
| 1144 | - void nestedState(std::string const& key, JSON const& value, state_e); | ||
| 1145 | - void setObjectDescription(QPDFObjectHandle& oh, JSON const& value); | ||
| 1146 | - QPDFObjectHandle makeObject(JSON const& value); | ||
| 1147 | - void error(qpdf_offset_t offset, std::string const& message); | ||
| 1148 | - QPDFObjectHandle reserveObject(int obj, int gen); | ||
| 1149 | - void replaceObject( | ||
| 1150 | - QPDFObjectHandle to_replace, | ||
| 1151 | - QPDFObjectHandle replacement, | ||
| 1152 | - JSON const& value); | ||
| 1153 | - | ||
| 1154 | - QPDF& pdf; | ||
| 1155 | - std::shared_ptr<InputSource> is; | ||
| 1156 | - bool must_be_complete; | ||
| 1157 | - std::shared_ptr<std::variant<std::string, JSON_Descr>> descr; | ||
| 1158 | - bool errors; | ||
| 1159 | - bool parse_error; | ||
| 1160 | - bool saw_qpdf; | ||
| 1161 | - bool saw_qpdf_meta; | ||
| 1162 | - bool saw_objects; | ||
| 1163 | - bool saw_json_version; | ||
| 1164 | - bool saw_pdf_version; | ||
| 1165 | - bool saw_trailer; | ||
| 1166 | - state_e state; | ||
| 1167 | - state_e next_state; | ||
| 1168 | - std::string cur_object; | ||
| 1169 | - bool saw_value; | ||
| 1170 | - bool saw_stream; | ||
| 1171 | - bool saw_dict; | ||
| 1172 | - bool saw_data; | ||
| 1173 | - bool saw_datafile; | ||
| 1174 | - bool this_stream_needs_data; | ||
| 1175 | - std::vector<state_e> state_stack; | ||
| 1176 | - std::vector<QPDFObjectHandle> object_stack; | ||
| 1177 | - std::set<QPDFObjGen> reserved; | ||
| 1178 | - }; | 1111 | + class JSONReactor; |
| 1179 | 1112 | ||
| 1180 | void parse(char const* password); | 1113 | void parse(char const* password); |
| 1181 | void inParse(bool); | 1114 | void inParse(bool); |
libqpdf/QPDF_json.cc
| @@ -223,13 +223,79 @@ provide_data( | @@ -223,13 +223,79 @@ provide_data( | ||
| 223 | }; | 223 | }; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | +class QPDF::JSONReactor: public JSON::Reactor | ||
| 227 | +{ | ||
| 228 | + public: | ||
| 229 | + JSONReactor(QPDF&, std::shared_ptr<InputSource> is, bool must_be_complete); | ||
| 230 | + virtual ~JSONReactor() = default; | ||
| 231 | + virtual void dictionaryStart() override; | ||
| 232 | + virtual void arrayStart() override; | ||
| 233 | + virtual void containerEnd(JSON const& value) override; | ||
| 234 | + virtual void topLevelScalar() override; | ||
| 235 | + virtual bool | ||
| 236 | + dictionaryItem(std::string const& key, JSON const& value) override; | ||
| 237 | + virtual bool arrayItem(JSON const& value) override; | ||
| 238 | + | ||
| 239 | + bool anyErrors() const; | ||
| 240 | + | ||
| 241 | + private: | ||
| 242 | + enum state_e { | ||
| 243 | + st_initial, | ||
| 244 | + st_top, | ||
| 245 | + st_qpdf, | ||
| 246 | + st_qpdf_meta, | ||
| 247 | + st_objects, | ||
| 248 | + st_trailer, | ||
| 249 | + st_object_top, | ||
| 250 | + st_stream, | ||
| 251 | + st_object, | ||
| 252 | + st_ignore, | ||
| 253 | + }; | ||
| 254 | + | ||
| 255 | + void containerStart(); | ||
| 256 | + void nestedState(std::string const& key, JSON const& value, state_e); | ||
| 257 | + void setObjectDescription(QPDFObjectHandle& oh, JSON const& value); | ||
| 258 | + QPDFObjectHandle makeObject(JSON const& value); | ||
| 259 | + void error(qpdf_offset_t offset, std::string const& message); | ||
| 260 | + QPDFObjectHandle reserveObject(int obj, int gen); | ||
| 261 | + void replaceObject( | ||
| 262 | + QPDFObjectHandle to_replace, | ||
| 263 | + QPDFObjectHandle replacement, | ||
| 264 | + JSON const& value); | ||
| 265 | + | ||
| 266 | + QPDF& pdf; | ||
| 267 | + std::shared_ptr<InputSource> is; | ||
| 268 | + bool must_be_complete; | ||
| 269 | + std::shared_ptr<QPDFValue::Description> descr; | ||
| 270 | + bool errors; | ||
| 271 | + bool parse_error; | ||
| 272 | + bool saw_qpdf; | ||
| 273 | + bool saw_qpdf_meta; | ||
| 274 | + bool saw_objects; | ||
| 275 | + bool saw_json_version; | ||
| 276 | + bool saw_pdf_version; | ||
| 277 | + bool saw_trailer; | ||
| 278 | + state_e state; | ||
| 279 | + state_e next_state; | ||
| 280 | + std::string cur_object; | ||
| 281 | + bool saw_value; | ||
| 282 | + bool saw_stream; | ||
| 283 | + bool saw_dict; | ||
| 284 | + bool saw_data; | ||
| 285 | + bool saw_datafile; | ||
| 286 | + bool this_stream_needs_data; | ||
| 287 | + std::vector<state_e> state_stack; | ||
| 288 | + std::vector<QPDFObjectHandle> object_stack; | ||
| 289 | + std::set<QPDFObjGen> reserved; | ||
| 290 | +}; | ||
| 291 | + | ||
| 226 | QPDF::JSONReactor::JSONReactor( | 292 | QPDF::JSONReactor::JSONReactor( |
| 227 | QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) : | 293 | QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) : |
| 228 | pdf(pdf), | 294 | pdf(pdf), |
| 229 | is(is), | 295 | is(is), |
| 230 | must_be_complete(must_be_complete), | 296 | must_be_complete(must_be_complete), |
| 231 | - descr(std::make_shared<std::variant<std::string, JSON_Descr>>( | ||
| 232 | - JSON_Descr(std::make_shared<std::string>(is->getName()), ""))), | 297 | + descr(std::make_shared<QPDFValue::Description>(QPDFValue::JSON_Descr( |
| 298 | + std::make_shared<std::string>(is->getName()), ""))), | ||
| 233 | errors(false), | 299 | errors(false), |
| 234 | parse_error(false), | 300 | parse_error(false), |
| 235 | saw_qpdf(false), | 301 | saw_qpdf(false), |
| @@ -679,10 +745,10 @@ QPDF::JSONReactor::arrayItem(JSON const& value) | @@ -679,10 +745,10 @@ QPDF::JSONReactor::arrayItem(JSON const& value) | ||
| 679 | void | 745 | void |
| 680 | QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value) | 746 | QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value) |
| 681 | { | 747 | { |
| 682 | - auto j_descr = std::get<JSON_Descr>(*descr); | 748 | + auto j_descr = std::get<QPDFValue::JSON_Descr>(*descr); |
| 683 | if (j_descr.object != cur_object) { | 749 | if (j_descr.object != cur_object) { |
| 684 | descr = std::make_shared<QPDFValue::Description>( | 750 | descr = std::make_shared<QPDFValue::Description>( |
| 685 | - JSON_Descr(j_descr.input, cur_object)); | 751 | + QPDFValue::JSON_Descr(j_descr.input, cur_object)); |
| 686 | } | 752 | } |
| 687 | 753 | ||
| 688 | oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart()); | 754 | oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart()); |
libqpdf/qpdf/QPDFValue.hh
| @@ -14,18 +14,6 @@ class QPDF; | @@ -14,18 +14,6 @@ class QPDF; | ||
| 14 | class QPDFObjectHandle; | 14 | class QPDFObjectHandle; |
| 15 | class QPDFObject; | 15 | class QPDFObject; |
| 16 | 16 | ||
| 17 | -struct JSON_Descr | ||
| 18 | -{ | ||
| 19 | - JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) : | ||
| 20 | - input(input), | ||
| 21 | - object(object) | ||
| 22 | - { | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - std::shared_ptr<std::string> input; | ||
| 26 | - std::string object; | ||
| 27 | -}; | ||
| 28 | - | ||
| 29 | class QPDFValue | 17 | class QPDFValue |
| 30 | { | 18 | { |
| 31 | friend class QPDFObject; | 19 | friend class QPDFObject; |
| @@ -37,6 +25,19 @@ class QPDFValue | @@ -37,6 +25,19 @@ class QPDFValue | ||
| 37 | virtual std::string unparse() = 0; | 25 | virtual std::string unparse() = 0; |
| 38 | virtual JSON getJSON(int json_version) = 0; | 26 | virtual JSON getJSON(int json_version) = 0; |
| 39 | 27 | ||
| 28 | + struct JSON_Descr | ||
| 29 | + { | ||
| 30 | + JSON_Descr( | ||
| 31 | + std::shared_ptr<std::string> input, std::string const& object) : | ||
| 32 | + input(input), | ||
| 33 | + object(object) | ||
| 34 | + { | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + std::shared_ptr<std::string> input; | ||
| 38 | + std::string object; | ||
| 39 | + }; | ||
| 40 | + | ||
| 40 | using Description = std::variant<std::string, JSON_Descr>; | 41 | using Description = std::variant<std::string, JSON_Descr>; |
| 41 | 42 | ||
| 42 | virtual void | 43 | virtual void |