parser_context.h 881 B

1234567891011121314151617181920212223242526272829303132
  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. ParserContext child(A const & child, std::string const & key) const {
  14. return {root, child, schema.as_object(), version, where / key};
  15. }
  16. ParserContext child(A const & child, size_t index) const {
  17. return {root, child, std::nullopt, version, where / index};
  18. }
  19. ParserContext neighbor(std::string const & key) const {
  20. return {root, (*parent)[key], parent, version, where.parent() / key};
  21. }
  22. schema::Node const * resolve(std::string_view uri) const;
  23. schema::Node const * node() const;
  24. };
  25. }