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<
143 ValueString, ValueStrings, sourcemeta::core::PropertyHashJSON<ValueString>>;
144
149 std::tuple<ValueStringSet, ValueStrings, std::vector<ValueRegex>>;
150
153using ValueIndexPair = std::pair<std::size_t, std::size_t>;
154
157using ValuePointer = sourcemeta::core::Pointer;
158
163using ValueNamedIndex = std::tuple<sourcemeta::core::JSON::Object::hash_type,
165
172 std::pair<std::vector<ValueNamedIndex>, std::vector<ValueIndexPair>>;
173
176using ValueTypedProperties = std::pair<ValueType, ValueStringSet>;
177
181 std::pair<std::vector<std::pair<ValueStringSet::hash_type, ValueString>>,
182 std::vector<ValueIndexPair>>;
183
186using ValueTypedHashes = std::pair<ValueType, ValueStringHashes>;
187
190using ValueIntegerBounds = std::pair<std::int64_t, std::int64_t>;
191
194using ValueIntegerBoundsWithSize = std::pair<ValueIntegerBounds, ValueRange>;
195
198using ValueTypesWithSize = std::pair<ValueTypes, ValueRange>;
199
202using ValueObjectProperties = std::vector<
203 std::tuple<ValueString, sourcemeta::core::JSON::Object::hash_type, bool>>;
204
207enum class ValueNumberType : std::uint8_t { Float, Double };
208
210using Value =
211 std::variant<ValueNone, ValueJSON, ValueSet, ValueString, ValueProperty,
219
220} // namespace sourcemeta::blaze
221
222#endif
std::pair< std::vector< std::pair< ValueStringSet::hash_type, ValueString > >, std::vector< ValueIndexPair > > ValueStringHashes
Definition evaluator_value.h:180
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:198
sourcemeta::core::JSONPropertySet ValueStringSet
Definition evaluator_value.h:56
sourcemeta::core::Pointer ValuePointer
Definition evaluator_value.h:157
std::tuple< ValueStringSet, ValueStrings, std::vector< ValueRegex > > ValuePropertyFilter
Definition evaluator_value.h:148
sourcemeta::core::JSON ValueJSON
Definition evaluator_value.h:33
std::tuple< sourcemeta::core::JSON::Object::hash_type, ValueUnsignedInteger, ValueString > ValueNamedIndex
Definition evaluator_value.h:163
std::vector< std::tuple< ValueString, sourcemeta::core::JSON::Object::hash_type, bool > > ValueObjectProperties
Definition evaluator_value.h:202
std::pair< ValueType, ValueStringSet > ValueTypedProperties
Definition evaluator_value.h:176
std::pair< ValueType, ValueStringHashes > ValueTypedHashes
Definition evaluator_value.h:186
sourcemeta::core::JSON::TypeSet ValueTypes
Definition evaluator_value.h:60
std::pair< ValueIntegerBounds, ValueRange > ValueIntegerBoundsWithSize
Definition evaluator_value.h:194
std::pair< std::vector< ValueNamedIndex >, std::vector< ValueIndexPair > > ValueNamedIndexes
Definition evaluator_value.h:171
bool ValueBoolean
Definition evaluator_value.h:111
std::pair< std::size_t, std::size_t > ValueIndexPair
Definition evaluator_value.h:153
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:190
sourcemeta::core::JSONObject< ValueString, ValueStrings, sourcemeta::core::PropertyHashJSON< ValueString > > ValueStringMap
Definition evaluator_value.h:142
ValueNumberType
Definition evaluator_value.h:207
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