Merge branch 'jhjensen-constraint_builder' into add-constraint-builder

This commit is contained in:
Tristan Penman 2016-04-08 07:33:02 +10:00
commit 3a67760e4b
4 changed files with 27 additions and 4 deletions

View File

@ -360,17 +360,17 @@ public:
return false;
}
bool getBool(bool &result) const
bool getBool(bool &) const
{
return false;
}
bool getDouble(double &result) const
bool getDouble(double &) const
{
return false;
}
bool getInteger(int64_t &result) const
bool getInteger(int64_t &) const
{
return false;
}

View File

@ -812,7 +812,7 @@ public:
const std::vector<std::string>& context,
valijson::ValidationResults *results) const = 0;
protected:
private:
virtual Constraint * cloneInto(void *) const = 0;
virtual size_t sizeOf() const = 0;

View File

@ -4,6 +4,8 @@
#include <stdexcept>
#include <iostream>
#include <vector>
#include <memory>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
@ -24,6 +26,12 @@
namespace valijson {
class ConstraintBuilder {
public:
virtual ~ConstraintBuilder() {}
virtual std::unique_ptr<constraints::Constraint> make(adapters::Adapter &node) = 0;
};
/**
* @brief Parser for populating a Schema based on a JSON Schema document.
*
@ -37,6 +45,10 @@ class SchemaParser
{
public:
void addConstraintBuilder(const std::string &key, ConstraintBuilder &builder) {
regConstraints.emplace_back(key, &builder);
}
/// Supported versions of JSON Schema
enum Version {
kDraft3, ///< @deprecated JSON Schema v3 has been superseded by v4
@ -509,6 +521,9 @@ private:
schemaCache, schemaCacheKeysToCreate);
}
std::vector<std::pair<std::string, ConstraintBuilder *>> regConstraints;
/**
* @brief Populate a Schema object from JSON Schema document
*
@ -770,6 +785,13 @@ private:
makePatternConstraint(itr->second), &subschema);
}
for (auto &builder : regConstraints) {
if ((itr = object.find(builder.first)) != object.end()) {
auto pcons = builder.second->make(itr->second);
rootSchema.addConstraintToSubschema(*pcons, &subschema);
}
}
{
// Check for schema keywords that require the creation of a
// PropertiesConstraint instance.

View File

@ -19,6 +19,7 @@ class ValidationResults
{
public:
virtual ~ValidationResults() {}
/**
* @brief Describes a validation error.
*