parser_context.h 987 B

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