parser_context.h 1.3 KB

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