mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-01 03:12:29 +00:00
Change JSON::Members::value to std::unique_ptr
This commit is contained in:
parent
a4f3dddb79
commit
7ae1e80fd6
@ -425,7 +425,7 @@ class JSON
|
|||||||
std::function<void(Pipeline*)> fn;
|
std::function<void(Pipeline*)> fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
JSON(std::shared_ptr<JSON_value>);
|
JSON(std::unique_ptr<JSON_value>);
|
||||||
|
|
||||||
static bool checkSchemaInternal(
|
static bool checkSchemaInternal(
|
||||||
JSON_value* this_v,
|
JSON_value* this_v,
|
||||||
@ -443,13 +443,13 @@ class JSON
|
|||||||
~Members() = default;
|
~Members() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Members(std::shared_ptr<JSON_value>);
|
Members(std::unique_ptr<JSON_value>);
|
||||||
Members(Members const&) = delete;
|
Members(Members const&) = delete;
|
||||||
|
|
||||||
std::shared_ptr<JSON_value> value;
|
std::unique_ptr<JSON_value> value;
|
||||||
// start and end are only populated for objects created by parse
|
// start and end are only populated for objects created by parse
|
||||||
qpdf_offset_t start;
|
qpdf_offset_t start{0};
|
||||||
qpdf_offset_t end;
|
qpdf_offset_t end{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<Members> m;
|
std::shared_ptr<Members> m;
|
||||||
|
@ -9,15 +9,13 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
JSON::Members::Members(std::shared_ptr<JSON_value> value) :
|
JSON::Members::Members(std::unique_ptr<JSON_value> value) :
|
||||||
value(value),
|
value(std::move(value))
|
||||||
start(0),
|
|
||||||
end(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON::JSON(std::shared_ptr<JSON_value> value) :
|
JSON::JSON(std::unique_ptr<JSON_value> value) :
|
||||||
m(new Members(value))
|
m(new Members(std::move(value)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +276,7 @@ JSON::encode_string(std::string const& str)
|
|||||||
JSON
|
JSON
|
||||||
JSON::makeDictionary()
|
JSON::makeDictionary()
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_dictionary>());
|
return JSON(std::make_unique<JSON_dictionary>());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
@ -286,7 +284,7 @@ JSON::addDictionaryMember(std::string const& key, JSON const& val)
|
|||||||
{
|
{
|
||||||
if (auto* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get())) {
|
if (auto* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get())) {
|
||||||
return obj->members[encode_string(key)] =
|
return obj->members[encode_string(key)] =
|
||||||
val.m->value ? val.m->value : std::make_shared<JSON_null>();
|
val.m->value ? val : makeNull();
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"JSON::addDictionaryMember called on non-dictionary");
|
"JSON::addDictionaryMember called on non-dictionary");
|
||||||
@ -311,7 +309,7 @@ JSON::checkDictionaryKeySeen(std::string const& key)
|
|||||||
JSON
|
JSON
|
||||||
JSON::makeArray()
|
JSON::makeArray()
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_array>());
|
return JSON(std::make_unique<JSON_array>());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
@ -332,43 +330,43 @@ JSON::addArrayElement(JSON const& val)
|
|||||||
JSON
|
JSON
|
||||||
JSON::makeString(std::string const& utf8)
|
JSON::makeString(std::string const& utf8)
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_string>(utf8));
|
return JSON(std::make_unique<JSON_string>(utf8));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
JSON::makeInt(long long int value)
|
JSON::makeInt(long long int value)
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_number>(value));
|
return JSON(std::make_unique<JSON_number>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
JSON::makeReal(double value)
|
JSON::makeReal(double value)
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_number>(value));
|
return JSON(std::make_unique<JSON_number>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
JSON::makeNumber(std::string const& encoded)
|
JSON::makeNumber(std::string const& encoded)
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_number>(encoded));
|
return JSON(std::make_unique<JSON_number>(encoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
JSON::makeBool(bool value)
|
JSON::makeBool(bool value)
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_bool>(value));
|
return JSON(std::make_unique<JSON_bool>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
JSON::makeNull()
|
JSON::makeNull()
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_null>());
|
return JSON(std::make_unique<JSON_null>());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON
|
JSON
|
||||||
JSON::makeBlob(std::function<void(Pipeline*)> fn)
|
JSON::makeBlob(std::function<void(Pipeline*)> fn)
|
||||||
{
|
{
|
||||||
return JSON(std::make_shared<JSON_blob>(fn));
|
return JSON(std::make_unique<JSON_blob>(fn));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Loading…
Reference in New Issue
Block a user