Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions src/foundation/foundation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

#include "helpers.h"

#include <algorithm> // std::max, std::ranges::fold_left
#include <cassert> // assert
#include <cstdint> // std::uint64_t
#include <limits> // std::numeric_limits
#include <sstream> // std::ostringstream
#include <string_view> // std::string_view
#include <type_traits> // std::remove_reference_t
#include <unordered_map> // std::unordered_map
#include <unordered_set> // std::unordered_set
#include <utility> // std::move, std::to_underlying

Expand Down Expand Up @@ -802,30 +797,6 @@ auto sourcemeta::blaze::vocabularies(const SchemaResolver &resolver,
return result;
}

auto sourcemeta::blaze::schema_keyword_priority(
std::string_view keyword,
const sourcemeta::blaze::Vocabularies &vocabularies,
const sourcemeta::blaze::SchemaWalker &walker) -> std::uint64_t {
const auto &result{walker(keyword, vocabularies)};
const auto priority_from_dependencies{std::ranges::fold_left(
result.dependencies, static_cast<std::uint64_t>(0),
[&vocabularies, &walker](const auto accumulator,
const auto &dependency) -> std::uint64_t {
return std::max(
accumulator,
schema_keyword_priority(dependency, vocabularies, walker) + 1);
})};
const auto priority_from_order_dependencies{std::ranges::fold_left(
result.order_dependencies, static_cast<std::uint64_t>(0),
[&vocabularies, &walker](const auto accumulator,
const auto &dependency) -> std::uint64_t {
return std::max(
accumulator,
schema_keyword_priority(dependency, vocabularies, walker) + 1);
})};
return std::max(priority_from_dependencies, priority_from_order_dependencies);
}

static auto parse_schema_type_string(const sourcemeta::core::JSON::String &type,
sourcemeta::core::JSON::TypeSet &result)
-> void {
Expand Down
44 changes: 0 additions & 44 deletions src/foundation/include/sourcemeta/blaze/foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
#include <sourcemeta/blaze/foundation_walker.h>
// NOLINTEND(misc-include-cleaner)

#include <cstdint> // std::uint8_t
#include <functional> // std::function
#include <optional> // std::optional, std::nullopt
#include <set> // std::set
#include <string> // std::string
#include <string_view> // std::string_view

/// @defgroup foundation Foundation
Expand Down Expand Up @@ -67,46 +63,6 @@ SOURCEMETA_BLAZE_FOUNDATION_EXPORT
auto to_base_dialect(const std::string_view base_dialect)
-> std::optional<SchemaBaseDialect>;

/// @ingroup foundation
///
/// Calculate the priority of a keyword that determines the ordering in which a
/// JSON Schema implementation should evaluate keyword on a subschema. It does
/// so based on the keyword dependencies expressed in the schema walker. The
/// higher the priority, the more the evaluation of such keyword must be
/// delayed.
///
/// For example:
///
/// ```cpp
/// #include <sourcemeta/core/json.h>
/// #include <sourcemeta/blaze/foundation.h>
/// #include <cassert>
///
/// const sourcemeta::core::JSON document =
/// sourcemeta::core::parse_json(R"JSON({
/// "$schema": "https://json-schema.org/draft/2020-12/schema",
/// "prefixItems": [ true, true ],
/// "items": false
/// })JSON");
///
/// const auto vocabularies{
/// sourcemeta::blaze::vocabularies(
/// document, sourcemeta::blaze::schema_resolver)};
///
/// assert(sourcemeta::blaze::schema_keyword_priority(
/// "prefixItems", vocabularies,
/// sourcemeta::blaze::schema_walker) == 0);
///
/// // The "items" keyword must be evaluated after the "prefixItems" keyword
/// assert(sourcemeta::blaze::schema_keyword_priority(
/// "items", vocabularies,
/// sourcemeta::blaze::schema_walker) == 1);
/// ```
SOURCEMETA_BLAZE_FOUNDATION_EXPORT
auto schema_keyword_priority(const std::string_view keyword,
const Vocabularies &vocabularies,
const SchemaWalker &walker) -> std::uint64_t;

/// @ingroup foundation
///
/// This function returns true if the given JSON instance is of a
Expand Down
20 changes: 0 additions & 20 deletions src/foundation/include/sourcemeta/blaze/foundation_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,6 @@ class SOURCEMETA_BLAZE_FOUNDATION_EXPORT SchemaReferenceObjectResourceError
std::string identifier_;
};

