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/core/json.h>
9#include <sourcemeta/core/jsonpointer.h>
10#include <sourcemeta/core/jsonschema.h>
11
12#include <sourcemeta/blaze/evaluator.h>
13
14#include <cstddef> // std::size_t
15#include <cstdint> // std::uint8_t
16#include <functional> // std::reference_wrapper
17// TODO(C++23): Consider std::flat_map/std::flat_set when available in libc++
18#include <string> // std::string
19#include <utility> // std::move
20#include <vector> // std::vector
21
22namespace sourcemeta::blaze {
23
68class SOURCEMETA_BLAZE_OUTPUT_EXPORT SimpleOutput {
69public:
70 SimpleOutput(const Template &schema_template,
71 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
88 sourcemeta::core::WeakPointer instance_location;
89 sourcemeta::core::WeakPointer evaluate_path;
90 std::reference_wrapper<const std::string> schema_location;
91 sourcemeta::core::JSON value;
92 bool is_wrapped;
93 };
94
95 auto operator()(const EvaluationType type, const bool result,
96 const Instruction &step,
97 const InstructionExtra &step_metadata,
98 const sourcemeta::core::WeakPointer &evaluate_path,
99 const sourcemeta::core::WeakPointer &instance_location,
100 const sourcemeta::core::JSON &annotation) -> void;
101
102 using container_type = std::vector<Entry>;
103 using const_iterator = container_type::const_iterator;
104 [[nodiscard]] auto begin() const -> const_iterator;
105 [[nodiscard]] auto end() const -> const_iterator;
106 [[nodiscard]] auto cbegin() const -> const_iterator;
107 [[nodiscard]] auto cend() const -> const_iterator;
108
112 [[nodiscard]] auto release() && -> container_type {
113 auto result{std::move(this->output_)};
114 // A moved-from container is left in a valid but unspecified state, so
115 // clear it to honor the documented empty postcondition portably
116 this->output_.clear();
117 return result;
118 }
119
125 [[nodiscard]] auto annotations() const -> const auto & {
126 return this->annotations_;
127 }
128
129private:
130// Exporting symbols that depends on the standard C++ library is considered
131// safe.
132// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
133#if defined(_MSC_VER)
134#pragma warning(disable : 4251)
135#endif
138 enum class MaskKind : std::uint8_t { None, Disjunction, Element, Subschema };
139
141 static auto mask_kind(const Instruction &step) noexcept -> MaskKind;
142
147 auto destination(const sourcemeta::core::WeakPointer &evaluate_path)
148 -> container_type *;
149
152 struct MaskEntry {
153 sourcemeta::core::WeakPointer evaluate_path;
154 sourcemeta::core::WeakPointer instance_location;
155 MaskKind kind;
156 std::size_t annotations_mark;
157 std::vector<Entry> buffered_traces;
158 };
159
160 const Template &schema_template_;
161 const sourcemeta::core::JSON &instance_;
162 const sourcemeta::core::WeakPointer base_;
163 container_type output_;
164 std::vector<MaskEntry> mask_;
165 std::vector<AnnotationEntry> annotations_;
166#if defined(_MSC_VER)
167#pragma warning(default : 4251)
168#endif
169}; // namespace sourcemeta::blaze
170
171} // namespace sourcemeta::blaze
172
173#endif
EvaluationType
Definition evaluator.h:60
Definition evaluator_instruction.h:303
Definition evaluator_instruction.h:286
Definition evaluator.h:38
auto annotations() const -> const auto &
Definition output_simple.h:125
auto release() &&-> container_type
Definition output_simple.h:112
A single collected annotation, in evaluation order.
Definition output_simple.h:87
Definition output_simple.h:79