Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
output_trace.h
1#ifndef SOURCEMETA_BLAZE_OUTPUT_TRACE_H_
2#define SOURCEMETA_BLAZE_OUTPUT_TRACE_H_
3
4#ifndef SOURCEMETA_BLAZE_OUTPUT_EXPORT
5#include <sourcemeta/blaze/output_export.h>
6#endif
7
8#include <sourcemeta/blaze/evaluator.h>
9#include <sourcemeta/core/jsonschema.h>
10
11#include <sourcemeta/core/json.h>
12#include <sourcemeta/core/jsonpointer.h>
13
14#include <cstdint> // std::uint8_t
15#include <functional> // std::function, std::reference_wrapper
16#include <optional> // std::optional, std::nullopt
17#include <string_view> // std::string_view
18#include <utility> // std::pair
19
20namespace sourcemeta::blaze {
21
59class SOURCEMETA_BLAZE_OUTPUT_EXPORT TraceOutput {
60public:
62 enum class EntryType : std::uint8_t { Push, Pass, Fail, Annotation };
63
64 // NOLINTNEXTLINE(bugprone-exception-escape)
65 struct Entry {
66 // NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
67 const EntryType type;
68 const std::string_view name;
71 const sourcemeta::core::WeakPointer &instance_location;
72 const sourcemeta::core::WeakPointer &evaluate_path;
73 const std::string_view keyword_location;
74 const sourcemeta::core::JSON &annotation;
76 const std::optional<std::string_view> vocabulary;
77 // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members)
78 };
79
80 // TODO(C++23): Use std::move_only_function when available in libc++
81 using Callback = std::function<void(const Entry &)>;
82
83 TraceOutput(const Template &schema_template, Callback callback,
84 sourcemeta::core::WeakPointer base =
85 sourcemeta::core::EMPTY_WEAK_POINTER);
86
87 // Prevent accidental copies
88 TraceOutput(const TraceOutput &) = delete;
89 auto operator=(const TraceOutput &) -> TraceOutput & = delete;
90
91 auto operator()(const EvaluationType type, const bool result,
92 const Instruction &step,
93 const InstructionExtra &step_metadata,
94 const sourcemeta::core::WeakPointer &evaluate_path,
95 const sourcemeta::core::WeakPointer &instance_location,
96 const sourcemeta::core::JSON &annotation) -> void;
97
98private:
99// Exporting symbols that depends on the standard C++ library is considered
100// safe.
101// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
102#if defined(_MSC_VER)
103#pragma warning(disable : 4251)
104#endif
105 const Template &schema_template_;
106 const sourcemeta::core::WeakPointer base_;
107 Callback callback_;
108#if defined(_MSC_VER)
109#pragma warning(default : 4251)
110#endif
111};
112
113} // namespace sourcemeta::blaze
114
115#endif
EvaluationType
Definition evaluator.h:60
Definition evaluator_instruction.h:303
Definition evaluator_instruction.h:286
Definition evaluator.h:38
EntryType
The kind of entry being reported. Annotations are always valid.
Definition output_trace.h:62
Definition output_trace.h:65
const std::optional< std::string_view > vocabulary
The vocabulary that owns the keyword, when it has one.
Definition output_trace.h:76
const Instruction & step
The instruction that produced this entry.
Definition output_trace.h:70