mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-08 17:24:06 +00:00
Move definition of QPDF::JSONReactor into QPDF_json
Allow access to private header files when defining data members.
This commit is contained in:
parent
dab27c9bb3
commit
da14ab4dc7
@ -32,7 +32,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <qpdf/Buffer.hh>
|
#include <qpdf/Buffer.hh>
|
||||||
@ -51,7 +50,6 @@ class BitStream;
|
|||||||
class BitWriter;
|
class BitWriter;
|
||||||
class QPDFLogger;
|
class QPDFLogger;
|
||||||
class QPDFParser;
|
class QPDFParser;
|
||||||
struct JSON_Descr;
|
|
||||||
|
|
||||||
class QPDF
|
class QPDF
|
||||||
{
|
{
|
||||||
@ -1110,72 +1108,7 @@ class QPDF
|
|||||||
std::set<QPDFObjGen>::const_iterator iter;
|
std::set<QPDFObjGen>::const_iterator iter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JSONReactor: public JSON::Reactor
|
class JSONReactor;
|
||||||
{
|
|
||||||
public:
|
|
||||||
JSONReactor(
|
|
||||||
QPDF&, std::shared_ptr<InputSource> is, bool must_be_complete);
|
|
||||||
virtual ~JSONReactor() = default;
|
|
||||||
virtual void dictionaryStart() override;
|
|
||||||
virtual void arrayStart() override;
|
|
||||||
virtual void containerEnd(JSON const& value) override;
|
|
||||||
virtual void topLevelScalar() override;
|
|
||||||
virtual bool
|
|
||||||
dictionaryItem(std::string const& key, JSON const& value) override;
|
|
||||||
virtual bool arrayItem(JSON const& value) override;
|
|
||||||
|
|
||||||
bool anyErrors() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum state_e {
|
|
||||||
st_initial,
|
|
||||||
st_top,
|
|
||||||
st_qpdf,
|
|
||||||
st_qpdf_meta,
|
|
||||||
st_objects,
|
|
||||||
st_trailer,
|
|
||||||
st_object_top,
|
|
||||||
st_stream,
|
|
||||||
st_object,
|
|
||||||
st_ignore,
|
|
||||||
};
|
|
||||||
|
|
||||||
void containerStart();
|
|
||||||
void nestedState(std::string const& key, JSON const& value, state_e);
|
|
||||||
void setObjectDescription(QPDFObjectHandle& oh, JSON const& value);
|
|
||||||
QPDFObjectHandle makeObject(JSON const& value);
|
|
||||||
void error(qpdf_offset_t offset, std::string const& message);
|
|
||||||
QPDFObjectHandle reserveObject(int obj, int gen);
|
|
||||||
void replaceObject(
|
|
||||||
QPDFObjectHandle to_replace,
|
|
||||||
QPDFObjectHandle replacement,
|
|
||||||
JSON const& value);
|
|
||||||
|
|
||||||
QPDF& pdf;
|
|
||||||
std::shared_ptr<InputSource> is;
|
|
||||||
bool must_be_complete;
|
|
||||||
std::shared_ptr<std::variant<std::string, JSON_Descr>> descr;
|
|
||||||
bool errors;
|
|
||||||
bool parse_error;
|
|
||||||
bool saw_qpdf;
|
|
||||||
bool saw_qpdf_meta;
|
|
||||||
bool saw_objects;
|
|
||||||
bool saw_json_version;
|
|
||||||
bool saw_pdf_version;
|
|
||||||
bool saw_trailer;
|
|
||||||
state_e state;
|
|
||||||
state_e next_state;
|
|
||||||
std::string cur_object;
|
|
||||||
bool saw_value;
|
|
||||||
bool saw_stream;
|
|
||||||
bool saw_dict;
|
|
||||||
bool saw_data;
|
|
||||||
bool saw_datafile;
|
|
||||||
bool this_stream_needs_data;
|
|
||||||
std::vector<state_e> state_stack;
|
|
||||||
std::vector<QPDFObjectHandle> object_stack;
|
|
||||||
std::set<QPDFObjGen> reserved;
|
|
||||||
};
|
|
||||||
|
|
||||||
void parse(char const* password);
|
void parse(char const* password);
|
||||||
void inParse(bool);
|
void inParse(bool);
|
||||||
|
@ -223,13 +223,79 @@ provide_data(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class QPDF::JSONReactor: public JSON::Reactor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JSONReactor(QPDF&, std::shared_ptr<InputSource> is, bool must_be_complete);
|
||||||
|
virtual ~JSONReactor() = default;
|
||||||
|
virtual void dictionaryStart() override;
|
||||||
|
virtual void arrayStart() override;
|
||||||
|
virtual void containerEnd(JSON const& value) override;
|
||||||
|
virtual void topLevelScalar() override;
|
||||||
|
virtual bool
|
||||||
|
dictionaryItem(std::string const& key, JSON const& value) override;
|
||||||
|
virtual bool arrayItem(JSON const& value) override;
|
||||||
|
|
||||||
|
bool anyErrors() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum state_e {
|
||||||
|
st_initial,
|
||||||
|
st_top,
|
||||||
|
st_qpdf,
|
||||||
|
st_qpdf_meta,
|
||||||
|
st_objects,
|
||||||
|
st_trailer,
|
||||||
|
st_object_top,
|
||||||
|
st_stream,
|
||||||
|
st_object,
|
||||||
|
st_ignore,
|
||||||
|
};
|
||||||
|
|
||||||
|
void containerStart();
|
||||||
|
void nestedState(std::string const& key, JSON const& value, state_e);
|
||||||
|
void setObjectDescription(QPDFObjectHandle& oh, JSON const& value);
|
||||||
|
QPDFObjectHandle makeObject(JSON const& value);
|
||||||
|
void error(qpdf_offset_t offset, std::string const& message);
|
||||||
|
QPDFObjectHandle reserveObject(int obj, int gen);
|
||||||
|
void replaceObject(
|
||||||
|
QPDFObjectHandle to_replace,
|
||||||
|
QPDFObjectHandle replacement,
|
||||||
|
JSON const& value);
|
||||||
|
|
||||||
|
QPDF& pdf;
|
||||||
|
std::shared_ptr<InputSource> is;
|
||||||
|
bool must_be_complete;
|
||||||
|
std::shared_ptr<QPDFValue::Description> descr;
|
||||||
|
bool errors;
|
||||||
|
bool parse_error;
|
||||||
|
bool saw_qpdf;
|
||||||
|
bool saw_qpdf_meta;
|
||||||
|
bool saw_objects;
|
||||||
|
bool saw_json_version;
|
||||||
|
bool saw_pdf_version;
|
||||||
|
bool saw_trailer;
|
||||||
|
state_e state;
|
||||||
|
state_e next_state;
|
||||||
|
std::string cur_object;
|
||||||
|
bool saw_value;
|
||||||
|
bool saw_stream;
|
||||||
|
bool saw_dict;
|
||||||
|
bool saw_data;
|
||||||
|
bool saw_datafile;
|
||||||
|
bool this_stream_needs_data;
|
||||||
|
std::vector<state_e> state_stack;
|
||||||
|
std::vector<QPDFObjectHandle> object_stack;
|
||||||
|
std::set<QPDFObjGen> reserved;
|
||||||
|
};
|
||||||
|
|
||||||
QPDF::JSONReactor::JSONReactor(
|
QPDF::JSONReactor::JSONReactor(
|
||||||
QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) :
|
QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) :
|
||||||
pdf(pdf),
|
pdf(pdf),
|
||||||
is(is),
|
is(is),
|
||||||
must_be_complete(must_be_complete),
|
must_be_complete(must_be_complete),
|
||||||
descr(std::make_shared<std::variant<std::string, JSON_Descr>>(
|
descr(std::make_shared<QPDFValue::Description>(QPDFValue::JSON_Descr(
|
||||||
JSON_Descr(std::make_shared<std::string>(is->getName()), ""))),
|
std::make_shared<std::string>(is->getName()), ""))),
|
||||||
errors(false),
|
errors(false),
|
||||||
parse_error(false),
|
parse_error(false),
|
||||||
saw_qpdf(false),
|
saw_qpdf(false),
|
||||||
@ -679,10 +745,10 @@ QPDF::JSONReactor::arrayItem(JSON const& value)
|
|||||||
void
|
void
|
||||||
QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value)
|
QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value)
|
||||||
{
|
{
|
||||||
auto j_descr = std::get<JSON_Descr>(*descr);
|
auto j_descr = std::get<QPDFValue::JSON_Descr>(*descr);
|
||||||
if (j_descr.object != cur_object) {
|
if (j_descr.object != cur_object) {
|
||||||
descr = std::make_shared<QPDFValue::Description>(
|
descr = std::make_shared<QPDFValue::Description>(
|
||||||
JSON_Descr(j_descr.input, cur_object));
|
QPDFValue::JSON_Descr(j_descr.input, cur_object));
|
||||||
}
|
}
|
||||||
|
|
||||||
oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart());
|
oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart());
|
||||||
|
@ -14,18 +14,6 @@ class QPDF;
|
|||||||
class QPDFObjectHandle;
|
class QPDFObjectHandle;
|
||||||
class QPDFObject;
|
class QPDFObject;
|
||||||
|
|
||||||
struct JSON_Descr
|
|
||||||
{
|
|
||||||
JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) :
|
|
||||||
input(input),
|
|
||||||
object(object)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<std::string> input;
|
|
||||||
std::string object;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QPDFValue
|
class QPDFValue
|
||||||
{
|
{
|
||||||
friend class QPDFObject;
|
friend class QPDFObject;
|
||||||
@ -37,6 +25,19 @@ class QPDFValue
|
|||||||
virtual std::string unparse() = 0;
|
virtual std::string unparse() = 0;
|
||||||
virtual JSON getJSON(int json_version) = 0;
|
virtual JSON getJSON(int json_version) = 0;
|
||||||
|
|
||||||
|
struct JSON_Descr
|
||||||
|
{
|
||||||
|
JSON_Descr(
|
||||||
|
std::shared_ptr<std::string> input, std::string const& object) :
|
||||||
|
input(input),
|
||||||
|
object(object)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<std::string> input;
|
||||||
|
std::string object;
|
||||||
|
};
|
||||||
|
|
||||||
using Description = std::variant<std::string, JSON_Descr>;
|
using Description = std::variant<std::string, JSON_Descr>;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
|
Loading…
Reference in New Issue
Block a user