/// @ingroup foundation
/// An error that represents an unrecognized base dialect
class SOURCEMETA_BLAZE_FOUNDATION_EXPORT SchemaBaseDialectError
: public std::exception {
public:
SchemaBaseDialectError(const std::string_view base_dialect)
: base_dialect_{base_dialect} {}

[[nodiscard]] auto what() const noexcept -> const char * override {
return "Unrecognized base dialect";
}

[[nodiscard]] auto base_dialect() const noexcept -> std::string_view {
return this->base_dialect_;
}

private:
std::string base_dialect_;
};

/// @ingroup foundation
/// An error that represents a schema keyword error
class SOURCEMETA_BLAZE_FOUNDATION_EXPORT SchemaKeywordError
Expand Down
68 changes: 0 additions & 68 deletions src/foundation/include/sourcemeta/blaze/foundation_walker.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include <sourcemeta/blaze/foundation_types.h>

#include <cstdint> // std::uint64_t
#include <optional> // std::optional
#include <string_view> // std::string_view
#include <vector> // std::vector

Expand Down Expand Up @@ -81,72 +79,6 @@ class SOURCEMETA_BLAZE_FOUNDATION_EXPORT SchemaIterator {
#endif
};

/// @ingroup foundation
///
/// Return an iterator over the subschemas of a given JSON Schema definition
/// according to the applicators understood by the provided walker function.
/// This walker traverse over the first-level of subschemas of the JSON Schema
/// definition, ignoring the top-level schema and reporting back each subschema.
///
/// Note that we don't promise any specific walking ordering.
///
/// For example:
///
/// ```cpp
/// #include <sourcemeta/core/json.h>
/// #include <sourcemeta/blaze/foundation.h>
/// #include <iostream>
///
/// const sourcemeta::core::JSON document =
/// sourcemeta::core::parse_json(R"JSON({
/// "$schema": "https://json-schema.org/draft/2020-12/schema",
/// "type": "object",
/// "properties": {
/// "foo": {
/// "type": "array",
/// "items": {
/// "type": "string"
/// }
/// }
/// }
/// })JSON");
///
/// for (const auto &entry :
/// sourcemeta::blaze::SchemaIteratorFlat{
/// document, sourcemeta::blaze::schema_walker,
/// sourcemeta::blaze::schema_resolver}) {
/// sourcemeta::core::prettify(
/// sourcemeta::core::get(document, entry.pointer), std::cout);
/// std::cout << "\n";
/// }
/// ```
class SOURCEMETA_BLAZE_FOUNDATION_EXPORT SchemaIteratorFlat {
private:
using internal = typename std::vector<SchemaIteratorEntry>;

public:
using const_iterator = typename internal::const_iterator;
SchemaIteratorFlat(const sourcemeta::core::JSON &input,
const SchemaWalker &walker, const SchemaResolver &resolver,
std::string_view default_dialect = "");
[[nodiscard]] auto begin() const -> const_iterator;
[[nodiscard]] auto end() const -> const_iterator;
[[nodiscard]] auto cbegin() const -> const_iterator;
[[nodiscard]] auto cend() const -> const_iterator;

private:
// Exporting symbols that depends on the standard C++ library is considered
// safe.
// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
#if defined(_MSC_VER)
#pragma warning(disable : 4251)
#endif
internal subschemas{};
#if defined(_MSC_VER)
#pragma warning(default : 4251)
#endif
};

/// @ingroup foundation
///
/// Return an iterator over the top-level keywords of a given JSON Schema
Expand Down
Loading
Loading