Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
 
Loading...
Searching...
No Matches
output_simple.h
1#ifndef SOURCEMETA_BLAZE_OUTPUT_SIMPLE_H_
2#define SOURCEMETA_BLAZE_OUTPUT_SIMPLE_H_
3
4#ifndef SOURCEMETA_BLAZE_OUTPUT_EXPORT
5#include <sourcemeta/blaze/output_export.h>
6#endif
7
8#include <sourcemeta/blaze/foundation.h>
9#include <sourcemeta/core/json.h>
10#include <sourcemeta/core/jsonpointer.h>
11
12#include <sourcemeta/blaze/evaluator.h>
13
14#include <functional> // std::reference_wrapper
15// TODO(C++23): Consider std::flat_map/std::flat_set when available in libc++
16#include <map> // std::map
17#include <ostream> // std::ostream
18#include <string> // std::string
19#include <tuple> // std::tie
20#include <utility> // std::pair
21#include <vector> // std::vector
22
23namespace sourcemeta::blaze {
24
69class SOURCEMETA_BLAZE_OUTPUT_EXPORT SimpleOutput {
70public:
71 SimpleOutput(const sourcemeta::core::JSON &instance,
72 sourcemeta::core::WeakPointer base =
73 sourcemeta::core::empty_weak_pointer);
74
75 // Prevent accidental copies
76 SimpleOutput(const SimpleOutput &) = delete;
77 auto operator=(const SimpleOutput &) -> SimpleOutput & = delete;
78
79 struct Entry {
80 std::string message;
81 sourcemeta::core::WeakPointer instance_location;
82 sourcemeta::core::WeakPointer evaluate_path;
83 std::reference_wrapper<const std::string> schema_location;
84 };
85
86 auto operator()(const EvaluationType type, const bool result,
87 const Instruction &step,
88 const InstructionExtra &step_metadata,
89 const sourcemeta::core::WeakPointer &evaluate_path,
90 const sourcemeta::core::WeakPointer &instance_location,
91 const sourcemeta::core::JSON &annotation) -> void;
92
93 using container_type = typename std::vector<Entry>;
94 using const_iterator = typename container_type::const_iterator;
95 [[nodiscard]] auto begin() const -> const_iterator;
96 [[nodiscard]] auto end() const -> const_iterator;
97 [[nodiscard]] auto cbegin() const -> const_iterator;
98 [[nodiscard]] auto cend() const -> const_iterator;
99
102 [[nodiscard]] auto annotations() const -> const auto & {
103 return this->annotations_;
104 }
105
106 // NOLINTNEXTLINE(bugprone-exception-escape)
107 struct Location {
108 auto operator<(const Location &other) const noexcept -> bool {
109 // Perform a lexicographical comparison
110 return std::tie(this->instance_location, this->evaluate_path,
111 this->schema_location.get()) <
112 std::tie(other.instance_location, other.evaluate_path,
113 other.schema_location.get());
114 }
115
116 // NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
117 const sourcemeta::core::WeakPointer instance_location;
118 const sourcemeta::core::WeakPointer evaluate_path;
119 const std::reference_wrapper<const std::string> schema_location;
120 // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members)
121 };
122
123private:
124// Exporting symbols that depends on the standard C++ library is considered
125// safe.
126// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
127#if defined(_MSC_VER)
128#pragma warning(disable : 4251)
129#endif
130 const sourcemeta::core::JSON &instance_;
131 const sourcemeta::core::WeakPointer base_;
132 container_type output;
133 std::vector<
134 std::pair<sourcemeta::core::WeakPointer, sourcemeta::core::WeakPointer>>
135 mask;
136 std::map<
137 std::pair<sourcemeta::core::WeakPointer, sourcemeta::core::WeakPointer>,
138 std::vector<Entry>>
139 masked_traces;
140 std::map<Location, std::vector<sourcemeta::core::JSON>> annotations_;
141#if defined(_MSC_VER)
142#pragma warning(default : 4251)
143#endif
144}; // namespace sourcemeta::blaze
145
146} // namespace sourcemeta::blaze
147
148#endif
EvaluationType
Definition evaluator.h:56
Definition evaluator_instruction.h:265
Definition evaluator_instruction.h:256
Definition output_simple.h:69
Definition output_simple.h:79
Definition output_simple.h:107