parser_context.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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> class ReferenceManager;
  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. ReferenceManager<A> & ref;
  14. std::optional<Object> parent = std::nullopt;
  15. Reference where = {};
  16. Reference dynamic_where = {};
  17. ParserContext rebind(A const & new_schema, Reference const & new_loc, Reference const & new_dyn,
  18. std::optional<Object> parent = std::nullopt) const {
  19. return {root, new_schema, version, factory, ref, parent, new_loc, new_dyn};
  20. }
  21. ParserContext child(A const & child, std::string const & key) const {
  22. return rebind(child, where / key, dynamic_where / key, schema.as_object());
  23. }
  24. ParserContext child(A const & child, size_t index) const {
  25. return rebind(child, where / index, dynamic_where / index);
  26. }
  27. ParserContext neighbor(std::string const & key) const {
  28. return rebind((*parent)[key], where.parent() / key, dynamic_where.parent() / key, parent);
  29. }
  30. schema::Node const * node() const;
  31. schema::Node const * always() const;
  32. schema::Node const * fixed_schema(bool accept) const;
  33. };
  34. }