|
|
@@ -157,6 +157,10 @@ private:
|
|
|
public:
|
|
|
ConstraintFactory() = default;
|
|
|
|
|
|
+ static pConstraint ptr(auto && in) {
|
|
|
+ return std::make_unique<constraint::Constraint>(std::move(in));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @brief Construct a new ConstraintFactory, with a pre-defined list of user
|
|
|
* keywords to be injected into the vocabulary. Does not override any keywords
|
|
|
@@ -249,7 +253,7 @@ public:
|
|
|
|
|
|
adapter::Type const type = context.schema.type();
|
|
|
if (type == adapter::Type::String) {
|
|
|
- return std::make_unique<constraint::TypeConstraint>(to_type(context.schema.as_string()));
|
|
|
+ return ptr(constraint::TypeConstraint{{to_type(context.schema.as_string())}});
|
|
|
}
|
|
|
|
|
|
EXPECT(type == adapter::Type::Array);
|
|
|
@@ -257,7 +261,7 @@ public:
|
|
|
for (auto subschema : context.schema.as_array()) {
|
|
|
types.insert(to_type(subschema.as_string()));
|
|
|
}
|
|
|
- return std::make_unique<constraint::TypeConstraint>(types);
|
|
|
+ return ptr(constraint::TypeConstraint{types});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -305,11 +309,11 @@ public:
|
|
|
if (context.schema.as_string() == "any") {
|
|
|
return nullptr; // nullptr is a synonym for "always accept"
|
|
|
}
|
|
|
- return std::make_unique<constraint::TypeConstraint>(to_type(context.schema.as_string()));
|
|
|
+ return ptr(constraint::TypeConstraint{{to_type(context.schema.as_string())}});
|
|
|
}
|
|
|
|
|
|
EXPECT(type == adapter::Type::Array);
|
|
|
- std::vector<schema::Node const *> children;
|
|
|
+ std::vector<constraint::SubConstraint> children;
|
|
|
|
|
|
std::set<adapter::Type> types;
|
|
|
for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
@@ -322,9 +326,8 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto rval = std::make_unique<constraint::AnyOfConstraint>(children);
|
|
|
- rval->children.push_back(std::make_unique<constraint::TypeConstraint>(types));
|
|
|
- return rval;
|
|
|
+ children.push_back(ptr(constraint::TypeConstraint{types}));
|
|
|
+ return ptr(constraint::AnyOfConstraint{std::move(children)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -344,7 +347,7 @@ public:
|
|
|
* @throws {@see ConstraintFactory::typeDraft3}
|
|
|
*/
|
|
|
static pConstraint disallowDraft3(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::NotConstraint>(typeDraft3(context));
|
|
|
+ return ptr(constraint::NotConstraint{typeDraft3(context)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -371,7 +374,7 @@ public:
|
|
|
* @throws any std::exception if precondition #2 is broken
|
|
|
*/
|
|
|
static pConstraint extendsDraft3(detail::ParserContext<A> const & context) {
|
|
|
- std::vector<schema::Node const *> children;
|
|
|
+ std::vector<constraint::SubConstraint> children;
|
|
|
switch (context.schema.type()) {
|
|
|
case adapter::Type::Object:
|
|
|
children.push_back(context.node());
|
|
|
@@ -386,7 +389,7 @@ public:
|
|
|
JVALIDATE_THROW(std::runtime_error, "extends must be a schema of array-of-schemas");
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::AllOfConstraint>(children);
|
|
|
+ return ptr(constraint::AllOfConstraint{std::move(children)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -415,7 +418,7 @@ public:
|
|
|
else_ = context.neighbor("else").node();
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::ConditionalConstraint>(context.node(), then_, else_);
|
|
|
+ return ptr(constraint::ConditionalConstraint{context.node(), then_, else_});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -435,7 +438,7 @@ public:
|
|
|
rval.push_back(subschema.freeze());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::EnumConstraint>(std::move(rval));
|
|
|
+ return ptr(constraint::EnumConstraint{std::move(rval)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -448,7 +451,9 @@ public:
|
|
|
* @returns A constraint that checks equality against a single value.
|
|
|
*/
|
|
|
static auto isConstant(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::EnumConstraint>(context.schema.freeze());
|
|
|
+ constraint::EnumConstraint rval;
|
|
|
+ rval.enumeration.push_back(context.schema.freeze());
|
|
|
+ return ptr(rval);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -466,12 +471,12 @@ public:
|
|
|
static auto allOf(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
|
|
|
|
- std::vector<schema::Node const *> rval;
|
|
|
+ std::vector<constraint::SubConstraint> rval;
|
|
|
for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::AllOfConstraint>(rval);
|
|
|
+ return ptr(constraint::AllOfConstraint{std::move(rval)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -489,12 +494,12 @@ public:
|
|
|
static auto anyOf(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
|
|
|
|
- std::vector<schema::Node const *> rval;
|
|
|
+ std::vector<constraint::SubConstraint> rval;
|
|
|
for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::AnyOfConstraint>(rval);
|
|
|
+ return ptr(constraint::AnyOfConstraint{std::move(rval)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -517,7 +522,7 @@ public:
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::OneOfConstraint>(rval);
|
|
|
+ return ptr(constraint::OneOfConstraint{rval});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -529,7 +534,7 @@ public:
|
|
|
* @returns A NotConstraint
|
|
|
*/
|
|
|
static auto isNot(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::NotConstraint>(context.node());
|
|
|
+ return ptr(constraint::NotConstraint{context.node()});
|
|
|
}
|
|
|
|
|
|
// SECTION: Numeric Constraints
|
|
|
@@ -556,9 +561,9 @@ public:
|
|
|
context.parent->contains("exclusiveMinimum")) {
|
|
|
auto exclusive = (*context.parent)["exclusiveMinimum"];
|
|
|
EXPECT(exclusive.type() == adapter::Type::Boolean);
|
|
|
- return std::make_unique<constraint::MinimumConstraint>(value, exclusive.as_boolean());
|
|
|
+ return ptr(constraint::MinimumConstraint{value, exclusive.as_boolean()});
|
|
|
}
|
|
|
- return std::make_unique<constraint::MinimumConstraint>(value, false);
|
|
|
+ return ptr(constraint::MinimumConstraint{value, false});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -574,7 +579,7 @@ public:
|
|
|
*/
|
|
|
static pConstraint exclusiveMinimum(detail::ParserContext<A> const & context) {
|
|
|
double value = context.schema.as_number();
|
|
|
- return std::make_unique<constraint::MinimumConstraint>(value, true);
|
|
|
+ return ptr(constraint::MinimumConstraint{value, true});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -599,9 +604,9 @@ public:
|
|
|
context.parent->contains("exclusiveMaximum")) {
|
|
|
auto exclusive = (*context.parent)["exclusiveMaximum"];
|
|
|
EXPECT(exclusive.type() == adapter::Type::Boolean);
|
|
|
- return std::make_unique<constraint::MaximumConstraint>(value, exclusive.as_boolean());
|
|
|
+ return ptr(constraint::MaximumConstraint{value, exclusive.as_boolean()});
|
|
|
}
|
|
|
- return std::make_unique<constraint::MaximumConstraint>(value, false);
|
|
|
+ return ptr(constraint::MaximumConstraint{value, false});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -617,7 +622,7 @@ public:
|
|
|
*/
|
|
|
static pConstraint exclusiveMaximum(detail::ParserContext<A> const & context) {
|
|
|
double value = context.schema.as_number();
|
|
|
- return std::make_unique<constraint::MaximumConstraint>(value, true);
|
|
|
+ return ptr(constraint::MaximumConstraint{value, true});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -639,7 +644,7 @@ public:
|
|
|
*/
|
|
|
static auto multipleOf(detail::ParserContext<A> const & context) {
|
|
|
double value = context.schema.as_number();
|
|
|
- return std::make_unique<constraint::MultipleOfConstraint>(value);
|
|
|
+ return ptr(constraint::MultipleOfConstraint{value});
|
|
|
}
|
|
|
|
|
|
// SECTION: String Constraints
|
|
|
@@ -661,7 +666,7 @@ public:
|
|
|
static auto minLength(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Integer ||
|
|
|
context.schema.type() == adapter::Type::Number);
|
|
|
- return std::make_unique<constraint::MinLengthConstraint>(context.schema.as_integer());
|
|
|
+ return ptr(constraint::MinLengthConstraint{context.schema.as_integer()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -681,7 +686,7 @@ public:
|
|
|
static auto maxLength(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Integer ||
|
|
|
context.schema.type() == adapter::Type::Number);
|
|
|
- return std::make_unique<constraint::MaxLengthConstraint>(context.schema.as_integer());
|
|
|
+ return ptr(constraint::MaxLengthConstraint{context.schema.as_integer()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -702,7 +707,7 @@ public:
|
|
|
* @throws If the contained value is not interpretable as a string
|
|
|
*/
|
|
|
static auto pattern(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::PatternConstraint>(context.schema.as_string());
|
|
|
+ return ptr(constraint::PatternConstraint{context.schema.as_string()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -723,8 +728,8 @@ public:
|
|
|
* @throws If the contained value is not interpretable as a string
|
|
|
*/
|
|
|
static auto format(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::FormatConstraint>(context.schema.as_string(),
|
|
|
- context.vocab->is_format_assertion());
|
|
|
+ return ptr(constraint::FormatConstraint{context.schema.as_string(),
|
|
|
+ context.vocab->is_format_assertion()});
|
|
|
}
|
|
|
|
|
|
// SECTION: Array Constraints
|
|
|
@@ -752,7 +757,7 @@ public:
|
|
|
*/
|
|
|
static auto contains(detail::ParserContext<A> const & context) {
|
|
|
if (context.vocab->version() < schema::Version::Draft2019_09) {
|
|
|
- return std::make_unique<constraint::ContainsConstraint>(context.node());
|
|
|
+ return ptr(constraint::ContainsConstraint{context.node()});
|
|
|
}
|
|
|
|
|
|
std::optional<size_t> maximum;
|
|
|
@@ -764,7 +769,7 @@ public:
|
|
|
minimum = (*context.parent)["minContains"].as_integer();
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::ContainsConstraint>(context.node(), minimum, maximum);
|
|
|
+ return ptr(constraint::ContainsConstraint{context.node(), minimum, maximum});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -783,7 +788,7 @@ public:
|
|
|
static auto minItems(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Integer ||
|
|
|
context.schema.type() == adapter::Type::Number);
|
|
|
- return std::make_unique<constraint::MinItemsConstraint>(context.schema.as_integer());
|
|
|
+ return ptr(constraint::MinItemsConstraint{context.schema.as_integer()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -802,7 +807,7 @@ public:
|
|
|
static auto maxItems(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Integer ||
|
|
|
context.schema.type() == adapter::Type::Number);
|
|
|
- return std::make_unique<constraint::MaxItemsConstraint>(context.schema.as_integer());
|
|
|
+ return ptr(constraint::MaxItemsConstraint{context.schema.as_integer()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -829,7 +834,7 @@ public:
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::TupleConstraint>(rval);
|
|
|
+ return ptr(constraint::TupleConstraint{rval});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -869,10 +874,10 @@ public:
|
|
|
// "additionalProperties" keywords.
|
|
|
if (context.vocab->version() < schema::Version::Draft06 &&
|
|
|
context.schema.type() == adapter::Type::Boolean) {
|
|
|
- return std::make_unique<constraint::AdditionalItemsConstraint>(context.always(), n);
|
|
|
+ return ptr(constraint::AdditionalItemsConstraint{context.always(), n});
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::AdditionalItemsConstraint>(context.node(), n);
|
|
|
+ return ptr(constraint::AdditionalItemsConstraint{context.node(), n});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -900,7 +905,7 @@ public:
|
|
|
return prefixItems(context);
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::AdditionalItemsConstraint>(context.node(), 0);
|
|
|
+ return ptr(constraint::AdditionalItemsConstraint{context.node(), 0});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -917,7 +922,7 @@ public:
|
|
|
* @returns An AdditionalPropertiesConstraint
|
|
|
*/
|
|
|
static auto unevaluatedItems(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::UnevaluatedItemsConstraint>(context.node());
|
|
|
+ return ptr(constraint::UnevaluatedItemsConstraint{context.node()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -938,7 +943,7 @@ public:
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::UniqueItemsConstraint>();
|
|
|
+ return ptr(constraint::UniqueItemsConstraint{});
|
|
|
}
|
|
|
|
|
|
// SECTION: Object Constraints
|
|
|
@@ -967,7 +972,7 @@ public:
|
|
|
rval.insert(subschema.as_string());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::RequiredConstraint>(rval);
|
|
|
+ return ptr(constraint::RequiredConstraint{rval});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -986,7 +991,7 @@ public:
|
|
|
static auto minProperties(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Integer ||
|
|
|
context.schema.type() == adapter::Type::Number);
|
|
|
- return std::make_unique<constraint::MinPropertiesConstraint>(context.schema.as_integer());
|
|
|
+ return ptr(constraint::MinPropertiesConstraint{context.schema.as_integer()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1005,7 +1010,7 @@ public:
|
|
|
static auto maxProperties(detail::ParserContext<A> const & context) {
|
|
|
EXPECT(context.schema.type() == adapter::Type::Integer ||
|
|
|
context.schema.type() == adapter::Type::Number);
|
|
|
- return std::make_unique<constraint::MaxPropertiesConstraint>(context.schema.as_integer());
|
|
|
+ return ptr(constraint::MaxPropertiesConstraint{context.schema.as_integer()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1036,7 +1041,7 @@ public:
|
|
|
rval.emplace_back(prop, context.child(subschema, prop).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::PatternPropertiesConstraint>(rval);
|
|
|
+ return ptr(constraint::PatternPropertiesConstraint{rval});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1061,7 +1066,7 @@ public:
|
|
|
rval.emplace(prop, context.child(subschema, prop).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::PropertiesConstraint>(rval);
|
|
|
+ return ptr(constraint::PropertiesConstraint{rval});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1106,10 +1111,10 @@ public:
|
|
|
return properties(context);
|
|
|
}
|
|
|
|
|
|
- std::vector<pConstraint> rval;
|
|
|
+ std::vector<constraint::SubConstraint> rval;
|
|
|
rval.push_back(properties(context));
|
|
|
- rval.push_back(std::make_unique<constraint::RequiredConstraint>(std::move(required)));
|
|
|
- return std::make_unique<constraint::AllOfConstraint>(std::move(rval));
|
|
|
+ rval.push_back(ptr(constraint::RequiredConstraint{std::move(required)}));
|
|
|
+ return ptr(constraint::AllOfConstraint{std::move(rval)});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1122,7 +1127,7 @@ public:
|
|
|
* @returns A PropertyNamesConstraint
|
|
|
*/
|
|
|
static auto propertyNames(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::PropertyNamesConstraint>(context.node());
|
|
|
+ return ptr(constraint::PropertyNamesConstraint{context.node()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1139,7 +1144,7 @@ public:
|
|
|
* @returns An AdditionalPropertiesConstraint
|
|
|
*/
|
|
|
static auto unevaluatedProperties(detail::ParserContext<A> const & context) {
|
|
|
- return std::make_unique<constraint::UnevaluatedPropertiesConstraint>(context.node());
|
|
|
+ return ptr(constraint::UnevaluatedPropertiesConstraint{context.node()});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1177,10 +1182,10 @@ public:
|
|
|
// "additionalProperties" keywords.
|
|
|
if (context.vocab->version() < schema::Version::Draft06 &&
|
|
|
context.schema.type() == adapter::Type::Boolean) {
|
|
|
- return std::make_unique<C>(context.always(), properties, patterns);
|
|
|
+ return ptr(C{context.always(), properties, patterns});
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<C>(context.node(), properties, patterns);
|
|
|
+ return ptr(C{context.node(), properties, patterns});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1230,7 +1235,7 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::DependenciesConstraint>(schemas, required);
|
|
|
+ return ptr(constraint::DependenciesConstraint{schemas, required});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1261,7 +1266,7 @@ public:
|
|
|
rval.emplace(prop, context.child(subschema, prop).node());
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::DependenciesConstraint>(rval);
|
|
|
+ return ptr(constraint::DependenciesConstraint{rval});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1295,7 +1300,7 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<constraint::DependenciesConstraint>(rval);
|
|
|
+ return ptr(constraint::DependenciesConstraint{{}, rval});
|
|
|
}
|
|
|
};
|
|
|
}
|