Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
evaluator_value.h
1#ifndef SOURCEMETA_BLAZE_EVALUATOR_VALUE_H
2#define SOURCEMETA_BLAZE_EVALUATOR_VALUE_H
3
4#include <sourcemeta/core/json.h>
5#include <sourcemeta/core/jsonpointer.h>
6#include <sourcemeta/core/regex.h>
7
8#include <cstdint> // std::uint8_t
9#include <optional> // std::optional
10#include <string> // std::string
11#include <tuple> // std::tuple
12#include <unordered_set> // std::unordered_set
13#include <utility> // std::pair
14#include <vector> // std::vector
15
16namespace sourcemeta::blaze {
17
20struct ValueNone {
21 [[nodiscard]] auto to_json() const -> sourcemeta::core::JSON {
22 return sourcemeta::core::JSON{nullptr};
23 }
24
25 static auto from_json(const sourcemeta::core::JSON &)
26 -> std::optional<ValueNone> {
27 return ValueNone{};
28 }
29};
30
33using ValueJSON = sourcemeta::core::JSON;
34
37using ValueSet =
38 std::unordered_set<sourcemeta::core::JSON,
39 sourcemeta::core::HashJSON<sourcemeta::core::JSON>>;
40
43using ValueString = sourcemeta::core::JSON::String;
44
48 std::pair<ValueString, sourcemeta::core::JSON::Object::hash_type>;
49
52using ValueStrings = std::vector<ValueString>;
53
56using ValueStringSet = sourcemeta::core::JSONPropertySet;
57
60using ValueTypes = sourcemeta::core::JSON::TypeSet;
61
64using ValueType = sourcemeta::core::JSON::Type;
65
71// NOLINTNEXTLINE(bugprone-exception-escape)
72struct ValueRegex {
73 using second_type = ValueString;
74 using first_type = sourcemeta::core::Regex;
75 first_type first;
76 second_type second;
77
78 [[nodiscard]] auto to_json() const -> sourcemeta::core::JSON {
79 return sourcemeta::core::to_json(this->second);
80 }
81
82 static auto from_json(const sourcemeta::core::JSON &value)
83 -> std::optional<ValueRegex> {
84 if (!value.is_string()) {
85 return std::nullopt;
86 }
87
88 auto string{value.to_string()};
89 auto regex{sourcemeta::core::to_regex(string)};
90 if (!regex.has_value()) {
91 return std::nullopt;
92 }
93
94 // NOLINTNEXTLINE(modernize-use-designated-initializers)
95 return ValueRegex{std::move(regex).value(), std::move(string)};
96 }
97};
98
101using ValueUnsignedInteger = std::size_t;
102
107using ValueRange = std::tuple<std::size_t, std::optional<std::size_t>, bool>;
108
111using ValueBoolean = bool;
112
115enum class ValueStringType : std::uint8_t {
116 URI,
117 URIReference,
118 URITemplate,
119 IRI,
120 IRIReference,
121 Email,
122 IDNEmail,
123 IPv4,
124 IPv6,
125 Hostname,
126 IDNHostname,
127 DateTime,
128 Date,
129 Time,
130 PartialTime,
131 Duration,
132 JSONPointer,
133 RelativeJSONPointer,
134 UUID,
135 Regex,
136 Color,
137 Base64
138};
139
142using ValueStringMap = sourcemeta::core::JSONObject<
144 sourcemeta::core::PropertyHashJSON<ValueString>>;
145
150 std::tuple<ValueStringSet, ValueStrings, std::vector<ValueRegex>>;
151
154using ValueIndexPair = std::pair<std::size_t, std::size_t>;
155
158using ValuePointer = sourcemeta::core::Pointer;
159
164using ValueNamedIndex = std::tuple<sourcemeta::core::JSON::Object::hash_type,
166
173 std::pair<std::vector<ValueNamedIndex>, std::vector<ValueIndexPair>>;
174
179 std::tuple<sourcemeta::core::JSON::Object::hash_type, ValueUnsignedInteger,
181
189 std::pair<std::pair<std::vector<ValueNamedIndexRequired>,
190 std::vector<ValueIndexPair>>,
192
195using ValueTypedProperties = std::pair<ValueType, ValueStringSet>;
196
200 std::pair<std::vector<std::pair<ValueStringSet::hash_type, ValueString>>,
201 std::vector<ValueIndexPair>>;
202
205using ValueTypedHashes = std::pair<ValueType, ValueStringHashes>;
206
209using ValueIntegerBounds = std::pair<std::int64_t, std::int64_t>;
210
213using ValueIntegerBoundsWithSize = std::pair<ValueIntegerBounds, ValueRange>;
214
217using ValueTypesWithSize = std::pair<ValueTypes, ValueRange>;
218
221using ValueObjectProperties = std::vector<
222 std::tuple<ValueString, sourcemeta::core::JSON::Object::hash_type, bool>>;
223
226enum class ValueNumberType : std::uint8_t { Float, Double };
227
229using Value = std::variant<
237
238} // namespace sourcemeta::blaze
239
240#endif
std::pair< std::vector< std::pair< ValueStringSet::hash_type, ValueString > >, std::vector< ValueIndexPair > > ValueStringHashes
Definition evaluator_value.h:199
sourcemeta::core::JSONObject< ValueString, ValueStringSet, sourcemeta::core::PropertyHashJSON< ValueString > > ValueStringMap
Definition evaluator_value.h:142
sourcemeta::core::JSON::Type ValueType
Definition evaluator_value.h:64
std::vector< ValueString > ValueStrings
Definition evaluator_value.h:52
sourcemeta::core::JSON::String ValueString
Definition evaluator_value.h:43
std::pair< ValueTypes, ValueRange > ValueTypesWithSize
Definition evaluator_value.h:217
sourcemeta::core::JSONPropertySet ValueStringSet
Definition evaluator_value.h:56
sourcemeta::core::Pointer ValuePointer
Definition evaluator_value.h:158
std::tuple< ValueStringSet, ValueStrings, std::vector< ValueRegex > > ValuePropertyFilter
Definition evaluator_value.h:149
sourcemeta::core::JSON ValueJSON
Definition evaluator_value.h:33
std::tuple< sourcemeta::core::JSON::Object::hash_type, ValueUnsignedInteger, ValueString > ValueNamedIndex
Definition evaluator_value.h:164
std::vector< std::tuple< ValueString, sourcemeta::core::JSON::Object::hash_type, bool > > ValueObjectProperties
Definition evaluator_value.h:221
std::pair< ValueType, ValueStringSet > ValueTypedProperties
Definition evaluator_value.h:195
std::pair< ValueType, ValueStringHashes > ValueTypedHashes
Definition evaluator_value.h:205
sourcemeta::core::JSON::TypeSet ValueTypes
Definition evaluator_value.h:60
std::tuple< sourcemeta::core::JSON::Object::hash_type, ValueUnsignedInteger, ValueString, ValueBoolean > ValueNamedIndexRequired
Definition evaluator_value.h:178
std::pair< ValueIntegerBounds, ValueRange > ValueIntegerBoundsWithSize
Definition evaluator_value.h:213
std::pair< std::vector< ValueNamedIndex >, std::vector< ValueIndexPair > > ValueNamedIndexes
Definition evaluator_value.h:172
bool ValueBoolean
Definition evaluator_value.h:111
std::pair< std::size_t, std::size_t > ValueIndexPair
Definition evaluator_value.h:154
std::size_t ValueUnsignedInteger
Definition evaluator_value.h:101
std::pair< ValueString, sourcemeta::core::JSON::Object::hash_type > ValueProperty
Definition evaluator_value.h:47
std::tuple< std::size_t, std::optional< std::size_t >, bool > ValueRange
Definition evaluator_value.h:107
std::pair< std::int64_t, std::int64_t > ValueIntegerBounds
Definition evaluator_value.h:209
ValueNumberType
Definition evaluator_value.h:226
std::pair< std::pair< std::vector< ValueNamedIndexRequired >, std::vector< ValueIndexPair > >, ValueUnsignedInteger > ValueNamedIndexesRequired
Definition evaluator_value.h:188
ValueStringType
Definition evaluator_value.h:115
std::unordered_set< sourcemeta::core::JSON, sourcemeta::core::HashJSON< sourcemeta::core::JSON > > ValueSet
Definition evaluator_value.h:37
Represents a compiler step empty value.
Definition evaluator_value.h:20
Definition evaluator_value.h:72