parser_context.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <optional>
  3. #include <jvalidate/detail/reference.h>
  4. #include <jvalidate/forward.h>
  5. #include <jvalidate/reference_handler.h>
  6. namespace jvalidate::detail {
  7. template <Adapter A> struct ParserContext {
  8. using Object = decltype(std::declval<A>().as_object());
  9. Schema & root;
  10. A schema;
  11. schema::Version version;
  12. ConstraintFactory<A> const & factory;
  13. DocumentCache<A> & external;
  14. ReferenceManager<A> & ref;
  15. std::optional<Object> parent = std::nullopt;
  16. Reference where = {};
  17. ParserContext rebind(A const & new_schema, Reference const & new_loc,
  18. std::optional<Object> parent = std::nullopt) const {
  19. return {root, new_schema, version, factory, external, ref, parent, new_loc};
  20. }
  21. ParserContext child(A const & child, std::string const & key) const {
  22. return rebind(child, where / key, schema.as_object());
  23. }
  24. ParserContext child(A const & child, size_t index) const { return rebind(child, where / index); }
  25. ParserContext neighbor(std::string const & key) const {
  26. return rebind((*parent)[key], where.parent() / key, parent);
  27. }
  28. schema::Node const * node() const;
  29. schema::Node const * always() const;
  30. schema::Node const * fixed_schema(bool accept) const;
  31. };
  32. }