Skip to content

Commit

Permalink
Get rid of std::future everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Oct 13, 2024
1 parent 80035b1 commit 99f378c
Show file tree
Hide file tree
Showing 58 changed files with 648 additions and 1,131 deletions.
9 changes: 3 additions & 6 deletions src/jsonschema/anchor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ namespace sourcemeta::jsontoolkit {

auto anchors(const JSON &schema, const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect)
-> std::future<std::map<std::string, AnchorType>> {
-> std::map<std::string, AnchorType> {
const std::map<std::string, bool> vocabularies{
sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect)
.get()};
std::promise<std::map<std::string, AnchorType>> promise;
promise.set_value(anchors(schema, vocabularies));
return promise.get_future();
sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect)};
return anchors(schema, vocabularies);
}

auto anchors(const JSON &schema,
Expand Down
9 changes: 3 additions & 6 deletions src/jsonschema/bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ auto bundle_schema(sourcemeta::jsontoolkit::JSON &root,
const std::optional<std::string> &default_dialect) -> void {
sourcemeta::jsontoolkit::ReferenceMap references;
sourcemeta::jsontoolkit::frame(subschema, frame, references, walker, resolver,
default_dialect)
.wait();
default_dialect);

for (const auto &[key, reference] : references) {
if (frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static,
Expand Down Expand Up @@ -138,8 +137,7 @@ auto remove_identifiers(sourcemeta::jsontoolkit::JSON &schema,
sourcemeta::jsontoolkit::ReferenceFrame frame;
sourcemeta::jsontoolkit::ReferenceMap references;
sourcemeta::jsontoolkit::frame(schema, frame, references, walker, resolver,
default_dialect)
.wait();
default_dialect);

// (2) Remove all identifiers and anchors
for (const auto &entry : sourcemeta::jsontoolkit::SchemaIterator{
Expand Down Expand Up @@ -199,8 +197,7 @@ auto bundle(sourcemeta::jsontoolkit::JSON &schema, const SchemaWalker &walker,
const SchemaResolver &resolver, const BundleOptions options,
const std::optional<std::string> &default_dialect) -> void {
const auto vocabularies{
sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect)
.get()};
sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect)};
sourcemeta::jsontoolkit::ReferenceFrame frame;
bundle_schema(schema, definitions_keyword(vocabularies), schema, frame,
walker, resolver, default_dialect);
Expand Down
11 changes: 4 additions & 7 deletions src/jsonschema/compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ auto compile(const JSON &schema, const SchemaWalker &walker,
ReferenceFrame frame;
ReferenceMap references;
sourcemeta::jsontoolkit::frame(result, frame, references, walker, resolver,
default_dialect)
.wait();
default_dialect);

const std::string base{
URI{sourcemeta::jsontoolkit::identify(
schema, resolver,
sourcemeta::jsontoolkit::IdentificationStrategy::Strict,
default_dialect)
.get()
.value_or("")}
.canonicalize()
.recompose()};
Expand All @@ -107,7 +105,7 @@ auto compile(const JSON &schema, const SchemaWalker &walker,
sourcemeta::jsontoolkit::SchemaCompilerSchemaContext schema_context{
empty_pointer,
result,
vocabularies(schema, resolver, root_frame_entry.dialect).get(),
vocabularies(schema, resolver, root_frame_entry.dialect),
root_frame_entry.base,
{},
{}};
Expand Down Expand Up @@ -187,7 +185,7 @@ auto compile(const JSON &schema, const SchemaWalker &walker,
// schema resource that we are precompiling
auto subschema{get(result, entry.second.pointer)};
auto nested_vocabularies{
vocabularies(subschema, resolver, entry.second.dialect).get()};
vocabularies(subschema, resolver, entry.second.dialect)};
const sourcemeta::jsontoolkit::SchemaCompilerSchemaContext
nested_schema_context{entry.second.relative_pointer,
std::move(subschema),
Expand Down Expand Up @@ -256,8 +254,7 @@ auto compile(const SchemaCompilerContext &context,
return compile_subschema(
context,
{entry.relative_pointer, new_schema,
vocabularies(new_schema, context.resolver, entry.dialect).get(),
entry.base,
vocabularies(new_schema, context.resolver, entry.dialect), entry.base,
// TODO: This represents a copy
schema_context.labels, schema_context.references},
{dynamic_context.keyword, destination_pointer,
Expand Down
19 changes: 9 additions & 10 deletions src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <sourcemeta/jsontoolkit/jsonschema_resolver.h>
#include <sourcemeta/jsontoolkit/jsonschema_walker.h>

#include <future> // std::future
#include <map> // std::map
#include <optional> // std::optional
#include <string> // std::string
Expand Down Expand Up @@ -71,7 +70,7 @@ enum class IdentificationStrategy : std::uint8_t {
/// })JSON");
///
/// std::optional<std::string> id{sourcemeta::jsontoolkit::identify(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
/// assert(id.has_value());
/// assert(id.value() == "https://sourcemeta.com/example-schema");
/// ```
Expand All @@ -85,7 +84,7 @@ auto identify(
const IdentificationStrategy strategy = IdentificationStrategy::Strict,
const std::optional<std::string> &default_dialect = std::nullopt,
const std::optional<std::string> &default_id = std::nullopt)
-> std::future<std::optional<std::string>>;
-> std::optional<std::string>;

/// @ingroup jsonschema
///
Expand Down Expand Up @@ -118,7 +117,7 @@ auto identify(const JSON &schema, const std::string &base_dialect,
/// "https://json-schema.org/draft/2020-12/schema");
///
/// std::optional<std::string> id{sourcemeta::jsontoolkit::identify(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
/// assert(!id.has_value());
/// ```
SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
Expand All @@ -145,7 +144,7 @@ auto anonymize(JSON &schema, const std::string &base_dialect) -> void;
/// sourcemeta::jsontoolkit::official_resolver);
///
/// std::optional<std::string> id{sourcemeta::jsontoolkit::identify(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
/// assert(id.has_value());
/// assert(id.value() == "https://example.com/my-new-id");
/// ```
Expand Down Expand Up @@ -239,7 +238,7 @@ auto metaschema(
///
/// const std::optional<std::string> base_dialect{
/// sourcemeta::jsontoolkit::base_dialect(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
///
/// assert(base_dialect.has_value());
/// assert(base_dialect.value() ==
Expand All @@ -248,7 +247,7 @@ auto metaschema(
SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto base_dialect(const JSON &schema, const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect =
std::nullopt) -> std::future<std::optional<std::string>>;
std::nullopt) -> std::optional<std::string>;

/// @ingroup jsonschema
///
Expand All @@ -272,7 +271,7 @@ auto base_dialect(const JSON &schema, const SchemaResolver &resolver,
///
/// const std::map<std::string, bool> vocabularies{
/// sourcemeta::jsontoolkit::vocabularies(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
///
/// assert(vocabularies.at("https://json-schema.org/draft/2020-12/vocab/core"));
/// assert(vocabularies.at("https://json-schema.org/draft/2020-12/vocab/applicator"));
Expand All @@ -285,7 +284,7 @@ auto base_dialect(const JSON &schema, const SchemaResolver &resolver,
SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto vocabularies(const JSON &schema, const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect =
std::nullopt) -> std::future<std::map<std::string, bool>>;
std::nullopt) -> std::map<std::string, bool>;

/// @ingroup jsonschema
///
Expand All @@ -294,7 +293,7 @@ auto vocabularies(const JSON &schema, const SchemaResolver &resolver,
SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto vocabularies(const SchemaResolver &resolver,
const std::string &base_dialect, const std::string &dialect)
-> std::future<std::map<std::string, bool>>;
-> std::map<std::string, bool>;

/// @ingroup jsonschema
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <sourcemeta/jsontoolkit/jsonschema_resolver.h>

#include <cstdint> // std::uint8_t
#include <future> // std::promise, std::future
#include <map> // std::map
#include <optional> // std::optional
#include <string> // std::string
Expand Down Expand Up @@ -38,7 +37,7 @@ enum class AnchorType : std::uint8_t { Static, Dynamic, All };
/// })JSON");
///
/// const auto anchors{sourcemeta::jsontoolkit::anchors(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
/// assert(anchors.size() == 1);
/// assert(anchors.contains("foo"));
/// // This is a static anchor
Expand All @@ -47,7 +46,7 @@ enum class AnchorType : std::uint8_t { Static, Dynamic, All };
SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto anchors(const JSON &schema, const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect = std::nullopt)
-> std::future<std::map<std::string, AnchorType>>;
-> std::map<std::string, AnchorType>;

/// @ingroup jsonschema
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <sourcemeta/jsontoolkit/jsonschema_walker.h>

#include <cstdint> // std::uint8_t
#include <future> // std::future
#include <optional> // std::optional, std::nullopt
#include <string> // std::string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <sourcemeta/jsontoolkit/jsonschema_walker.h>

#include <cstdint> // std::uint8_t
#include <future> // std::future
#include <map> // std::map
#include <optional> // std::optional
#include <string> // std::string
Expand Down Expand Up @@ -102,11 +101,9 @@ using ReferenceMap =
///
/// sourcemeta::jsontoolkit::ReferenceFrame frame;
/// sourcemeta::jsontoolkit::ReferenceMap references;
/// sourcemeta::jsontoolkit::frame(document, frame,
/// references,
/// sourcemeta::jsontoolkit::frame(document, frame, references,
/// sourcemeta::jsontoolkit::default_schema_walker,
/// sourcemeta::jsontoolkit::official_resolver)
/// .wait();
/// sourcemeta::jsontoolkit::official_resolver);
///
/// // IDs
/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static,
Expand Down Expand Up @@ -159,8 +156,7 @@ SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT
auto frame(const JSON &schema, ReferenceFrame &frame, ReferenceMap &references,
const SchemaWalker &walker, const SchemaResolver &resolver,
const std::optional<std::string> &default_dialect = std::nullopt,
const std::optional<std::string> &default_id = std::nullopt)
-> std::future<void>;
const std::optional<std::string> &default_id = std::nullopt) -> void;

} // namespace sourcemeta::jsontoolkit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT SchemaIteratorFlat {
///
/// const auto vocabularies{
/// sourcemeta::jsontoolkit::vocabularies(
/// document, sourcemeta::jsontoolkit::official_resolver).get()};
/// document, sourcemeta::jsontoolkit::official_resolver)};
///
/// assert(sourcemeta::jsontoolkit::keyword_priority(
/// "prefixItems", vocabularies,
Expand Down
Loading

0 comments on commit 99f378c

Please sign in to comment.