1#ifndef SOURCEMETA_CORE_JSONPOINTER_TOKEN_H_
2#define SOURCEMETA_CORE_JSONPOINTER_TOKEN_H_
4#include <sourcemeta/core/json.h>
8namespace sourcemeta::core {
20 using Index = Value::Array::size_type;
26 : as_property_{true}, property_{std::move(value)},
51 : as_property_{true}, property_{std::move(value)},
52 data_hash{HASHER(property_)} {}
88 : as_property_{false}, property_{DEFAULT_PROPERTY}, data_index{value} {}
100 : as_property_{false}, property_{DEFAULT_PROPERTY},
101 data_index{static_cast<
Index>(value)} {
116 : as_property_{false}, property_{DEFAULT_PROPERTY}, data_index{value} {}
130 return this->as_property_;
146 return this->as_property_ && this->property_.size() == 1 &&
147 this->property_.front() ==
'\u002D';
160 [[nodiscard]]
auto is_index() const noexcept ->
bool {
161 return !this->as_property_;
178 if constexpr (
requires { this->property_.get(); }) {
179 return this->property_.get();
181 return this->property_;
196 [[nodiscard]]
auto property_hash() const noexcept -> const Hash::HashType & {
198 return this->data_hash;
216 const Hash::HashType &value_hash)
const noexcept ->
bool {
218 assert(HASHER(value.data(), value.size()) == value_hash);
219 if constexpr (
requires { HASHER.is_perfect(value_hash); }) {
222 return this->data_hash == value_hash &&
223 (HASHER.is_perfect(value_hash) || this->
to_property() == value);
225 return this->data_hash == value_hash && this->
to_property() == value;
242 return this->data_index;
271 if (this->as_property_ != other.as_property_) {
274 if (this->as_property_) {
275 if constexpr (
requires { HASHER.is_perfect(this->data_hash); }) {
278 if (HASHER.is_perfect(this->data_hash) &&
279 HASHER.is_perfect(other.data_hash)) {
280 return this->data_hash == other.data_hash;
284 return this->data_hash == other.data_hash &&
287 return this->data_index == other.data_index;
294 if (this->as_property_ && !other.as_property_) {
297 if (!this->as_property_ && other.as_property_) {
300 if (this->as_property_) {
303 return this->data_index < other.data_index;
309 inline static const Hash HASHER;
316 Hash::HashType data_hash;
char Char
The character type used by the JSON document.
Definition json_value.h:42
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
auto property_equals(const JSON::StringView value, const Hash::HashType &value_hash) const noexcept -> bool
Definition jsonpointer_token.h:215
auto to_json() const -> JSON
Definition jsonpointer_token.h:261
JSON Value
The JSON value type these tokens convert to.
Definition jsonpointer_token.h:16
GenericToken(const JSON::Char value)
Definition jsonpointer_token.h:75
Value::Array::size_type Index
The stored type of an array index token.
Definition jsonpointer_token.h:20
GenericToken(const Index value)
Definition jsonpointer_token.h:87
GenericToken(const int value)
Definition jsonpointer_token.h:99
auto is_hyphen() const noexcept -> bool
Definition jsonpointer_token.h:145
auto property_hash() const noexcept -> const Hash::HashType &
Definition jsonpointer_token.h:196
auto is_index() const noexcept -> bool
Definition jsonpointer_token.h:160
GenericToken(const Property &value)
Definition jsonpointer_token.h:38
GenericToken(Property &&value)
Definition jsonpointer_token.h:50
auto to_index() const noexcept -> Index
Definition jsonpointer_token.h:240
auto is_property() const noexcept -> bool
Definition jsonpointer_token.h:129
GenericToken(Property value, const Hash::HashType &property_hash)
Definition jsonpointer_token.h:25
auto to_property() const noexcept -> const auto &
Definition jsonpointer_token.h:176
GenericToken(const JSON::Char *const value)
Definition jsonpointer_token.h:63
PropertyT Property
The stored type of an object property token.
Definition jsonpointer_token.h:18